<s> from django . db . models import fields , SubfieldBase <EOL> from ldapdb import escape_ldap_filter <EOL> import datetime <EOL> class CharField ( fields . CharField ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> defaults = { '<STR_LIT:max_length>' : <NUM_LIT:200> } <EOL> defaults . update ( kwargs ) <EOL> super ( CharField , self ) . __init__ ( * args , ** defaults ) <EOL> def from_ldap ( self , value , connection ) : <EOL> if len ( value ) == <NUM_LIT:0> : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return value [ <NUM_LIT:0> ] . decode ( connection . charset ) <EOL> def get_db_prep_lookup ( self , lookup_type , value , connection , <EOL> prepared = False ) : <EOL> "<STR_LIT>" <EOL> if lookup_type == '<STR_LIT>' : <EOL> return [ "<STR_LIT>" % escape_ldap_filter ( value ) ] <EOL> elif lookup_type == '<STR_LIT>' : <EOL> return [ "<STR_LIT>" % escape_ldap_filter ( value ) ] <EOL> elif lookup_type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ "<STR_LIT>" % escape_ldap_filter ( value ) ] <EOL> elif lookup_type == '<STR_LIT>' : <EOL> return [ escape_ldap_filter ( value ) ] <EOL> elif lookup_type == '<STR_LIT>' : <EOL> return [ escape_ldap_filter ( v ) for v in value ] <EOL> raise TypeError ( "<STR_LIT>" % lookup_type ) <EOL> def get_db_prep_save ( self , value , connection ) : <EOL> if not value : <EOL> return None <EOL> return [ value . encode ( connection . charset ) ] <EOL> def get_prep_lookup ( self , lookup_type , value ) : <EOL> "<STR_LIT>" <EOL> if lookup_type == '<STR_LIT>' : <EOL> return "<STR_LIT>" % escape_ldap_filter ( value ) <EOL> elif lookup_type == '<STR_LIT>' : <EOL> return "<STR_LIT>" % escape_ldap_filter ( value ) <EOL> elif lookup_type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return "<STR_LIT>" % escape_ldap_filter ( value ) <EOL> elif lookup_type == '<STR_LIT>' : <EOL> return escape_ldap_filter ( value ) <EOL> elif lookup_type == '<STR_LIT>' : <EOL> return [ escape_ldap_filter ( v ) for v in value ] <EOL> raise TypeError ( "<STR_LIT>" % lookup_type ) <EOL> class ImageField ( fields . Field ) : <EOL> def from_ldap ( self , value , connection ) : <EOL> if len ( value ) == <NUM_LIT:0> : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return value [ <NUM_LIT:0> ] <EOL> def get_db_prep_lookup ( self , lookup_type , value , connection , <EOL> prepared = False ) : <EOL> "<STR_LIT>" <EOL> return [ self . get_prep_lookup ( lookup_type , value ) ] <EOL> def get_db_prep_save ( self , value , connection ) : <EOL> if not value : <EOL> return None <EOL> return [ value ] <EOL> def get_prep_lookup ( self , lookup_type , value ) : <EOL> "<STR_LIT>" <EOL> raise TypeError ( "<STR_LIT>" % lookup_type ) <EOL> class IntegerField ( fields . IntegerField ) : <EOL> def from_ldap ( self , value , connection ) : <EOL> if len ( value ) == <NUM_LIT:0> : <EOL> return <NUM_LIT:0> <EOL> else : <EOL> return int ( value [ <NUM_LIT:0> ] ) <EOL> def get_db_prep_lookup ( self , lookup_type , value , connection , <EOL> prepared = False ) : <EOL> "<STR_LIT>" <EOL> return [ self . get_prep_lookup ( lookup_type , value ) ] <EOL> def get_db_prep_save ( self , value , connection ) : <EOL> if value is None : <EOL> return None <EOL> return [ str ( value ) ] <EOL> def get_prep_lookup ( self , lookup_type , value ) : <EOL> "<STR_LIT>" <EOL> if lookup_type in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return value <EOL> raise TypeError ( "<STR_LIT>" % lookup_type ) <EOL> class FloatField ( fields . FloatField ) : <EOL> def from_ldap ( self , value , connection ) : <EOL> if len ( value ) == <NUM_LIT:0> : <EOL> return <NUM_LIT:0.0> <EOL> else : <EOL> return float ( value [ <NUM_LIT:0> ] ) <EOL> def get_db_prep_lookup ( self , lookup_type , value , connection , <EOL> prepared = False ) : <EOL> "<STR_LIT>" <EOL> return [ self . get_prep_lookup ( lookup_type , value ) ] <EOL> def get_db_prep_save ( self , value , connection ) : <EOL> if value is None : <EOL> return None <EOL> return [ str ( value ) ] <EOL> def get_prep_lookup ( self , lookup_type , value ) : <EOL> "<STR_LIT>" <EOL> if lookup_type in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return value <EOL> raise TypeError ( "<STR_LIT>" % lookup_type ) <EOL> class ListField ( fields . Field ) : <EOL> __metaclass__ = SubfieldBase <EOL> def from_ldap ( self , value , connection ) : <EOL> return [ x . decode ( connection . charset ) for x in value ] <EOL> def get_db_prep_lookup ( self , lookup_type , value , connection , <EOL> prepared = False ) : <EOL> "<STR_LIT>" <EOL> return [ self . get_prep_lookup ( lookup_type , value ) ] <EOL> def get_db_prep_save ( self , value , connection ) : <EOL> if not value : <EOL> return None <EOL> return [ x . encode ( connection . charset ) for x in value ] <EOL> def get_prep_lookup ( self , lookup_type , value ) : <EOL> "<STR_LIT>" <EOL> if lookup_type == '<STR_LIT>' : <EOL> return escape_ldap_filter ( value ) <EOL> raise TypeError ( "<STR_LIT>" % lookup_type ) <EOL> def to_python ( self , value ) : <EOL> if not value : <EOL> return [ ] <EOL> return value <EOL> class DateField ( fields . DateField ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> if '<STR_LIT>' in kwargs : <EOL> self . _date_format = kwargs . pop ( '<STR_LIT>' ) <EOL> else : <EOL> self . _date_format = '<STR_LIT>' <EOL> super ( DateField , self ) . __init__ ( * args , ** kwargs ) <EOL> def from_ldap ( self , value , connection ) : <EOL> if len ( value ) == <NUM_LIT:0> : <EOL> return None <EOL> else : <EOL> return datetime . datetime . strptime ( value [ <NUM_LIT:0> ] , <EOL> self . _date_format ) . date ( ) <EOL> def get_db_prep_lookup ( self , lookup_type , value , connection , <EOL> prepared = False ) : <EOL> "<STR_LIT>" <EOL> return [ self . get_prep_lookup ( lookup_type , value ) ] <EOL> def get_db_prep_save ( self , value , connection ) : <EOL> if not value : <EOL> return None <EOL> if not isinstance ( value , datetime . date ) and not isinstance ( value , datetime . datetime ) : <EOL> raise ValueError ( <EOL> '<STR_LIT>' ) <EOL> return [ value . strftime ( self . _date_format ) ] <EOL> def get_prep_lookup ( self , lookup_type , value ) : <EOL> "<STR_LIT>" <EOL> if lookup_type in ( '<STR_LIT>' , ) : <EOL> return value <EOL> raise TypeError ( "<STR_LIT>" % lookup_type ) </s>
