<s> from __future__ import unicode_literals <EOL> from decimal import Decimal <EOL> import sys <EOL> from faker . providers . lorem . la import Provider as Lorem <EOL> from faker . generator import random <EOL> from . . import BaseProvider <EOL> if sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> : <EOL> string_types = ( basestring , ) <EOL> elif sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:3> : <EOL> string_types = ( str , bytes ) <EOL> else : <EOL> raise SystemError ( "<STR_LIT>" . format ( sys . version_info [ <NUM_LIT:0> ] ) ) <EOL> class Provider ( BaseProvider ) : <EOL> @ classmethod <EOL> def pybool ( cls ) : <EOL> return cls . random_int ( <NUM_LIT:0> , <NUM_LIT:1> ) == <NUM_LIT:1> <EOL> @ classmethod <EOL> def pystr ( cls , min_chars = None , max_chars = <NUM_LIT:20> ) : <EOL> """<STR_LIT>""" <EOL> if min_chars is None : <EOL> return "<STR_LIT>" . join ( cls . random_letter ( ) for i in range ( max_chars ) ) <EOL> else : <EOL> assert ( max_chars >= min_chars ) , "<STR_LIT>" <EOL> return "<STR_LIT>" . join ( cls . random_letter ( ) for i in range ( <NUM_LIT:0> , random . randint ( min_chars , max_chars ) ) ) <EOL> @ classmethod <EOL> def pyfloat ( cls , left_digits = None , right_digits = None , positive = False ) : <EOL> left_digits = left_digits or cls . random_int ( <NUM_LIT:1> , sys . float_info . dig ) <EOL> right_digits = right_digits or cls . random_int ( <NUM_LIT:0> , sys . float_info . dig - left_digits ) <EOL> sign = <NUM_LIT:1> if positive or cls . random_int ( <NUM_LIT:0> , <NUM_LIT:1> ) else - <NUM_LIT:1> <EOL> return float ( "<STR_LIT>" . format ( <EOL> sign * cls . random_number ( left_digits ) , cls . random_number ( right_digits ) <EOL> ) ) <EOL> @ classmethod <EOL> def pyint ( cls ) : <EOL> return cls . random_int ( ) <EOL> @ classmethod <EOL> def pydecimal ( cls , left_digits = None , right_digits = None , positive = False ) : <EOL> return Decimal ( str ( cls . pyfloat ( left_digits , right_digits , positive ) ) ) <EOL> def pytuple ( self , nb_elements = <NUM_LIT:10> , variable_nb_elements = True , * value_types ) : <EOL> return tuple ( self . pyset ( nb_elements , variable_nb_elements , * value_types ) ) <EOL> def pyset ( self , nb_elements = <NUM_LIT:10> , variable_nb_elements = True , * value_types ) : <EOL> return set ( self . _pyiterable ( nb_elements , variable_nb_elements , * value_types ) ) <EOL> def pylist ( self , nb_elements = <NUM_LIT:10> , variable_nb_elements = True , * value_types ) : <EOL> return list ( self . _pyiterable ( nb_elements , variable_nb_elements , * value_types ) ) <EOL> def pyiterable ( self , nb_elements = <NUM_LIT:10> , variable_nb_elements = True , * value_types ) : <EOL> return self . random_element ( [ self . pylist , self . pytuple , self . pyset ] ) ( nb_elements , variable_nb_elements , * value_types ) <EOL> def _random_type ( self , type_list ) : <EOL> value_type = self . random_element ( type_list ) <EOL> method_name = "<STR_LIT>" . format ( value_type ) <EOL> if hasattr ( self , method_name ) : <EOL> value_type = method_name <EOL> return self . generator . format ( value_type ) <EOL> def _pyiterable ( self , nb_elements = <NUM_LIT:10> , variable_nb_elements = True , * value_types ) : <EOL> value_types = [ t if isinstance ( t , string_types ) else getattr ( t , '<STR_LIT>' , type ( t ) . __name__ ) . lower ( ) <EOL> for t in value_types <EOL> if t not in [ '<STR_LIT>' , '<STR_LIT:list>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> if not value_types : <EOL> value_types = [ '<STR_LIT:str>' , '<STR_LIT:str>' , '<STR_LIT:str>' , '<STR_LIT:str>' , '<STR_LIT:float>' , '<STR_LIT:int>' , '<STR_LIT:int>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:email>' ] <EOL> if variable_nb_elements : <EOL> nb_elements = self . randomize_nb_elements ( nb_elements ) <EOL> for f in range ( nb_elements ) : <EOL> yield self . _random_type ( value_types ) <EOL> def pydict ( self , nb_elements = <NUM_LIT:10> , variable_nb_elements = True , * value_types ) : <EOL> """<STR_LIT>""" <EOL> if variable_nb_elements : <EOL> nb_elements = self . randomize_nb_elements ( nb_elements ) <EOL> return dict ( zip ( <EOL> Lorem . words ( nb_elements ) , <EOL> self . _pyiterable ( nb_elements , False , * value_types ) <EOL> ) ) <EOL> def pystruct ( self , count = <NUM_LIT:10> , * value_types ) : <EOL> value_types = [ t if isinstance ( t , string_types ) else getattr ( t , '<STR_LIT>' , type ( t ) . __name__ ) . lower ( ) <EOL> for t in value_types <EOL> if t != '<STR_LIT>' ] <EOL> if not value_types : <EOL> value_types = [ '<STR_LIT:str>' , '<STR_LIT:str>' , '<STR_LIT:str>' , '<STR_LIT:str>' , '<STR_LIT:float>' , '<STR_LIT:int>' , '<STR_LIT:int>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:email>' ] <EOL> l = [ ] <EOL> d = { } <EOL> nd = { } <EOL> for i in range ( count ) : <EOL> d [ Lorem . word ( ) ] = self . _random_type ( value_types ) <EOL> l . append ( self . _random_type ( value_types ) ) <EOL> nd [ Lorem . word ( ) ] = { <EOL> i : self . _random_type ( value_types ) , <EOL> i + <NUM_LIT:1> : [ self . _random_type ( value_types ) , self . _random_type ( value_types ) , self . _random_type ( value_types ) ] , <EOL> i + <NUM_LIT:2> : { <EOL> i : self . _random_type ( value_types ) , <EOL> i + <NUM_LIT:1> : self . _random_type ( value_types ) , <EOL> i + <NUM_LIT:2> : [ <EOL> self . _random_type ( value_types ) , <EOL> self . _random_type ( value_types ) <EOL> ] <EOL> } <EOL> } <EOL> return l , d , nd </s>
