<s> import os <EOL> from django . contrib . gis . geos import HAS_GEOS <EOL> from django . utils import text , timezone <EOL> from faker . generator import random <EOL> from . compat import django_version , HAS_PSYCOPG2 <EOL> def comma_sep_integers ( faker , field , * args , ** kwargs ) : <EOL> return '<STR_LIT:U+002C>' . join ( [ faker . random_int ( ) for _ in range ( <NUM_LIT:10> ) ] ) <EOL> def decimal ( faker , field , * args , ** kwargs ) : <EOL> right_digits = field . decimal_places <EOL> left_digits = field . max_digits - right_digits <EOL> return faker . pydecimal ( left_digits = left_digits , right_digits = right_digits , positive = True ) <EOL> def random_bytes ( faker , field , length , * args , ** kwargs ) : <EOL> return os . urandom ( length ) <EOL> def slug ( faker , field , count , * args , ** kwargs ) : <EOL> return text . slugify ( "<STR_LIT:U+0020>" . join ( faker . words ( nb = count ) ) ) <EOL> if HAS_GEOS : <EOL> from django . contrib . gis import geos <EOL> def point ( faker , field , srid ) : <EOL> lat = random . uniform ( - <NUM_LIT> , <NUM_LIT> ) <EOL> lng = random . uniform ( - <NUM_LIT> , <NUM_LIT> ) <EOL> if field . dim == <NUM_LIT:2> : <EOL> return geos . Point ( lat , lng , srid = srid ) <EOL> else : <EOL> alt = random . uniform ( - <NUM_LIT> , <NUM_LIT> ) <EOL> return geos . Point ( lat , lng , alt , srid = srid ) <EOL> def linestring ( faker , field , srid , * args , ** kwargs ) : <EOL> point_count = faker . random_int ( min = <NUM_LIT:2> , max = <NUM_LIT:10> ) <EOL> points = [ point ( faker , field , srid ) for _ in range ( point_count ) ] <EOL> return geos . LineString ( * points ) <EOL> def linearring ( faker , field , srid , * args , ** kwargs ) : <EOL> point_0 = point ( faker , field , srid ) <EOL> point_1 = point ( faker , field , srid ) <EOL> point_2 = point ( faker , field , srid ) <EOL> point_3 = geos . Point ( point_0 . x , point_0 . y ) <EOL> points = [ point_0 , point_1 , point_2 , point_3 ] <EOL> return geos . LinearRing ( * points ) <EOL> def polygon ( faker , field , srid , * args , ** kwargs ) : <EOL> ring = linearring ( faker , field , srid ) <EOL> return geos . Polygon ( ring ) <EOL> def collection ( faker , field , srid , element_func , geometry_class , * args , ** kwargs ) : <EOL> element_count = faker . random_int ( min = <NUM_LIT:1> , max = <NUM_LIT:10> ) <EOL> elements = [ element_func ( faker , field , srid ) for _ in range ( element_count ) ] <EOL> return geometry_class ( * elements ) <EOL> def multipoint ( faker , field , srid , * args , ** kwargs ) : <EOL> return collection ( faker , field , srid , point , geos . MultiPoint ) <EOL> def multilinestring ( faker , field , srid , * args , ** kwargs ) : <EOL> return collection ( faker , field , srid , linestring , geos . MultiLineString ) <EOL> def multipolygon ( faker , field , srid , * args , ** kwargs ) : <EOL> return collection ( faker , field , srid , polygon , geos . MultiPolygon ) <EOL> def geometrycollection ( faker , field , srid , * args , ** kwargs ) : <EOL> single_point = point ( faker , field , srid ) <EOL> points = collection ( faker , field , srid , point , geos . MultiPoint ) <EOL> geometries = [ single_point ] + points <EOL> return geos . GeometryCollection ( * geometries ) <EOL> if django_version >= ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:0> ) and HAS_PSYCOPG2 : <EOL> from psycopg2 . extras import DateRange , DateTimeTZRange , NumericRange <EOL> def array ( faker , field , * args , ** kwargs ) : <EOL> from . field_mappings import mappings_types <EOL> from . values import Evaluator <EOL> if field . size : <EOL> size = field . size <EOL> else : <EOL> size = <NUM_LIT:10> <EOL> element_count = faker . random_int ( min = <NUM_LIT:1> , max = size ) <EOL> evaluator = Evaluator ( faker = faker , factory = None , iteration = None ) <EOL> fake = mappings_types [ field . base_field . __class__ ] <EOL> return [ evaluator . evaluate_fake ( fake , field ) for _ in range ( element_count ) ] <EOL> def integerrange ( faker , field , min , max , * args , ** kwargs ) : <EOL> lower = faker . random_int ( min = min , max = max - <NUM_LIT:1> ) <EOL> upper = faker . random_int ( min = lower , max = max ) <EOL> return NumericRange ( lower , upper ) <EOL> def floatrange ( faker , field , * args , ** kwargs ) : <EOL> lower = random . uniform ( - <NUM_LIT> , <NUM_LIT> ) <EOL> upper = random . uniform ( lower , <NUM_LIT> ) <EOL> return NumericRange ( lower , upper ) <EOL> def datetimerange ( faker , field , * args , ** kwargs ) : <EOL> lower = timezone . make_aware ( faker . date_time ( ) ) <EOL> upper = timezone . make_aware ( faker . date_time_between_dates ( datetime_start = lower ) ) <EOL> return DateTimeTZRange ( lower , upper ) <EOL> def daterange ( faker , field , * args , ** kwargs ) : <EOL> lower = faker . date_time ( ) . date ( ) <EOL> upper = faker . date_time_between_dates ( datetime_start = lower ) . date ( ) <EOL> return DateRange ( lower , upper ) </s>
