<s> from __future__ import unicode_literals <EOL> from cgi import escape <EOL> from wtforms . compat import text_type , string_types , iteritems <EOL> __all__ = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> def html_params ( ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = [ ] <EOL> for k , v in sorted ( iteritems ( kwargs ) ) : <EOL> if k in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> k = k [ : - <NUM_LIT:1> ] <EOL> if v is True : <EOL> params . append ( k ) <EOL> else : <EOL> params . append ( '<STR_LIT>' % ( text_type ( k ) , escape ( text_type ( v ) , quote = True ) ) ) <EOL> return '<STR_LIT:U+0020>' . join ( params ) <EOL> class HTMLString ( text_type ) : <EOL> def __html__ ( self ) : <EOL> return self <EOL> class ListWidget ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , html_tag = '<STR_LIT>' , prefix_label = True ) : <EOL> assert html_tag in ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . html_tag = html_tag <EOL> self . prefix_label = prefix_label <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:id>' , field . id ) <EOL> html = [ '<STR_LIT>' % ( self . html_tag , html_params ( ** kwargs ) ) ] <EOL> for subfield in field : <EOL> if self . prefix_label : <EOL> html . append ( '<STR_LIT>' % ( subfield . label , subfield ( ) ) ) <EOL> else : <EOL> html . append ( '<STR_LIT>' % ( subfield ( ) , subfield . label ) ) <EOL> html . append ( '<STR_LIT>' % self . html_tag ) <EOL> return HTMLString ( '<STR_LIT>' . join ( html ) ) <EOL> class TableWidget ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , with_table_tag = True ) : <EOL> self . with_table_tag = with_table_tag <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> html = [ ] <EOL> if self . with_table_tag : <EOL> kwargs . setdefault ( '<STR_LIT:id>' , field . id ) <EOL> html . append ( '<STR_LIT>' % html_params ( ** kwargs ) ) <EOL> hidden = '<STR_LIT>' <EOL> for subfield in field : <EOL> if subfield . type == '<STR_LIT>' : <EOL> hidden += text_type ( subfield ) <EOL> else : <EOL> html . append ( '<STR_LIT>' % ( text_type ( subfield . label ) , hidden , text_type ( subfield ) ) ) <EOL> hidden = '<STR_LIT>' <EOL> if self . with_table_tag : <EOL> html . append ( '<STR_LIT>' ) <EOL> if hidden : <EOL> html . append ( hidden ) <EOL> return HTMLString ( '<STR_LIT>' . join ( html ) ) <EOL> class Input ( object ) : <EOL> """<STR_LIT>""" <EOL> html_params = staticmethod ( html_params ) <EOL> def __init__ ( self , input_type = None ) : <EOL> if input_type is not None : <EOL> self . input_type = input_type <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:id>' , field . id ) <EOL> kwargs . setdefault ( '<STR_LIT:type>' , self . input_type ) <EOL> if '<STR_LIT:value>' not in kwargs : <EOL> kwargs [ '<STR_LIT:value>' ] = field . _value ( ) <EOL> return HTMLString ( '<STR_LIT>' % self . html_params ( name = field . name , ** kwargs ) ) <EOL> class TextInput ( Input ) : <EOL> """<STR_LIT>""" <EOL> input_type = '<STR_LIT:text>' <EOL> class PasswordInput ( Input ) : <EOL> """<STR_LIT>""" <EOL> input_type = '<STR_LIT:password>' <EOL> def __init__ ( self , hide_value = True ) : <EOL> self . hide_value = hide_value <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> if self . hide_value : <EOL> kwargs [ '<STR_LIT:value>' ] = '<STR_LIT>' <EOL> return super ( PasswordInput , self ) . __call__ ( field , ** kwargs ) <EOL> class HiddenInput ( Input ) : <EOL> """<STR_LIT>""" <EOL> input_type = '<STR_LIT>' <EOL> class CheckboxInput ( Input ) : <EOL> """<STR_LIT>""" <EOL> input_type = '<STR_LIT>' <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> if getattr ( field , '<STR_LIT>' , field . data ) : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> return super ( CheckboxInput , self ) . __call__ ( field , ** kwargs ) <EOL> class RadioInput ( Input ) : <EOL> """<STR_LIT>""" <EOL> input_type = '<STR_LIT>' <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> if field . checked : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> return super ( RadioInput , self ) . __call__ ( field , ** kwargs ) <EOL> class FileInput ( object ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:id>' , field . id ) <EOL> value = field . _value ( ) <EOL> if value : <EOL> kwargs . setdefault ( '<STR_LIT:value>' , value ) <EOL> return HTMLString ( '<STR_LIT>' % html_params ( name = field . name , type = '<STR_LIT:file>' , ** kwargs ) ) <EOL> class SubmitInput ( Input ) : <EOL> """<STR_LIT>""" <EOL> input_type = '<STR_LIT>' <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:value>' , field . label . text ) <EOL> return super ( SubmitInput , self ) . __call__ ( field , ** kwargs ) <EOL> class TextArea ( object ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:id>' , field . id ) <EOL> return HTMLString ( '<STR_LIT>' % ( html_params ( name = field . name , ** kwargs ) , escape ( text_type ( field . _value ( ) ) ) ) ) <EOL> class Select ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , multiple = False ) : <EOL> self . multiple = multiple <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:id>' , field . id ) <EOL> if self . multiple : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> html = [ '<STR_LIT>' % html_params ( name = field . name , ** kwargs ) ] <EOL> for val , label , selected in field . iter_choices ( ) : <EOL> html . append ( self . render_option ( val , label , selected ) ) <EOL> html . append ( '<STR_LIT>' ) <EOL> return HTMLString ( '<STR_LIT>' . join ( html ) ) <EOL> @ classmethod <EOL> def render_option ( cls , value , label , selected , ** kwargs ) : <EOL> options = dict ( kwargs , value = value ) <EOL> if selected : <EOL> options [ '<STR_LIT>' ] = True <EOL> return HTMLString ( '<STR_LIT>' % ( html_params ( ** options ) , escape ( text_type ( label ) ) ) ) <EOL> class Option ( object ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> return Select . render_option ( field . _value ( ) , field . label . text , field . checked , ** kwargs ) </s>
