@@ -547,15 +547,23 @@ def crop_string_middle(s, length=32, cropper='...'):
547547 return s [:half ] + cropper + s [- half - 1 :]
548548
549549
550- class partial_match (object ): # noqa
551- """Use this to wrap values to be selected using partial matching in various objects .
550+ class FillValueWrapper (object ):
551+ """Base class for fill value wrapping. Subclass to create your own for special treatment .
552552
553553 It proxies all ``get`` operations to the underlying ``item``.
554554
555555 It also proxies ``dir`` so you get the exactly same result of :py:func:`dir` as if you did it
556556 on the wrapped object.
557557
558+ If ``None`` is passed as the item, it is passed through so
559+ :py:meth:`widgetastic.widget.View.fill` can skip the field
560+
558561 """
562+ def __new__ (cls , item ):
563+ if item is None :
564+ return None
565+ return super (FillValueWrapper , cls ).__new__ (cls )
566+
559567 def __init__ (self , item ):
560568 self .item = item
561569
@@ -567,12 +575,30 @@ def __getattr__(self, attr):
567575
568576 def __setattr__ (self , attr , value ):
569577 if attr == 'item' :
570- super (partial_match , self ).__setattr__ (attr , value )
578+ super (FillValueWrapper , self ).__setattr__ (attr , value )
571579 else :
572580 setattr (self .item , attr , value )
573581
574582 def __repr__ (self ):
575- return 'partial_match({!r})' .format (self .item )
583+ return '{}({!r})' .format (type (self ).__name__ , self .item )
584+
585+
586+ class PartialMatch (FillValueWrapper ):
587+ """Use this to wrap values to be selected using partial matching in various objects.
588+
589+ Example may be a ``<select>``. This will select the first item in the select containing "bat":
590+
591+ .. code-block:: python
592+
593+ some_view.fill({
594+ 'foo': 'bar',
595+ 'baz': PartialMatch('bat')
596+ })
597+ """
598+
599+
600+ # Backwards compatibility
601+ partial_match = PartialMatch
576602
577603
578604class Ignore (object ):
0 commit comments