<s> import copy <EOL> import datetime <EOL> import os <EOL> import re <EOL> import time <EOL> try : <EOL> import decimal <EOL> except ImportError : <EOL> from django . utils import _decimal as decimal <EOL> from django . db import connection <EOL> from django . db . models import signals <EOL> from django . db . models . query_utils import QueryWrapper <EOL> from django . dispatch import dispatcher <EOL> from django . conf import settings <EOL> from django import forms <EOL> from django . core import exceptions <EOL> from django . utils . datastructures import DictWrapper <EOL> from django . utils . functional import curry <EOL> from django . utils . itercompat import tee <EOL> from django . utils . text import capfirst <EOL> from django . utils . translation import ugettext_lazy , ugettext as _ <EOL> from django . utils . encoding import smart_unicode , force_unicode , smart_str <EOL> from django . utils import datetime_safe <EOL> class NOT_PROVIDED : <EOL> pass <EOL> BLANK_CHOICE_DASH = [ ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> BLANK_CHOICE_NONE = [ ( "<STR_LIT>" , "<STR_LIT:None>" ) ] <EOL> class FieldDoesNotExist ( Exception ) : <EOL> pass <EOL> class Field ( object ) : <EOL> empty_strings_allowed = True <EOL> creation_counter = <NUM_LIT:0> <EOL> auto_creation_counter = - <NUM_LIT:1> <EOL> def __init__ ( self , verbose_name = None , name = None , primary_key = False , <EOL> max_length = None , unique = False , blank = False , null = False , <EOL> db_index = False , rel = None , default = NOT_PROVIDED , editable = True , <EOL> serialize = True , unique_for_date = None , unique_for_month = None , <EOL> unique_for_year = None , choices = None , help_text = '<STR_LIT>' , db_column = None , <EOL> db_tablespace = None , auto_created = False ) : <EOL> self . name = name <EOL> self . verbose_name = verbose_name <EOL> self . primary_key = primary_key <EOL> self . max_length , self . _unique = max_length , unique <EOL> self . blank , self . null = blank , null <EOL> if self . empty_strings_allowed and connection . features . interprets_empty_strings_as_nulls : <EOL> self . null = True <EOL> self . rel = rel <EOL> self . default = default <EOL> self . editable = editable <EOL> self . serialize = serialize <EOL> self . unique_for_date , self . unique_for_month = unique_for_date , unique_for_month <EOL> self . unique_for_year = unique_for_year <EOL> self . _choices = choices or [ ] <EOL> self . help_text = help_text <EOL> self . db_column = db_column <EOL> self . db_tablespace = db_tablespace or settings . DEFAULT_INDEX_TABLESPACE <EOL> self . auto_created = auto_created <EOL> self . db_index = db_index <EOL> if auto_created : <EOL> self . creation_counter = Field . auto_creation_counter <EOL> Field . auto_creation_counter -= <NUM_LIT:1> <EOL> else : <EOL> self . creation_counter = Field . creation_counter <EOL> Field . creation_counter += <NUM_LIT:1> <EOL> def __cmp__ ( self , other ) : <EOL> return cmp ( self . creation_counter , other . creation_counter ) <EOL> def __deepcopy__ ( self , memodict ) : <EOL> obj = copy . copy ( self ) <EOL> if self . rel : <EOL> obj . rel = copy . copy ( self . rel ) <EOL> memodict [ id ( self ) ] = obj <EOL> return obj <EOL> def to_python ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return value <EOL> def db_type ( self ) : <EOL> """<STR_LIT>""" <EOL> data = DictWrapper ( self . __dict__ , connection . ops . quote_name , "<STR_LIT>" ) <EOL> try : <EOL> return connection . creation . data_types [ self . get_internal_type ( ) ] % data <EOL> except KeyError : <EOL> return None <EOL> def unique ( self ) : <EOL> return self . _unique or self . primary_key <EOL> unique = property ( unique ) <EOL> def set_attributes_from_name ( self , name ) : <EOL> self . name = name <EOL> self . attname , self . column = self . get_attname_column ( ) <EOL> if self . verbose_name is None and name : <EOL> self . verbose_name = name . replace ( '<STR_LIT:_>' , '<STR_LIT:U+0020>' ) <EOL> def contribute_to_class ( self , cls , name ) : <EOL> self . set_attributes_from_name ( name ) <EOL> cls . _meta . add_field ( self ) <EOL> if self . choices : <EOL> setattr ( cls , '<STR_LIT>' % self . name , curry ( cls . _get_FIELD_display , field = self ) ) <EOL> def get_attname ( self ) : <EOL> return self . name <EOL> def get_attname_column ( self ) : <EOL> attname = self . get_attname ( ) <EOL> column = self . db_column or attname <EOL> return attname , column <EOL> def get_cache_name ( self ) : <EOL> return '<STR_LIT>' % self . name <EOL> def get_internal_type ( self ) : <EOL> return self . __class__ . __name__ <EOL> def pre_save ( self , model_instance , add ) : <EOL> "<STR_LIT>" <EOL> return getattr ( model_instance , self . attname ) <EOL> def get_db_prep_value ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return value <EOL> def get_db_prep_save ( self , value ) : <EOL> "<STR_LIT>" <EOL> return self . get_db_prep_value ( value ) <EOL> def get_db_prep_lookup ( self , lookup_type , value ) : <EOL> "<STR_LIT>" <EOL> if hasattr ( value , '<STR_LIT>' ) or hasattr ( value , '<STR_LIT>' ) : <EOL> if hasattr ( value , '<STR_LIT>' ) : <EOL> return value <EOL> if hasattr ( value , '<STR_LIT>' ) : <EOL> sql , params = value . as_sql ( ) <EOL> else : <EOL> sql , params = value . _as_sql ( ) <EOL> return QueryWrapper ( ( '<STR_LIT>' % sql ) , params ) <EOL> if lookup_type in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return [ value ] <EOL> elif lookup_type in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return [ self . get_db_prep_value ( value ) ] <EOL> elif lookup_type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return [ self . get_db_prep_value ( v ) for v in value ] <EOL> elif lookup_type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return [ "<STR_LIT>" % connection . ops . prep_for_like_query ( value ) ] <EOL> elif lookup_type == '<STR_LIT>' : <EOL> return [ connection . ops . prep_for_iexact_query ( value ) ] <EOL> elif lookup_type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return [ "<STR_LIT>" % connection . ops . prep_for_like_query ( value ) ] <EOL> elif lookup_type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return [ "<STR_LIT>" % connection . ops . prep_for_like_query ( value ) ] <EOL> elif lookup_type == '<STR_LIT>' : <EOL> return [ ] <EOL> elif lookup_type == '<STR_LIT>' : <EOL> try : <EOL> value = int ( value ) <EOL> except ValueError : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . get_internal_type ( ) == '<STR_LIT>' : <EOL> return connection . ops . year_lookup_bounds_for_date_field ( value ) <EOL> else : <EOL> return connection . ops . year_lookup_bounds ( value ) <EOL> raise TypeError ( "<STR_LIT>" % lookup_type ) <EOL> def has_default ( self ) : <EOL> "<STR_LIT>" <EOL> return self . default is not NOT_PROVIDED <EOL> def get_default ( self ) : <EOL> "<STR_LIT>" <EOL> if self . has_default ( ) : <EOL> if callable ( self . default ) : <EOL> return self . default ( ) <EOL> return force_unicode ( self . default , strings_only = True ) <EOL> if not self . empty_strings_allowed or ( self . null and not connection . features . interprets_empty_strings_as_nulls ) : <EOL> return None <EOL> return "<STR_LIT>" <EOL> def get_validator_unique_lookup_type ( self ) : <EOL> return '<STR_LIT>' % self . name <EOL> def get_choices ( self , include_blank = True , blank_choice = BLANK_CHOICE_DASH ) : <EOL> """<STR_LIT>""" <EOL> first_choice = include_blank and blank_choice or [ ] <EOL> if self . choices : <EOL> return first_choice + list ( self . choices ) <EOL> rel_model = self . rel . to <EOL> if hasattr ( self . rel , '<STR_LIT>' ) : <EOL> lst = [ ( getattr ( x , self . rel . get_related_field ( ) . attname ) , smart_unicode ( x ) ) for x in rel_model . _default_manager . complex_filter ( self . rel . limit_choices_to ) ] <EOL> else : <EOL> lst = [ ( x . _get_pk_val ( ) , smart_unicode ( x ) ) for x in rel_model . _default_manager . complex_filter ( self . rel . limit_choices_to ) ] <EOL> return first_choice + lst <EOL> def get_choices_default ( self ) : <EOL> return self . get_choices ( ) <EOL> def get_flatchoices ( self , include_blank = True , blank_choice = BLANK_CHOICE_DASH ) : <EOL> "<STR_LIT>" <EOL> first_choice = include_blank and blank_choice or [ ] <EOL> return first_choice + list ( self . flatchoices ) <EOL> def _get_val_from_obj ( self , obj ) : <EOL> if obj : <EOL> return getattr ( obj , self . attname ) <EOL> else : <EOL> return self . get_default ( ) <EOL> def value_to_string ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> return smart_unicode ( self . _get_val_from_obj ( obj ) ) <EOL> def bind ( self , fieldmapping , original , bound_field_class ) : <EOL> return bound_field_class ( self , fieldmapping , original ) <EOL> def _get_choices ( self ) : <EOL> if hasattr ( self . _choices , '<STR_LIT>' ) : <EOL> choices , self . _choices = tee ( self . _choices ) <EOL> return choices <EOL> else : <EOL> return self . _choices <EOL> choices = property ( _get_choices ) <EOL> def _get_flatchoices ( self ) : <EOL> """<STR_LIT>""" <EOL> flat = [ ] <EOL> for choice , value in self . choices : <EOL> if type ( value ) in ( list , tuple ) : <EOL> flat . extend ( value ) <EOL> else : <EOL> flat . append ( ( choice , value ) ) <EOL> return flat <EOL> flatchoices = property ( _get_flatchoices ) <EOL> def save_form_data ( self , instance , data ) : <EOL> setattr ( instance , self . name , data ) <EOL> def formfield ( self , form_class = forms . CharField , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> defaults = { '<STR_LIT>' : not self . blank , '<STR_LIT:label>' : capfirst ( self . verbose_name ) , '<STR_LIT>' : self . help_text } <EOL> if self . has_default ( ) : <EOL> defaults [ '<STR_LIT>' ] = self . get_default ( ) <EOL> if callable ( self . default ) : <EOL> defaults [ '<STR_LIT>' ] = True <EOL> if self . choices : <EOL> include_blank = self . blank or not ( self . has_default ( ) or '<STR_LIT>' in kwargs ) <EOL> defaults [ '<STR_LIT>' ] = self . get_choices ( include_blank = include_blank ) <EOL> defaults [ '<STR_LIT>' ] = self . to_python <EOL> if self . null : <EOL> defaults [ '<STR_LIT>' ] = None <EOL> form_class = forms . TypedChoiceField <EOL> for k in kwargs . keys ( ) : <EOL> if k not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:label>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) : <EOL> del kwargs [ k ] <EOL> defaults . update ( kwargs ) <EOL> return form_class ( ** defaults ) <EOL> def value_from_object ( self , obj ) : <EOL> "<STR_LIT>" <EOL> return getattr ( obj , self . attname ) <EOL> class AutoField ( Field ) : <EOL> empty_strings_allowed = False <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> assert kwargs . get ( '<STR_LIT:primary_key>' , False ) is True , "<STR_LIT>" % self . __class__ . __name__ <EOL> kwargs [ '<STR_LIT:blank>' ] = True <EOL> Field . __init__ ( self , * args , ** kwargs ) <EOL> def to_python ( self , value ) : <EOL> if value is None : <EOL> return value <EOL> try : <EOL> return int ( value ) <EOL> except ( TypeError , ValueError ) : <EOL> raise exceptions . ValidationError ( <EOL> _ ( "<STR_LIT>" ) ) <EOL> def get_db_prep_value ( self , value ) : <EOL> if value is None : <EOL> return None <EOL> return int ( value ) <EOL> def contribute_to_class ( self , cls , name ) : <EOL> assert not cls . _meta . has_auto_field , "<STR_LIT>" <EOL> super ( AutoField , self ) . contribute_to_class ( cls , name ) <EOL> cls . _meta . has_auto_field = True <EOL> cls . _meta . auto_field = self <EOL> def formfield ( self , ** kwargs ) : <EOL> return None <EOL> class BooleanField ( Field ) : <EOL> empty_strings_allowed = False <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> kwargs [ '<STR_LIT:blank>' ] = True <EOL> if '<STR_LIT:default>' not in kwargs and not kwargs . get ( '<STR_LIT:null>' ) : <EOL> kwargs [ '<STR_LIT:default>' ] = False <EOL> Field . __init__ ( self , * args , ** kwargs ) <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def to_python ( self , value ) : <EOL> if value in ( True , False ) : return value <EOL> if value in ( '<STR_LIT:t>' , '<STR_LIT:True>' , '<STR_LIT:1>' ) : return True <EOL> if value in ( '<STR_LIT:f>' , '<STR_LIT:False>' , '<STR_LIT:0>' ) : return False <EOL> raise exceptions . ValidationError ( <EOL> _ ( "<STR_LIT>" ) ) <EOL> def get_db_prep_lookup ( self , lookup_type , value ) : <EOL> if value in ( '<STR_LIT:1>' , '<STR_LIT:0>' ) : <EOL> value = bool ( int ( value ) ) <EOL> return super ( BooleanField , self ) . get_db_prep_lookup ( lookup_type , value ) <EOL> def get_db_prep_value ( self , value ) : <EOL> if value is None : <EOL> return None <EOL> return bool ( value ) <EOL> def formfield ( self , ** kwargs ) : <EOL> if self . choices : <EOL> include_blank = self . null or not ( self . has_default ( ) or '<STR_LIT>' in kwargs ) <EOL> defaults = { '<STR_LIT>' : self . get_choices ( include_blank = include_blank ) } <EOL> else : <EOL> defaults = { '<STR_LIT>' : forms . BooleanField } <EOL> defaults . update ( kwargs ) <EOL> return super ( BooleanField , self ) . formfield ( ** defaults ) <EOL> class CharField ( Field ) : <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def to_python ( self , value ) : <EOL> if isinstance ( value , basestring ) : <EOL> return value <EOL> if value is None : <EOL> if self . null : <EOL> return value <EOL> else : <EOL> raise exceptions . ValidationError ( <EOL> ugettext_lazy ( "<STR_LIT>" ) ) <EOL> return smart_unicode ( value ) <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT:max_length>' : self . max_length } <EOL> defaults . update ( kwargs ) <EOL> return super ( CharField , self ) . formfield ( ** defaults ) <EOL> class CommaSeparatedIntegerField ( CharField ) : <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { <EOL> '<STR_LIT>' : forms . RegexField , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:max_length>' : self . max_length , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : _ ( u'<STR_LIT>' ) , <EOL> } <EOL> } <EOL> defaults . update ( kwargs ) <EOL> return super ( CommaSeparatedIntegerField , self ) . formfield ( ** defaults ) <EOL> ansi_date_re = re . compile ( r'<STR_LIT>' ) <EOL> class DateField ( Field ) : <EOL> empty_strings_allowed = False <EOL> def __init__ ( self , verbose_name = None , name = None , auto_now = False , auto_now_add = False , ** kwargs ) : <EOL> self . auto_now , self . auto_now_add = auto_now , auto_now_add <EOL> if auto_now or auto_now_add : <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:blank>' ] = True <EOL> Field . __init__ ( self , verbose_name , name , ** kwargs ) <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def to_python ( self , value ) : <EOL> if value is None : <EOL> return value <EOL> if isinstance ( value , datetime . datetime ) : <EOL> return value . date ( ) <EOL> if isinstance ( value , datetime . date ) : <EOL> return value <EOL> if not ansi_date_re . search ( value ) : <EOL> raise exceptions . ValidationError ( <EOL> _ ( '<STR_LIT>' ) ) <EOL> year , month , day = map ( int , value . split ( '<STR_LIT:->' ) ) <EOL> try : <EOL> return datetime . date ( year , month , day ) <EOL> except ValueError , e : <EOL> msg = _ ( '<STR_LIT>' ) % _ ( str ( e ) ) <EOL> raise exceptions . ValidationError ( msg ) <EOL> def pre_save ( self , model_instance , add ) : <EOL> if self . auto_now or ( self . auto_now_add and add ) : <EOL> value = datetime . datetime . now ( ) <EOL> setattr ( model_instance , self . attname , value ) <EOL> return value <EOL> else : <EOL> return super ( DateField , self ) . pre_save ( model_instance , add ) <EOL> def contribute_to_class ( self , cls , name ) : <EOL> super ( DateField , self ) . contribute_to_class ( cls , name ) <EOL> if not self . null : <EOL> setattr ( cls , '<STR_LIT>' % self . name , <EOL> curry ( cls . _get_next_or_previous_by_FIELD , field = self , is_next = True ) ) <EOL> setattr ( cls , '<STR_LIT>' % self . name , <EOL> curry ( cls . _get_next_or_previous_by_FIELD , field = self , is_next = False ) ) <EOL> def get_db_prep_lookup ( self , lookup_type , value ) : <EOL> if lookup_type in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return [ int ( value ) ] <EOL> return super ( DateField , self ) . get_db_prep_lookup ( lookup_type , value ) <EOL> def get_db_prep_value ( self , value ) : <EOL> return connection . ops . value_to_db_date ( self . to_python ( value ) ) <EOL> def value_to_string ( self , obj ) : <EOL> val = self . _get_val_from_obj ( obj ) <EOL> if val is None : <EOL> data = '<STR_LIT>' <EOL> else : <EOL> data = datetime_safe . new_date ( val ) . strftime ( "<STR_LIT>" ) <EOL> return data <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : forms . DateField } <EOL> defaults . update ( kwargs ) <EOL> return super ( DateField , self ) . formfield ( ** defaults ) <EOL> class DateTimeField ( DateField ) : <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def to_python ( self , value ) : <EOL> if value is None : <EOL> return value <EOL> if isinstance ( value , datetime . datetime ) : <EOL> return value <EOL> if isinstance ( value , datetime . date ) : <EOL> return datetime . datetime ( value . year , value . month , value . day ) <EOL> value = smart_str ( value ) <EOL> if '<STR_LIT:.>' in value : <EOL> try : <EOL> value , usecs = value . split ( '<STR_LIT:.>' ) <EOL> usecs = int ( usecs ) <EOL> except ValueError : <EOL> raise exceptions . ValidationError ( <EOL> _ ( '<STR_LIT>' ) ) <EOL> else : <EOL> usecs = <NUM_LIT:0> <EOL> kwargs = { '<STR_LIT>' : usecs } <EOL> try : <EOL> return datetime . datetime ( * time . strptime ( value , '<STR_LIT>' ) [ : <NUM_LIT:6> ] , <EOL> ** kwargs ) <EOL> except ValueError : <EOL> try : <EOL> return datetime . datetime ( * time . strptime ( value , '<STR_LIT>' ) [ : <NUM_LIT:5> ] , <EOL> ** kwargs ) <EOL> except ValueError : <EOL> try : <EOL> return datetime . datetime ( * time . strptime ( value , '<STR_LIT>' ) [ : <NUM_LIT:3> ] , <EOL> ** kwargs ) <EOL> except ValueError : <EOL> raise exceptions . ValidationError ( <EOL> _ ( '<STR_LIT>' ) ) <EOL> def get_db_prep_value ( self , value ) : <EOL> return connection . ops . value_to_db_datetime ( self . to_python ( value ) ) <EOL> def value_to_string ( self , obj ) : <EOL> val = self . _get_val_from_obj ( obj ) <EOL> if val is None : <EOL> data = '<STR_LIT>' <EOL> else : <EOL> d = datetime_safe . new_datetime ( val ) <EOL> data = d . strftime ( '<STR_LIT>' ) <EOL> return data <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : forms . DateTimeField } <EOL> defaults . update ( kwargs ) <EOL> return super ( DateTimeField , self ) . formfield ( ** defaults ) <EOL> class DecimalField ( Field ) : <EOL> empty_strings_allowed = False <EOL> def __init__ ( self , verbose_name = None , name = None , max_digits = None , decimal_places = None , ** kwargs ) : <EOL> self . max_digits , self . decimal_places = max_digits , decimal_places <EOL> Field . __init__ ( self , verbose_name , name , ** kwargs ) <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def to_python ( self , value ) : <EOL> if value is None : <EOL> return value <EOL> try : <EOL> return decimal . Decimal ( value ) <EOL> except decimal . InvalidOperation : <EOL> raise exceptions . ValidationError ( <EOL> _ ( "<STR_LIT>" ) ) <EOL> def _format ( self , value ) : <EOL> if isinstance ( value , basestring ) or value is None : <EOL> return value <EOL> else : <EOL> return self . format_number ( value ) <EOL> def format_number ( self , value ) : <EOL> """<STR_LIT>""" <EOL> from django . db . backends import util <EOL> return util . format_number ( value , self . max_digits , self . decimal_places ) <EOL> def get_db_prep_save ( self , value ) : <EOL> return connection . ops . value_to_db_decimal ( self . to_python ( value ) , <EOL> self . max_digits , self . decimal_places ) <EOL> def get_db_prep_value ( self , value ) : <EOL> return self . to_python ( value ) <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { <EOL> '<STR_LIT>' : self . max_digits , <EOL> '<STR_LIT>' : self . decimal_places , <EOL> '<STR_LIT>' : forms . DecimalField , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> return super ( DecimalField , self ) . formfield ( ** defaults ) <EOL> class EmailField ( CharField ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> kwargs [ '<STR_LIT:max_length>' ] = kwargs . get ( '<STR_LIT:max_length>' , <NUM_LIT> ) <EOL> CharField . __init__ ( self , * args , ** kwargs ) <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : forms . EmailField } <EOL> defaults . update ( kwargs ) <EOL> return super ( EmailField , self ) . formfield ( ** defaults ) <EOL> class FilePathField ( Field ) : <EOL> def __init__ ( self , verbose_name = None , name = None , path = '<STR_LIT>' , match = None , recursive = False , ** kwargs ) : <EOL> self . path , self . match , self . recursive = path , match , recursive <EOL> kwargs [ '<STR_LIT:max_length>' ] = kwargs . get ( '<STR_LIT:max_length>' , <NUM_LIT:100> ) <EOL> Field . __init__ ( self , verbose_name , name , ** kwargs ) <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { <EOL> '<STR_LIT:path>' : self . path , <EOL> '<STR_LIT>' : self . match , <EOL> '<STR_LIT>' : self . recursive , <EOL> '<STR_LIT>' : forms . FilePathField , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> return super ( FilePathField , self ) . formfield ( ** defaults ) <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> class FloatField ( Field ) : <EOL> empty_strings_allowed = False <EOL> def get_db_prep_value ( self , value ) : <EOL> if value is None : <EOL> return None <EOL> return float ( value ) <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def to_python ( self , value ) : <EOL> if value is None : <EOL> return value <EOL> try : <EOL> return float ( value ) <EOL> except ( TypeError , ValueError ) : <EOL> raise exceptions . ValidationError ( <EOL> _ ( "<STR_LIT>" ) ) <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : forms . FloatField } <EOL> defaults . update ( kwargs ) <EOL> return super ( FloatField , self ) . formfield ( ** defaults ) <EOL> class IntegerField ( Field ) : <EOL> empty_strings_allowed = False <EOL> def get_db_prep_value ( self , value ) : <EOL> if value is None : <EOL> return None <EOL> return int ( value ) <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def to_python ( self , value ) : <EOL> if value is None : <EOL> return value <EOL> try : <EOL> return int ( value ) <EOL> except ( TypeError , ValueError ) : <EOL> raise exceptions . ValidationError ( <EOL> _ ( "<STR_LIT>" ) ) <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : forms . IntegerField } <EOL> defaults . update ( kwargs ) <EOL> return super ( IntegerField , self ) . formfield ( ** defaults ) <EOL> class IPAddressField ( Field ) : <EOL> empty_strings_allowed = False <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> kwargs [ '<STR_LIT:max_length>' ] = <NUM_LIT:15> <EOL> Field . __init__ ( self , * args , ** kwargs ) <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : forms . IPAddressField } <EOL> defaults . update ( kwargs ) <EOL> return super ( IPAddressField , self ) . formfield ( ** defaults ) <EOL> class NullBooleanField ( Field ) : <EOL> empty_strings_allowed = False <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> kwargs [ '<STR_LIT:null>' ] = True <EOL> Field . __init__ ( self , * args , ** kwargs ) <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def to_python ( self , value ) : <EOL> if value in ( None , True , False ) : return value <EOL> if value in ( '<STR_LIT:None>' , ) : return None <EOL> if value in ( '<STR_LIT:t>' , '<STR_LIT:True>' , '<STR_LIT:1>' ) : return True <EOL> if value in ( '<STR_LIT:f>' , '<STR_LIT:False>' , '<STR_LIT:0>' ) : return False <EOL> raise exceptions . ValidationError ( <EOL> _ ( "<STR_LIT>" ) ) <EOL> def get_db_prep_lookup ( self , lookup_type , value ) : <EOL> if value in ( '<STR_LIT:1>' , '<STR_LIT:0>' ) : <EOL> value = bool ( int ( value ) ) <EOL> return super ( NullBooleanField , self ) . get_db_prep_lookup ( lookup_type , value ) <EOL> def get_db_prep_value ( self , value ) : <EOL> if value is None : <EOL> return None <EOL> return bool ( value ) <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { <EOL> '<STR_LIT>' : forms . NullBooleanField , <EOL> '<STR_LIT>' : not self . blank , <EOL> '<STR_LIT:label>' : capfirst ( self . verbose_name ) , <EOL> '<STR_LIT>' : self . help_text } <EOL> defaults . update ( kwargs ) <EOL> return super ( NullBooleanField , self ) . formfield ( ** defaults ) <EOL> class PositiveIntegerField ( IntegerField ) : <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : <NUM_LIT:0> } <EOL> defaults . update ( kwargs ) <EOL> return super ( PositiveIntegerField , self ) . formfield ( ** defaults ) <EOL> class PositiveSmallIntegerField ( IntegerField ) : <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : <NUM_LIT:0> } <EOL> defaults . update ( kwargs ) <EOL> return super ( PositiveSmallIntegerField , self ) . formfield ( ** defaults ) <EOL> class SlugField ( CharField ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> kwargs [ '<STR_LIT:max_length>' ] = kwargs . get ( '<STR_LIT:max_length>' , <NUM_LIT:50> ) <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> super ( SlugField , self ) . __init__ ( * args , ** kwargs ) <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : forms . SlugField } <EOL> defaults . update ( kwargs ) <EOL> return super ( SlugField , self ) . formfield ( ** defaults ) <EOL> class SmallIntegerField ( IntegerField ) : <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> class TextField ( Field ) : <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : forms . Textarea } <EOL> defaults . update ( kwargs ) <EOL> return super ( TextField , self ) . formfield ( ** defaults ) <EOL> class TimeField ( Field ) : <EOL> empty_strings_allowed = False <EOL> def __init__ ( self , verbose_name = None , name = None , auto_now = False , auto_now_add = False , ** kwargs ) : <EOL> self . auto_now , self . auto_now_add = auto_now , auto_now_add <EOL> if auto_now or auto_now_add : <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> Field . __init__ ( self , verbose_name , name , ** kwargs ) <EOL> def get_internal_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def to_python ( self , value ) : <EOL> if value is None : <EOL> return None <EOL> if isinstance ( value , datetime . time ) : <EOL> return value <EOL> if isinstance ( value , datetime . datetime ) : <EOL> return value . time <EOL> value = smart_str ( value ) <EOL> if '<STR_LIT:.>' in value : <EOL> try : <EOL> value , usecs = value . split ( '<STR_LIT:.>' ) <EOL> usecs = int ( usecs ) <EOL> except ValueError : <EOL> raise exceptions . ValidationError ( <EOL> _ ( '<STR_LIT>' ) ) <EOL> else : <EOL> usecs = <NUM_LIT:0> <EOL> kwargs = { '<STR_LIT>' : usecs } <EOL> try : <EOL> return datetime . time ( * time . strptime ( value , '<STR_LIT>' ) [ <NUM_LIT:3> : <NUM_LIT:6> ] , <EOL> ** kwargs ) <EOL> except ValueError : <EOL> try : <EOL> return datetime . time ( * time . strptime ( value , '<STR_LIT>' ) [ <NUM_LIT:3> : <NUM_LIT:5> ] , <EOL> ** kwargs ) <EOL> except ValueError : <EOL> raise exceptions . ValidationError ( <EOL> _ ( '<STR_LIT>' ) ) <EOL> def pre_save ( self , model_instance , add ) : <EOL> if self . auto_now or ( self . auto_now_add and add ) : <EOL> value = datetime . datetime . now ( ) . time ( ) <EOL> setattr ( model_instance , self . attname , value ) <EOL> return value <EOL> else : <EOL> return super ( TimeField , self ) . pre_save ( model_instance , add ) <EOL> def get_db_prep_value ( self , value ) : <EOL> return connection . ops . value_to_db_time ( self . to_python ( value ) ) <EOL> def value_to_string ( self , obj ) : <EOL> val = self . _get_val_from_obj ( obj ) <EOL> if val is None : <EOL> data = '<STR_LIT>' <EOL> else : <EOL> data = val . strftime ( "<STR_LIT>" ) <EOL> return data <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : forms . TimeField } <EOL> defaults . update ( kwargs ) <EOL> return super ( TimeField , self ) . formfield ( ** defaults ) <EOL> class URLField ( CharField ) : <EOL> def __init__ ( self , verbose_name = None , name = None , verify_exists = True , ** kwargs ) : <EOL> kwargs [ '<STR_LIT:max_length>' ] = kwargs . get ( '<STR_LIT:max_length>' , <NUM_LIT:200> ) <EOL> self . verify_exists = verify_exists <EOL> CharField . __init__ ( self , verbose_name , name , ** kwargs ) <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { '<STR_LIT>' : forms . URLField , '<STR_LIT>' : self . verify_exists } <EOL> defaults . update ( kwargs ) <EOL> return super ( URLField , self ) . formfield ( ** defaults ) <EOL> class XMLField ( TextField ) : <EOL> def __init__ ( self , verbose_name = None , name = None , schema_path = None , ** kwargs ) : <EOL> self . schema_path = schema_path <EOL> Field . __init__ ( self , verbose_name , name , ** kwargs ) </s>
