<s> from datetime import datetime , date , timedelta <EOL> from decimal import Decimal <EOL> import threading <EOL> import six <EOL> try : <EOL> from django . utils . timezone import now <EOL> except ImportError : <EOL> now = datetime . now <EOL> try : <EOL> from django . contrib . gis . geos import * <EOL> except ImportError : <EOL> pass <EOL> from django_dynamic_fixture . fixture_algorithms . default_fixture import BaseDataFixture , GeoDjangoDataFixture <EOL> from django_dynamic_fixture . django_helper import field_is_unique <EOL> class AutoDataFiller ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . __data_controller_map = { } <EOL> self . __locks = { } <EOL> def next ( self , key ) : <EOL> if key not in self . __data_controller_map : <EOL> self . __data_controller_map [ key ] = <NUM_LIT:0> <EOL> self . __locks [ key ] = threading . RLock ( ) <EOL> self . __locks [ key ] . acquire ( ) <EOL> self . __data_controller_map [ key ] += <NUM_LIT:1> <EOL> value = self . __data_controller_map [ key ] <EOL> self . __locks [ key ] . release ( ) <EOL> return value <EOL> def current ( self , key ) : <EOL> if key not in self . __data_controller_map : <EOL> self . next ( key ) <EOL> return self . __data_controller_map [ key ] <EOL> class SequentialDataFixture ( BaseDataFixture , GeoDjangoDataFixture ) : <EOL> def __init__ ( self ) : <EOL> super ( SequentialDataFixture , self ) . __init__ ( ) <EOL> self . filler = AutoDataFiller ( ) <EOL> def get_value ( self , field , key ) : <EOL> return self . filler . next ( key ) <EOL> def integerfield_config ( self , field , key ) : <EOL> return self . get_value ( field , key ) <EOL> def smallintegerfield_config ( self , field , key ) : <EOL> return self . integerfield_config ( field , key ) <EOL> def positiveintegerfield_config ( self , field , key ) : <EOL> return self . integerfield_config ( field , key ) <EOL> def positivesmallintegerfield_config ( self , field , key ) : <EOL> return self . integerfield_config ( field , key ) <EOL> def bigintegerfield_config ( self , field , key ) : <EOL> return self . integerfield_config ( field , key ) <EOL> def floatfield_config ( self , field , key ) : <EOL> return float ( self . get_value ( field , key ) ) <EOL> def decimalfield_config ( self , field , key ) : <EOL> data = self . get_value ( field , key ) <EOL> number_of_digits = field . max_digits - field . decimal_places <EOL> max_value = <NUM_LIT:10> ** number_of_digits <EOL> data = data % max_value <EOL> return Decimal ( str ( data ) ) <EOL> def charfield_config ( self , field , key ) : <EOL> data = self . get_value ( field , key ) <EOL> if field . max_length : <EOL> max_value = ( <NUM_LIT:10> ** field . max_length ) - <NUM_LIT:1> <EOL> data = six . text_type ( data % max_value ) <EOL> data = data [ : field . max_length ] <EOL> else : <EOL> data = six . text_type ( data ) <EOL> return data <EOL> def textfield_config ( self , field , key ) : <EOL> return self . charfield_config ( field , key ) <EOL> def slugfield_config ( self , field , key ) : <EOL> return self . charfield_config ( field , key ) <EOL> def commaseparatedintegerfield_config ( self , field , key ) : <EOL> return self . charfield_config ( field , key ) <EOL> def booleanfield_config ( self , field , key ) : <EOL> return False <EOL> def nullbooleanfield_config ( self , field , key ) : <EOL> return None <EOL> def datefield_config ( self , field , key ) : <EOL> data = self . get_value ( field , key ) <EOL> return date . today ( ) - timedelta ( days = data ) <EOL> def timefield_config ( self , field , key ) : <EOL> data = self . get_value ( field , key ) <EOL> return now ( ) - timedelta ( seconds = data ) <EOL> def datetimefield_config ( self , field , key ) : <EOL> data = self . get_value ( field , key ) <EOL> return now ( ) - timedelta ( seconds = data ) <EOL> def emailfield_config ( self , field , key ) : <EOL> return six . text_type ( '<STR_LIT>' ) % self . get_value ( field , key ) <EOL> def urlfield_config ( self , field , key ) : <EOL> return six . text_type ( '<STR_LIT>' ) % self . get_value ( field , key ) <EOL> def ipaddressfield_config ( self , field , key ) : <EOL> data = self . get_value ( field , key ) <EOL> a = '<STR_LIT:1>' <EOL> b = '<STR_LIT:1>' <EOL> c = '<STR_LIT:1>' <EOL> d = data % <NUM_LIT> <EOL> return six . text_type ( '<STR_LIT>' ) % ( a , b , c , str ( d ) ) <EOL> def xmlfield_config ( self , field , key ) : <EOL> return six . text_type ( '<STR_LIT>' ) % self . get_value ( field , key ) <EOL> def filepathfield_config ( self , field , key ) : <EOL> return six . text_type ( self . get_value ( field , key ) ) <EOL> def filefield_config ( self , field , key ) : <EOL> return six . text_type ( self . get_value ( field , key ) ) <EOL> def imagefield_config ( self , field , key ) : <EOL> return six . text_type ( self . get_value ( field , key ) ) <EOL> class GlobalSequentialDataFixture ( SequentialDataFixture ) : <EOL> def get_value ( self , field , key ) : <EOL> return self . filler . next ( '<STR_LIT>' ) <EOL> class StaticSequentialDataFixture ( SequentialDataFixture ) : <EOL> def get_value ( self , field , key ) : <EOL> if field_is_unique ( field ) : <EOL> return self . filler . next ( key ) <EOL> else : <EOL> return self . filler . current ( key ) </s>
