<s> """<STR_LIT>""" <EOL> import decimal as dc <EOL> import datetime as dt <EOL> import locale as pylocale <EOL> from collections import defaultdict <EOL> from faker import Factory , Generator <EOL> from faker . config import DEFAULT_LOCALE , AVAILABLE_LOCALES <EOL> try : <EOL> from faker . config import PROVIDERS <EOL> except ImportError : <EOL> from faker . config import DEFAULT_PROVIDERS as PROVIDERS <EOL> from faker . providers import BaseProvider <EOL> GENRES = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:action>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> HOSTNAMES = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> COUNTRY_CODES = '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> HOSTZONES = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:info>" , "<STR_LIT:int>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT:name>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) + COUNTRY_CODES <EOL> USERNAMES = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:root>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT:user>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> class UTCZone ( dt . tzinfo ) : <EOL> """<STR_LIT>""" <EOL> utcoffset = dst = lambda s , d : dt . timedelta ( <NUM_LIT:0> ) <EOL> tzname = lambda s , d : "<STR_LIT>" <EOL> UTC = UTCZone ( ) <EOL> class MixerProvider ( BaseProvider ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , generator ) : <EOL> self . providers = [ ] <EOL> self . generator = generator <EOL> def load ( self , providers = PROVIDERS , locale = None ) : <EOL> if locale is None : <EOL> locale = self . generator . locale <EOL> for pname in providers : <EOL> pcls , lang_found = Factory . _get_provider_class ( pname , locale ) <EOL> provider = pcls ( self . generator ) <EOL> provider . __provider__ = pname <EOL> provider . __lang__ = lang_found <EOL> self . generator . add_provider ( provider ) <EOL> @ classmethod <EOL> def choices ( cls , elements = ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) , length = None ) : <EOL> """<STR_LIT>""" <EOL> if length is None : <EOL> length = len ( elements ) <EOL> return tuple ( cls . random_element ( elements ) for _ in range ( length ) ) <EOL> def big_integer ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . generator . random_int ( - <NUM_LIT> , <NUM_LIT> ) <EOL> def ip_generic ( self , protocol = None ) : <EOL> """<STR_LIT>""" <EOL> if protocol == '<STR_LIT>' : <EOL> return self . generator . ipv4 ( ) <EOL> if protocol == '<STR_LIT>' : <EOL> return self . generator . ipv6 ( ) <EOL> return self . generator . ipv4 ( ) if self . generator . boolean ( ) else self . generator . ipv6 ( ) <EOL> def positive_decimal ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . generator . pydecimal ( positive = True , ** kwargs ) <EOL> def positive_integer ( self , max = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> return self . random_int ( <NUM_LIT:0> , max = max ) <EOL> def small_integer ( self , min = - <NUM_LIT> , max = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> return self . random_int ( min = min , max = max ) <EOL> def small_positive_integer ( self , max = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> return self . random_int ( <NUM_LIT:0> , max = max ) <EOL> @ staticmethod <EOL> def uuid ( ) : <EOL> import uuid <EOL> return str ( uuid . uuid1 ( ) ) <EOL> @ classmethod <EOL> def genre ( cls ) : <EOL> return cls . random_element ( GENRES ) <EOL> @ classmethod <EOL> def percent ( cls ) : <EOL> return cls . random_int ( <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> @ classmethod <EOL> def percent_decimal ( cls ) : <EOL> return dc . Decimal ( "<STR_LIT>" % cls . random_int ( <NUM_LIT:0> , <NUM_LIT> ) ) + dc . Decimal ( '<STR_LIT>' ) <EOL> def title ( self ) : <EOL> words = self . generator . words ( <NUM_LIT:6> ) <EOL> return "<STR_LIT:U+0020>" . join ( words ) . title ( ) <EOL> def datetime ( self , start_date = '<STR_LIT>' , end_date = '<STR_LIT>' , tzinfo = False ) : <EOL> dt = self . generator . date_time_between ( start_date , end_date ) <EOL> if tzinfo : <EOL> dt = dt . replace ( tzinfo = UTC ) <EOL> return dt <EOL> def coordinates ( self ) : <EOL> return ( self . generator . latitude ( ) , self . generator . longitude ( ) ) <EOL> def hostzone ( self ) : <EOL> return self . generator . random_element ( HOSTZONES ) <EOL> def hostname ( self ) : <EOL> return "<STR_LIT>" % ( self . generator . random_element ( HOSTNAMES ) , self . hostzone ( ) ) <EOL> def email_address ( self ) : <EOL> return self . generator . parse ( "<STR_LIT>" ) <EOL> def alias ( self ) : <EOL> return self . random_element ( USERNAMES ) <EOL> def nickname ( self ) : <EOL> template = self . random_element ( ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) ) <EOL> return self . bothify ( self . generator . parse ( template ) ) <EOL> def pybytes ( self , size = <NUM_LIT:20> ) : <EOL> return self . pystr ( size ) . encode ( '<STR_LIT:utf-8>' ) <EOL> def date_time_this_month ( self , before_now = True , after_now = False ) : <EOL> """<STR_LIT>""" <EOL> now = dt . datetime . now ( ) <EOL> this_month_start = now . replace ( day = <NUM_LIT:1> , hour = <NUM_LIT:0> , minute = <NUM_LIT:0> , second = <NUM_LIT:0> , microsecond = <NUM_LIT:0> ) <EOL> next_month_start = dt . datetime ( now . year , ( now . month + <NUM_LIT:1> ) % <NUM_LIT:12> , <NUM_LIT:1> ) <EOL> if before_now and after_now : <EOL> return self . generator . date_time_between_dates ( this_month_start , next_month_start ) <EOL> if not before_now and after_now : <EOL> return self . generator . date_time_between_dates ( now , next_month_start ) <EOL> if not after_now and before_now : <EOL> return self . generator . date_time_between_dates ( this_month_start , now ) <EOL> return now <EOL> class MixerGenerator ( Generator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , locale = DEFAULT_LOCALE , providers = PROVIDERS , ** config ) : <EOL> self . _locale = None <EOL> self . _envs = defaultdict ( self . __create_env ) <EOL> self . locale = locale <EOL> super ( MixerGenerator , self ) . __init__ ( ** config ) <EOL> self . env . load ( providers ) <EOL> def __create_env ( self ) : <EOL> return MixerProvider ( self ) <EOL> def __getattr__ ( self , name ) : <EOL> return getattr ( self . env , name ) <EOL> @ property <EOL> def providers ( self ) : <EOL> return self . env . providers <EOL> @ providers . setter <EOL> def providers ( self , value ) : <EOL> self . env . providers = value <EOL> @ property <EOL> def locale ( self ) : <EOL> return self . _locale <EOL> @ locale . setter <EOL> def locale ( self , value ) : <EOL> value = pylocale . normalize ( value . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) ) . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> if value not in AVAILABLE_LOCALES : <EOL> value = DEFAULT_LOCALE <EOL> if value == self . _locale : <EOL> return None <EOL> nenv = self . _envs [ value ] <EOL> senv = self . env <EOL> self . _locale = value <EOL> if senv . providers and not nenv . providers : <EOL> nenv . load ( [ p . __provider__ for p in senv . providers ] , value ) <EOL> @ property <EOL> def env ( self ) : <EOL> return self . _envs [ self . _locale ] <EOL> def set_formatter ( self , name , method ) : <EOL> if not hasattr ( self . env , name ) : <EOL> setattr ( self . env , name , method ) <EOL> faker = MixerGenerator ( ) </s>
