id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
228,000
lk-geimfari/mimesis
mimesis/providers/person.py
Person.password
def password(self, length: int = 8, hashed: bool = False) -> str: """Generate a password or hash of password. :param length: Length of password. :param hashed: MD5 hash. :return: Password or hash of password. :Example: k6dv2odff9#4h """ text = ascii_letters + digits + punctuation password = ''.join([self.random.choice(text) for _ in range(length)]) if hashed: md5 = hashlib.md5() md5.update(password.encode()) return md5.hexdigest() else: return password
python
def password(self, length: int = 8, hashed: bool = False) -> str: """Generate a password or hash of password. :param length: Length of password. :param hashed: MD5 hash. :return: Password or hash of password. :Example: k6dv2odff9#4h """ text = ascii_letters + digits + punctuation password = ''.join([self.random.choice(text) for _ in range(length)]) if hashed: md5 = hashlib.md5() md5.update(password.encode()) return md5.hexdigest() else: return password
[ "def", "password", "(", "self", ",", "length", ":", "int", "=", "8", ",", "hashed", ":", "bool", "=", "False", ")", "->", "str", ":", "text", "=", "ascii_letters", "+", "digits", "+", "punctuation", "password", "=", "''", ".", "join", "(", "[", "self", ".", "random", ".", "choice", "(", "text", ")", "for", "_", "in", "range", "(", "length", ")", "]", ")", "if", "hashed", ":", "md5", "=", "hashlib", ".", "md5", "(", ")", "md5", ".", "update", "(", "password", ".", "encode", "(", ")", ")", "return", "md5", ".", "hexdigest", "(", ")", "else", ":", "return", "password" ]
Generate a password or hash of password. :param length: Length of password. :param hashed: MD5 hash. :return: Password or hash of password. :Example: k6dv2odff9#4h
[ "Generate", "a", "password", "or", "hash", "of", "password", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L213-L231
228,001
lk-geimfari/mimesis
mimesis/providers/person.py
Person.email
def email(self, domains: Union[tuple, list] = None) -> str: """Generate a random email. :param domains: List of custom domains for emails. :type domains: list or tuple :return: Email address. :Example: foretime10@live.com """ if not domains: domains = EMAIL_DOMAINS domain = self.random.choice(domains) name = self.username(template='ld') return '{name}{domain}'.format( name=name, domain=domain, )
python
def email(self, domains: Union[tuple, list] = None) -> str: """Generate a random email. :param domains: List of custom domains for emails. :type domains: list or tuple :return: Email address. :Example: foretime10@live.com """ if not domains: domains = EMAIL_DOMAINS domain = self.random.choice(domains) name = self.username(template='ld') return '{name}{domain}'.format( name=name, domain=domain, )
[ "def", "email", "(", "self", ",", "domains", ":", "Union", "[", "tuple", ",", "list", "]", "=", "None", ")", "->", "str", ":", "if", "not", "domains", ":", "domains", "=", "EMAIL_DOMAINS", "domain", "=", "self", ".", "random", ".", "choice", "(", "domains", ")", "name", "=", "self", ".", "username", "(", "template", "=", "'ld'", ")", "return", "'{name}{domain}'", ".", "format", "(", "name", "=", "name", ",", "domain", "=", "domain", ",", ")" ]
Generate a random email. :param domains: List of custom domains for emails. :type domains: list or tuple :return: Email address. :Example: foretime10@live.com
[ "Generate", "a", "random", "email", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L233-L251
228,002
lk-geimfari/mimesis
mimesis/providers/person.py
Person.social_media_profile
def social_media_profile(self, site: Optional[SocialNetwork] = None) -> str: """Generate profile for random social network. :return: Profile in some network. :Example: http://facebook.com/some_user """ key = self._validate_enum(site, SocialNetwork) website = SOCIAL_NETWORKS[key] url = 'https://www.' + website return url.format(self.username())
python
def social_media_profile(self, site: Optional[SocialNetwork] = None) -> str: """Generate profile for random social network. :return: Profile in some network. :Example: http://facebook.com/some_user """ key = self._validate_enum(site, SocialNetwork) website = SOCIAL_NETWORKS[key] url = 'https://www.' + website return url.format(self.username())
[ "def", "social_media_profile", "(", "self", ",", "site", ":", "Optional", "[", "SocialNetwork", "]", "=", "None", ")", "->", "str", ":", "key", "=", "self", ".", "_validate_enum", "(", "site", ",", "SocialNetwork", ")", "website", "=", "SOCIAL_NETWORKS", "[", "key", "]", "url", "=", "'https://www.'", "+", "website", "return", "url", ".", "format", "(", "self", ".", "username", "(", ")", ")" ]
Generate profile for random social network. :return: Profile in some network. :Example: http://facebook.com/some_user
[ "Generate", "profile", "for", "random", "social", "network", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L253-L265
228,003
lk-geimfari/mimesis
mimesis/providers/person.py
Person.gender
def gender(self, iso5218: bool = False, symbol: bool = False) -> Union[str, int]: """Get a random gender. Get a random title of gender, code for the representation of human sexes is an international standard that defines a representation of human sexes through a language-neutral single-digit code or symbol of gender. :param iso5218: Codes for the representation of human sexes is an international standard (0 - not known, 1 - male, 2 - female, 9 - not applicable). :param symbol: Symbol of gender. :return: Title of gender. :Example: Male """ if iso5218: return self.random.choice([0, 1, 2, 9]) if symbol: return self.random.choice(GENDER_SYMBOLS) return self.random.choice(self._data['gender'])
python
def gender(self, iso5218: bool = False, symbol: bool = False) -> Union[str, int]: """Get a random gender. Get a random title of gender, code for the representation of human sexes is an international standard that defines a representation of human sexes through a language-neutral single-digit code or symbol of gender. :param iso5218: Codes for the representation of human sexes is an international standard (0 - not known, 1 - male, 2 - female, 9 - not applicable). :param symbol: Symbol of gender. :return: Title of gender. :Example: Male """ if iso5218: return self.random.choice([0, 1, 2, 9]) if symbol: return self.random.choice(GENDER_SYMBOLS) return self.random.choice(self._data['gender'])
[ "def", "gender", "(", "self", ",", "iso5218", ":", "bool", "=", "False", ",", "symbol", ":", "bool", "=", "False", ")", "->", "Union", "[", "str", ",", "int", "]", ":", "if", "iso5218", ":", "return", "self", ".", "random", ".", "choice", "(", "[", "0", ",", "1", ",", "2", ",", "9", "]", ")", "if", "symbol", ":", "return", "self", ".", "random", ".", "choice", "(", "GENDER_SYMBOLS", ")", "return", "self", ".", "random", ".", "choice", "(", "self", ".", "_data", "[", "'gender'", "]", ")" ]
Get a random gender. Get a random title of gender, code for the representation of human sexes is an international standard that defines a representation of human sexes through a language-neutral single-digit code or symbol of gender. :param iso5218: Codes for the representation of human sexes is an international standard (0 - not known, 1 - male, 2 - female, 9 - not applicable). :param symbol: Symbol of gender. :return: Title of gender. :Example: Male
[ "Get", "a", "random", "gender", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L267-L291
228,004
lk-geimfari/mimesis
mimesis/providers/person.py
Person.weight
def weight(self, minimum: int = 38, maximum: int = 90) -> int: """Generate a random weight in Kg. :param minimum: min value :param maximum: max value :return: Weight. :Example: 48. """ weight = self.random.randint(minimum, maximum) return weight
python
def weight(self, minimum: int = 38, maximum: int = 90) -> int: """Generate a random weight in Kg. :param minimum: min value :param maximum: max value :return: Weight. :Example: 48. """ weight = self.random.randint(minimum, maximum) return weight
[ "def", "weight", "(", "self", ",", "minimum", ":", "int", "=", "38", ",", "maximum", ":", "int", "=", "90", ")", "->", "int", ":", "weight", "=", "self", ".", "random", ".", "randint", "(", "minimum", ",", "maximum", ")", "return", "weight" ]
Generate a random weight in Kg. :param minimum: min value :param maximum: max value :return: Weight. :Example: 48.
[ "Generate", "a", "random", "weight", "in", "Kg", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L306-L317
228,005
lk-geimfari/mimesis
mimesis/providers/person.py
Person.occupation
def occupation(self) -> str: """Get a random job. :return: The name of job. :Example: Programmer. """ jobs = self._data['occupation'] return self.random.choice(jobs)
python
def occupation(self) -> str: """Get a random job. :return: The name of job. :Example: Programmer. """ jobs = self._data['occupation'] return self.random.choice(jobs)
[ "def", "occupation", "(", "self", ")", "->", "str", ":", "jobs", "=", "self", ".", "_data", "[", "'occupation'", "]", "return", "self", ".", "random", ".", "choice", "(", "jobs", ")" ]
Get a random job. :return: The name of job. :Example: Programmer.
[ "Get", "a", "random", "job", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L344-L353
228,006
lk-geimfari/mimesis
mimesis/providers/person.py
Person.political_views
def political_views(self) -> str: """Get a random political views. :return: Political views. :Example: Liberal. """ views = self._data['political_views'] return self.random.choice(views)
python
def political_views(self) -> str: """Get a random political views. :return: Political views. :Example: Liberal. """ views = self._data['political_views'] return self.random.choice(views)
[ "def", "political_views", "(", "self", ")", "->", "str", ":", "views", "=", "self", ".", "_data", "[", "'political_views'", "]", "return", "self", ".", "random", ".", "choice", "(", "views", ")" ]
Get a random political views. :return: Political views. :Example: Liberal.
[ "Get", "a", "random", "political", "views", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L355-L364
228,007
lk-geimfari/mimesis
mimesis/providers/person.py
Person.worldview
def worldview(self) -> str: """Get a random worldview. :return: Worldview. :Example: Pantheism. """ views = self._data['worldview'] return self.random.choice(views)
python
def worldview(self) -> str: """Get a random worldview. :return: Worldview. :Example: Pantheism. """ views = self._data['worldview'] return self.random.choice(views)
[ "def", "worldview", "(", "self", ")", "->", "str", ":", "views", "=", "self", ".", "_data", "[", "'worldview'", "]", "return", "self", ".", "random", ".", "choice", "(", "views", ")" ]
Get a random worldview. :return: Worldview. :Example: Pantheism.
[ "Get", "a", "random", "worldview", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L366-L375
228,008
lk-geimfari/mimesis
mimesis/providers/person.py
Person.views_on
def views_on(self) -> str: """Get a random views on. :return: Views on. :Example: Negative. """ views = self._data['views_on'] return self.random.choice(views)
python
def views_on(self) -> str: """Get a random views on. :return: Views on. :Example: Negative. """ views = self._data['views_on'] return self.random.choice(views)
[ "def", "views_on", "(", "self", ")", "->", "str", ":", "views", "=", "self", ".", "_data", "[", "'views_on'", "]", "return", "self", ".", "random", ".", "choice", "(", "views", ")" ]
Get a random views on. :return: Views on. :Example: Negative.
[ "Get", "a", "random", "views", "on", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L377-L386
228,009
lk-geimfari/mimesis
mimesis/providers/person.py
Person.nationality
def nationality(self, gender: Optional[Gender] = None) -> str: """Get a random nationality. :param gender: Gender. :return: Nationality. :Example: Russian """ nationalities = self._data['nationality'] # Separated by gender if isinstance(nationalities, dict): key = self._validate_enum(gender, Gender) nationalities = nationalities[key] return self.random.choice(nationalities)
python
def nationality(self, gender: Optional[Gender] = None) -> str: """Get a random nationality. :param gender: Gender. :return: Nationality. :Example: Russian """ nationalities = self._data['nationality'] # Separated by gender if isinstance(nationalities, dict): key = self._validate_enum(gender, Gender) nationalities = nationalities[key] return self.random.choice(nationalities)
[ "def", "nationality", "(", "self", ",", "gender", ":", "Optional", "[", "Gender", "]", "=", "None", ")", "->", "str", ":", "nationalities", "=", "self", ".", "_data", "[", "'nationality'", "]", "# Separated by gender", "if", "isinstance", "(", "nationalities", ",", "dict", ")", ":", "key", "=", "self", ".", "_validate_enum", "(", "gender", ",", "Gender", ")", "nationalities", "=", "nationalities", "[", "key", "]", "return", "self", ".", "random", ".", "choice", "(", "nationalities", ")" ]
Get a random nationality. :param gender: Gender. :return: Nationality. :Example: Russian
[ "Get", "a", "random", "nationality", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L388-L404
228,010
lk-geimfari/mimesis
mimesis/providers/person.py
Person.university
def university(self) -> str: """Get a random university. :return: University name. :Example: MIT. """ universities = self._data['university'] return self.random.choice(universities)
python
def university(self) -> str: """Get a random university. :return: University name. :Example: MIT. """ universities = self._data['university'] return self.random.choice(universities)
[ "def", "university", "(", "self", ")", "->", "str", ":", "universities", "=", "self", ".", "_data", "[", "'university'", "]", "return", "self", ".", "random", ".", "choice", "(", "universities", ")" ]
Get a random university. :return: University name. :Example: MIT.
[ "Get", "a", "random", "university", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L406-L415
228,011
lk-geimfari/mimesis
mimesis/providers/person.py
Person.academic_degree
def academic_degree(self) -> str: """Get a random academic degree. :return: Degree. :Example: Bachelor. """ degrees = self._data['academic_degree'] return self.random.choice(degrees)
python
def academic_degree(self) -> str: """Get a random academic degree. :return: Degree. :Example: Bachelor. """ degrees = self._data['academic_degree'] return self.random.choice(degrees)
[ "def", "academic_degree", "(", "self", ")", "->", "str", ":", "degrees", "=", "self", ".", "_data", "[", "'academic_degree'", "]", "return", "self", ".", "random", ".", "choice", "(", "degrees", ")" ]
Get a random academic degree. :return: Degree. :Example: Bachelor.
[ "Get", "a", "random", "academic", "degree", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L417-L426
228,012
lk-geimfari/mimesis
mimesis/providers/person.py
Person.language
def language(self) -> str: """Get a random language. :return: Random language. :Example: Irish. """ languages = self._data['language'] return self.random.choice(languages)
python
def language(self) -> str: """Get a random language. :return: Random language. :Example: Irish. """ languages = self._data['language'] return self.random.choice(languages)
[ "def", "language", "(", "self", ")", "->", "str", ":", "languages", "=", "self", ".", "_data", "[", "'language'", "]", "return", "self", ".", "random", ".", "choice", "(", "languages", ")" ]
Get a random language. :return: Random language. :Example: Irish.
[ "Get", "a", "random", "language", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L428-L437
228,013
lk-geimfari/mimesis
mimesis/providers/person.py
Person.telephone
def telephone(self, mask: str = '', placeholder: str = '#') -> str: """Generate a random phone number. :param mask: Mask for formatting number. :param placeholder: A placeholder for a mask (default is #). :return: Phone number. :Example: +7-(963)-409-11-22. """ if not mask: code = self.random.choice(CALLING_CODES) default = '{}-(###)-###-####'.format(code) masks = self._data.get('telephone_fmt', [default]) mask = self.random.choice(masks) return self.random.custom_code(mask=mask, digit=placeholder)
python
def telephone(self, mask: str = '', placeholder: str = '#') -> str: """Generate a random phone number. :param mask: Mask for formatting number. :param placeholder: A placeholder for a mask (default is #). :return: Phone number. :Example: +7-(963)-409-11-22. """ if not mask: code = self.random.choice(CALLING_CODES) default = '{}-(###)-###-####'.format(code) masks = self._data.get('telephone_fmt', [default]) mask = self.random.choice(masks) return self.random.custom_code(mask=mask, digit=placeholder)
[ "def", "telephone", "(", "self", ",", "mask", ":", "str", "=", "''", ",", "placeholder", ":", "str", "=", "'#'", ")", "->", "str", ":", "if", "not", "mask", ":", "code", "=", "self", ".", "random", ".", "choice", "(", "CALLING_CODES", ")", "default", "=", "'{}-(###)-###-####'", ".", "format", "(", "code", ")", "masks", "=", "self", ".", "_data", ".", "get", "(", "'telephone_fmt'", ",", "[", "default", "]", ")", "mask", "=", "self", ".", "random", ".", "choice", "(", "masks", ")", "return", "self", ".", "random", ".", "custom_code", "(", "mask", "=", "mask", ",", "digit", "=", "placeholder", ")" ]
Generate a random phone number. :param mask: Mask for formatting number. :param placeholder: A placeholder for a mask (default is #). :return: Phone number. :Example: +7-(963)-409-11-22.
[ "Generate", "a", "random", "phone", "number", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L439-L455
228,014
lk-geimfari/mimesis
mimesis/providers/person.py
Person.avatar
def avatar(self, size: int = 256) -> str: """Generate a random avatar.. :param size: Size of avatar. :return: Link to avatar. """ url = 'https://api.adorable.io/avatars/{0}/{1}.png' return url.format(size, self.password(hashed=True))
python
def avatar(self, size: int = 256) -> str: """Generate a random avatar.. :param size: Size of avatar. :return: Link to avatar. """ url = 'https://api.adorable.io/avatars/{0}/{1}.png' return url.format(size, self.password(hashed=True))
[ "def", "avatar", "(", "self", ",", "size", ":", "int", "=", "256", ")", "->", "str", ":", "url", "=", "'https://api.adorable.io/avatars/{0}/{1}.png'", "return", "url", ".", "format", "(", "size", ",", "self", ".", "password", "(", "hashed", "=", "True", ")", ")" ]
Generate a random avatar.. :param size: Size of avatar. :return: Link to avatar.
[ "Generate", "a", "random", "avatar", ".." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L457-L464
228,015
lk-geimfari/mimesis
mimesis/providers/person.py
Person.identifier
def identifier(self, mask: str = '##-##/##') -> str: """Generate a random identifier by mask. With this method you can generate any identifiers that you need. Simply select the mask that you need. :param mask: The mask. Here ``@`` is a placeholder for characters and ``#`` is placeholder for digits. :return: An identifier. :Example: 07-97/04 """ return self.random.custom_code(mask=mask)
python
def identifier(self, mask: str = '##-##/##') -> str: """Generate a random identifier by mask. With this method you can generate any identifiers that you need. Simply select the mask that you need. :param mask: The mask. Here ``@`` is a placeholder for characters and ``#`` is placeholder for digits. :return: An identifier. :Example: 07-97/04 """ return self.random.custom_code(mask=mask)
[ "def", "identifier", "(", "self", ",", "mask", ":", "str", "=", "'##-##/##'", ")", "->", "str", ":", "return", "self", ".", "random", ".", "custom_code", "(", "mask", "=", "mask", ")" ]
Generate a random identifier by mask. With this method you can generate any identifiers that you need. Simply select the mask that you need. :param mask: The mask. Here ``@`` is a placeholder for characters and ``#`` is placeholder for digits. :return: An identifier. :Example: 07-97/04
[ "Generate", "a", "random", "identifier", "by", "mask", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/person.py#L466-L480
228,016
lk-geimfari/mimesis
mimesis/providers/clothing.py
Clothing.custom_size
def custom_size(self, minimum: int = 40, maximum: int = 62) -> int: """Generate clothing size using custom format. :param minimum: Minimum value. :param maximum: Maximum value. :return: Clothing size. """ return self.random.randint(minimum, maximum)
python
def custom_size(self, minimum: int = 40, maximum: int = 62) -> int: """Generate clothing size using custom format. :param minimum: Minimum value. :param maximum: Maximum value. :return: Clothing size. """ return self.random.randint(minimum, maximum)
[ "def", "custom_size", "(", "self", ",", "minimum", ":", "int", "=", "40", ",", "maximum", ":", "int", "=", "62", ")", "->", "int", ":", "return", "self", ".", "random", ".", "randint", "(", "minimum", ",", "maximum", ")" ]
Generate clothing size using custom format. :param minimum: Minimum value. :param maximum: Maximum value. :return: Clothing size.
[ "Generate", "clothing", "size", "using", "custom", "format", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/clothing.py#L33-L40
228,017
lk-geimfari/mimesis
mimesis/shortcuts.py
luhn_checksum
def luhn_checksum(num: str) -> str: """Calculate a checksum for num using the Luhn algorithm. :param num: The number to calculate a checksum for as a string. :return: Checksum for number. """ check = 0 for i, s in enumerate(reversed(num)): sx = int(s) sx = sx * 2 if i % 2 == 0 else sx sx = sx - 9 if sx > 9 else sx check += sx return str(check * 9 % 10)
python
def luhn_checksum(num: str) -> str: """Calculate a checksum for num using the Luhn algorithm. :param num: The number to calculate a checksum for as a string. :return: Checksum for number. """ check = 0 for i, s in enumerate(reversed(num)): sx = int(s) sx = sx * 2 if i % 2 == 0 else sx sx = sx - 9 if sx > 9 else sx check += sx return str(check * 9 % 10)
[ "def", "luhn_checksum", "(", "num", ":", "str", ")", "->", "str", ":", "check", "=", "0", "for", "i", ",", "s", "in", "enumerate", "(", "reversed", "(", "num", ")", ")", ":", "sx", "=", "int", "(", "s", ")", "sx", "=", "sx", "*", "2", "if", "i", "%", "2", "==", "0", "else", "sx", "sx", "=", "sx", "-", "9", "if", "sx", ">", "9", "else", "sx", "check", "+=", "sx", "return", "str", "(", "check", "*", "9", "%", "10", ")" ]
Calculate a checksum for num using the Luhn algorithm. :param num: The number to calculate a checksum for as a string. :return: Checksum for number.
[ "Calculate", "a", "checksum", "for", "num", "using", "the", "Luhn", "algorithm", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/shortcuts.py#L14-L26
228,018
lk-geimfari/mimesis
mimesis/shortcuts.py
download_image
def download_image(url: str = '', save_path: str = '', unverified_ctx: bool = False) -> Union[None, str]: """Download image and save in current directory on local machine. :param url: URL to image. :param save_path: Saving path. :param unverified_ctx: Create unverified context. :return: Path to downloaded image. :rtype: str or None """ if unverified_ctx: ssl._create_default_https_context = ssl._create_unverified_context if url: image_name = url.rsplit('/')[-1] splitted_name = image_name.rsplit('.') if len(splitted_name) < 2: image_name = '{}.jpg'.format(uuid4()) else: image_name = '{}.{}'.format(uuid4(), splitted_name[-1]) full_image_path = path.join(save_path, image_name) request.urlretrieve(url, full_image_path) return full_image_path return None
python
def download_image(url: str = '', save_path: str = '', unverified_ctx: bool = False) -> Union[None, str]: """Download image and save in current directory on local machine. :param url: URL to image. :param save_path: Saving path. :param unverified_ctx: Create unverified context. :return: Path to downloaded image. :rtype: str or None """ if unverified_ctx: ssl._create_default_https_context = ssl._create_unverified_context if url: image_name = url.rsplit('/')[-1] splitted_name = image_name.rsplit('.') if len(splitted_name) < 2: image_name = '{}.jpg'.format(uuid4()) else: image_name = '{}.{}'.format(uuid4(), splitted_name[-1]) full_image_path = path.join(save_path, image_name) request.urlretrieve(url, full_image_path) return full_image_path return None
[ "def", "download_image", "(", "url", ":", "str", "=", "''", ",", "save_path", ":", "str", "=", "''", ",", "unverified_ctx", ":", "bool", "=", "False", ")", "->", "Union", "[", "None", ",", "str", "]", ":", "if", "unverified_ctx", ":", "ssl", ".", "_create_default_https_context", "=", "ssl", ".", "_create_unverified_context", "if", "url", ":", "image_name", "=", "url", ".", "rsplit", "(", "'/'", ")", "[", "-", "1", "]", "splitted_name", "=", "image_name", ".", "rsplit", "(", "'.'", ")", "if", "len", "(", "splitted_name", ")", "<", "2", ":", "image_name", "=", "'{}.jpg'", ".", "format", "(", "uuid4", "(", ")", ")", "else", ":", "image_name", "=", "'{}.{}'", ".", "format", "(", "uuid4", "(", ")", ",", "splitted_name", "[", "-", "1", "]", ")", "full_image_path", "=", "path", ".", "join", "(", "save_path", ",", "image_name", ")", "request", ".", "urlretrieve", "(", "url", ",", "full_image_path", ")", "return", "full_image_path", "return", "None" ]
Download image and save in current directory on local machine. :param url: URL to image. :param save_path: Saving path. :param unverified_ctx: Create unverified context. :return: Path to downloaded image. :rtype: str or None
[ "Download", "image", "and", "save", "in", "current", "directory", "on", "local", "machine", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/shortcuts.py#L29-L53
228,019
lk-geimfari/mimesis
mimesis/builtins/pl.py
PolandSpecProvider.nip
def nip(self) -> str: """Generate random valid 10-digit NIP. :return: Valid 10-digit NIP """ nip_digits = [int(d) for d in str(self.random.randint(101, 998))] nip_digits += [self.random.randint(0, 9) for _ in range(6)] nip_coefficients = (6, 5, 7, 2, 3, 4, 5, 6, 7) sum_v = sum([nc * nd for nc, nd in zip(nip_coefficients, nip_digits)]) checksum_digit = sum_v % 11 if checksum_digit > 9: return self.nip() nip_digits.append(checksum_digit) return ''.join(str(d) for d in nip_digits)
python
def nip(self) -> str: """Generate random valid 10-digit NIP. :return: Valid 10-digit NIP """ nip_digits = [int(d) for d in str(self.random.randint(101, 998))] nip_digits += [self.random.randint(0, 9) for _ in range(6)] nip_coefficients = (6, 5, 7, 2, 3, 4, 5, 6, 7) sum_v = sum([nc * nd for nc, nd in zip(nip_coefficients, nip_digits)]) checksum_digit = sum_v % 11 if checksum_digit > 9: return self.nip() nip_digits.append(checksum_digit) return ''.join(str(d) for d in nip_digits)
[ "def", "nip", "(", "self", ")", "->", "str", ":", "nip_digits", "=", "[", "int", "(", "d", ")", "for", "d", "in", "str", "(", "self", ".", "random", ".", "randint", "(", "101", ",", "998", ")", ")", "]", "nip_digits", "+=", "[", "self", ".", "random", ".", "randint", "(", "0", ",", "9", ")", "for", "_", "in", "range", "(", "6", ")", "]", "nip_coefficients", "=", "(", "6", ",", "5", ",", "7", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ")", "sum_v", "=", "sum", "(", "[", "nc", "*", "nd", "for", "nc", ",", "nd", "in", "zip", "(", "nip_coefficients", ",", "nip_digits", ")", "]", ")", "checksum_digit", "=", "sum_v", "%", "11", "if", "checksum_digit", ">", "9", ":", "return", "self", ".", "nip", "(", ")", "nip_digits", ".", "append", "(", "checksum_digit", ")", "return", "''", ".", "join", "(", "str", "(", "d", ")", "for", "d", "in", "nip_digits", ")" ]
Generate random valid 10-digit NIP. :return: Valid 10-digit NIP
[ "Generate", "random", "valid", "10", "-", "digit", "NIP", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/builtins/pl.py#L25-L40
228,020
lk-geimfari/mimesis
mimesis/builtins/pl.py
PolandSpecProvider.pesel
def pesel(self, birth_date: DateTime = None, gender: Gender = None) -> str: """Generate random 11-digit PESEL. :param birth_date: Initial birth date (optional) :param gender: Gender of person :return: Valid 11-digit PESEL """ date_object = birth_date if not date_object: date_object = Datetime().datetime(1940, 2018) year = date_object.date().year month = date_object.date().month day = date_object.date().day pesel_digits = [int(d) for d in str(year)][-2:] if 1800 <= year <= 1899: month += 80 elif 2000 <= year <= 2099: month += 20 elif 2100 <= year <= 2199: month += 40 elif 2200 <= year <= 2299: month += 60 pesel_digits += [int(d) for d in '{:02d}'.format(month)] pesel_digits += [int(d) for d in '{:02d}'.format(day)] series_number = self.random.randint(0, 999) pesel_digits += [int(d) for d in '{:03d}'.format(series_number)] if gender == Gender.MALE: gender_digit = self.random.choice((1, 3, 5, 7, 9)) elif gender == Gender.FEMALE: gender_digit = self.random.choice((0, 2, 4, 6, 8)) else: gender_digit = self.random.choice(range(10)) pesel_digits.append(gender_digit) pesel_coeffs = (9, 7, 3, 1, 9, 7, 3, 1, 9, 7) sum_v = sum([nc * nd for nc, nd in zip(pesel_coeffs, pesel_digits)]) checksum_digit = sum_v % 10 pesel_digits.append(checksum_digit) return ''.join(str(d) for d in pesel_digits)
python
def pesel(self, birth_date: DateTime = None, gender: Gender = None) -> str: """Generate random 11-digit PESEL. :param birth_date: Initial birth date (optional) :param gender: Gender of person :return: Valid 11-digit PESEL """ date_object = birth_date if not date_object: date_object = Datetime().datetime(1940, 2018) year = date_object.date().year month = date_object.date().month day = date_object.date().day pesel_digits = [int(d) for d in str(year)][-2:] if 1800 <= year <= 1899: month += 80 elif 2000 <= year <= 2099: month += 20 elif 2100 <= year <= 2199: month += 40 elif 2200 <= year <= 2299: month += 60 pesel_digits += [int(d) for d in '{:02d}'.format(month)] pesel_digits += [int(d) for d in '{:02d}'.format(day)] series_number = self.random.randint(0, 999) pesel_digits += [int(d) for d in '{:03d}'.format(series_number)] if gender == Gender.MALE: gender_digit = self.random.choice((1, 3, 5, 7, 9)) elif gender == Gender.FEMALE: gender_digit = self.random.choice((0, 2, 4, 6, 8)) else: gender_digit = self.random.choice(range(10)) pesel_digits.append(gender_digit) pesel_coeffs = (9, 7, 3, 1, 9, 7, 3, 1, 9, 7) sum_v = sum([nc * nd for nc, nd in zip(pesel_coeffs, pesel_digits)]) checksum_digit = sum_v % 10 pesel_digits.append(checksum_digit) return ''.join(str(d) for d in pesel_digits)
[ "def", "pesel", "(", "self", ",", "birth_date", ":", "DateTime", "=", "None", ",", "gender", ":", "Gender", "=", "None", ")", "->", "str", ":", "date_object", "=", "birth_date", "if", "not", "date_object", ":", "date_object", "=", "Datetime", "(", ")", ".", "datetime", "(", "1940", ",", "2018", ")", "year", "=", "date_object", ".", "date", "(", ")", ".", "year", "month", "=", "date_object", ".", "date", "(", ")", ".", "month", "day", "=", "date_object", ".", "date", "(", ")", ".", "day", "pesel_digits", "=", "[", "int", "(", "d", ")", "for", "d", "in", "str", "(", "year", ")", "]", "[", "-", "2", ":", "]", "if", "1800", "<=", "year", "<=", "1899", ":", "month", "+=", "80", "elif", "2000", "<=", "year", "<=", "2099", ":", "month", "+=", "20", "elif", "2100", "<=", "year", "<=", "2199", ":", "month", "+=", "40", "elif", "2200", "<=", "year", "<=", "2299", ":", "month", "+=", "60", "pesel_digits", "+=", "[", "int", "(", "d", ")", "for", "d", "in", "'{:02d}'", ".", "format", "(", "month", ")", "]", "pesel_digits", "+=", "[", "int", "(", "d", ")", "for", "d", "in", "'{:02d}'", ".", "format", "(", "day", ")", "]", "series_number", "=", "self", ".", "random", ".", "randint", "(", "0", ",", "999", ")", "pesel_digits", "+=", "[", "int", "(", "d", ")", "for", "d", "in", "'{:03d}'", ".", "format", "(", "series_number", ")", "]", "if", "gender", "==", "Gender", ".", "MALE", ":", "gender_digit", "=", "self", ".", "random", ".", "choice", "(", "(", "1", ",", "3", ",", "5", ",", "7", ",", "9", ")", ")", "elif", "gender", "==", "Gender", ".", "FEMALE", ":", "gender_digit", "=", "self", ".", "random", ".", "choice", "(", "(", "0", ",", "2", ",", "4", ",", "6", ",", "8", ")", ")", "else", ":", "gender_digit", "=", "self", ".", "random", ".", "choice", "(", "range", "(", "10", ")", ")", "pesel_digits", ".", "append", "(", "gender_digit", ")", "pesel_coeffs", "=", "(", "9", ",", "7", ",", "3", ",", "1", ",", "9", ",", "7", ",", "3", ",", "1", ",", "9", ",", "7", ")", "sum_v", "=", "sum", "(", "[", "nc", "*", "nd", "for", "nc", ",", "nd", "in", "zip", "(", "pesel_coeffs", ",", "pesel_digits", ")", "]", ")", "checksum_digit", "=", "sum_v", "%", "10", "pesel_digits", ".", "append", "(", "checksum_digit", ")", "return", "''", ".", "join", "(", "str", "(", "d", ")", "for", "d", "in", "pesel_digits", ")" ]
Generate random 11-digit PESEL. :param birth_date: Initial birth date (optional) :param gender: Gender of person :return: Valid 11-digit PESEL
[ "Generate", "random", "11", "-", "digit", "PESEL", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/builtins/pl.py#L42-L86
228,021
lk-geimfari/mimesis
mimesis/builtins/pl.py
PolandSpecProvider.regon
def regon(self) -> str: """Generate random valid 9-digit REGON. :return: Valid 9-digit REGON """ regon_coeffs = (8, 9, 2, 3, 4, 5, 6, 7) regon_digits = [self.random.randint(0, 9) for _ in range(8)] sum_v = sum([nc * nd for nc, nd in zip(regon_coeffs, regon_digits)]) checksum_digit = sum_v % 11 if checksum_digit > 9: checksum_digit = 0 regon_digits.append(checksum_digit) return ''.join(str(d) for d in regon_digits)
python
def regon(self) -> str: """Generate random valid 9-digit REGON. :return: Valid 9-digit REGON """ regon_coeffs = (8, 9, 2, 3, 4, 5, 6, 7) regon_digits = [self.random.randint(0, 9) for _ in range(8)] sum_v = sum([nc * nd for nc, nd in zip(regon_coeffs, regon_digits)]) checksum_digit = sum_v % 11 if checksum_digit > 9: checksum_digit = 0 regon_digits.append(checksum_digit) return ''.join(str(d) for d in regon_digits)
[ "def", "regon", "(", "self", ")", "->", "str", ":", "regon_coeffs", "=", "(", "8", ",", "9", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ")", "regon_digits", "=", "[", "self", ".", "random", ".", "randint", "(", "0", ",", "9", ")", "for", "_", "in", "range", "(", "8", ")", "]", "sum_v", "=", "sum", "(", "[", "nc", "*", "nd", "for", "nc", ",", "nd", "in", "zip", "(", "regon_coeffs", ",", "regon_digits", ")", "]", ")", "checksum_digit", "=", "sum_v", "%", "11", "if", "checksum_digit", ">", "9", ":", "checksum_digit", "=", "0", "regon_digits", ".", "append", "(", "checksum_digit", ")", "return", "''", ".", "join", "(", "str", "(", "d", ")", "for", "d", "in", "regon_digits", ")" ]
Generate random valid 9-digit REGON. :return: Valid 9-digit REGON
[ "Generate", "random", "valid", "9", "-", "digit", "REGON", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/builtins/pl.py#L88-L101
228,022
lk-geimfari/mimesis
mimesis/builtins/en.py
USASpecProvider.tracking_number
def tracking_number(self, service: str = 'usps') -> str: """Generate random tracking number. Supported services: USPS, FedEx and UPS. :param str service: Post service. :return: Tracking number. """ service = service.lower() if service not in ('usps', 'fedex', 'ups'): raise ValueError('Unsupported post service') services = { 'usps': ( '#### #### #### #### ####', '@@ ### ### ### US', ), 'fedex': ( '#### #### ####', '#### #### #### ###', ), 'ups': ( '1Z@####@##########', ), } mask = self.random.choice(services[service]) # type: ignore return self.random.custom_code(mask=mask)
python
def tracking_number(self, service: str = 'usps') -> str: """Generate random tracking number. Supported services: USPS, FedEx and UPS. :param str service: Post service. :return: Tracking number. """ service = service.lower() if service not in ('usps', 'fedex', 'ups'): raise ValueError('Unsupported post service') services = { 'usps': ( '#### #### #### #### ####', '@@ ### ### ### US', ), 'fedex': ( '#### #### ####', '#### #### #### ###', ), 'ups': ( '1Z@####@##########', ), } mask = self.random.choice(services[service]) # type: ignore return self.random.custom_code(mask=mask)
[ "def", "tracking_number", "(", "self", ",", "service", ":", "str", "=", "'usps'", ")", "->", "str", ":", "service", "=", "service", ".", "lower", "(", ")", "if", "service", "not", "in", "(", "'usps'", ",", "'fedex'", ",", "'ups'", ")", ":", "raise", "ValueError", "(", "'Unsupported post service'", ")", "services", "=", "{", "'usps'", ":", "(", "'#### #### #### #### ####'", ",", "'@@ ### ### ### US'", ",", ")", ",", "'fedex'", ":", "(", "'#### #### ####'", ",", "'#### #### #### ###'", ",", ")", ",", "'ups'", ":", "(", "'1Z@####@##########'", ",", ")", ",", "}", "mask", "=", "self", ".", "random", ".", "choice", "(", "services", "[", "service", "]", ")", "# type: ignore", "return", "self", ".", "random", ".", "custom_code", "(", "mask", "=", "mask", ")" ]
Generate random tracking number. Supported services: USPS, FedEx and UPS. :param str service: Post service. :return: Tracking number.
[ "Generate", "random", "tracking", "number", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/builtins/en.py#L25-L52
228,023
lk-geimfari/mimesis
mimesis/builtins/en.py
USASpecProvider.ssn
def ssn(self) -> str: """Generate a random, but valid SSN. :returns: SSN. :Example: 569-66-5801 """ area = self.random.randint(1, 899) if area == 666: area = 665 return '{:03}-{:02}-{:04}'.format( area, self.random.randint(1, 99), self.random.randint(1, 9999), )
python
def ssn(self) -> str: """Generate a random, but valid SSN. :returns: SSN. :Example: 569-66-5801 """ area = self.random.randint(1, 899) if area == 666: area = 665 return '{:03}-{:02}-{:04}'.format( area, self.random.randint(1, 99), self.random.randint(1, 9999), )
[ "def", "ssn", "(", "self", ")", "->", "str", ":", "area", "=", "self", ".", "random", ".", "randint", "(", "1", ",", "899", ")", "if", "area", "==", "666", ":", "area", "=", "665", "return", "'{:03}-{:02}-{:04}'", ".", "format", "(", "area", ",", "self", ".", "random", ".", "randint", "(", "1", ",", "99", ")", ",", "self", ".", "random", ".", "randint", "(", "1", ",", "9999", ")", ",", ")" ]
Generate a random, but valid SSN. :returns: SSN. :Example: 569-66-5801
[ "Generate", "a", "random", "but", "valid", "SSN", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/builtins/en.py#L54-L70
228,024
lk-geimfari/mimesis
mimesis/builtins/en.py
USASpecProvider.personality
def personality(self, category: str = 'mbti') -> Union[str, int]: """Generate a type of personality. :param category: Category. :return: Personality type. :rtype: str or int :Example: ISFJ. """ mbtis = ('ISFJ', 'ISTJ', 'INFJ', 'INTJ', 'ISTP', 'ISFP', 'INFP', 'INTP', 'ESTP', 'ESFP', 'ENFP', 'ENTP', 'ESTJ', 'ESFJ', 'ENFJ', 'ENTJ') if category.lower() == 'rheti': return self.random.randint(1, 10) return self.random.choice(mbtis)
python
def personality(self, category: str = 'mbti') -> Union[str, int]: """Generate a type of personality. :param category: Category. :return: Personality type. :rtype: str or int :Example: ISFJ. """ mbtis = ('ISFJ', 'ISTJ', 'INFJ', 'INTJ', 'ISTP', 'ISFP', 'INFP', 'INTP', 'ESTP', 'ESFP', 'ENFP', 'ENTP', 'ESTJ', 'ESFJ', 'ENFJ', 'ENTJ') if category.lower() == 'rheti': return self.random.randint(1, 10) return self.random.choice(mbtis)
[ "def", "personality", "(", "self", ",", "category", ":", "str", "=", "'mbti'", ")", "->", "Union", "[", "str", ",", "int", "]", ":", "mbtis", "=", "(", "'ISFJ'", ",", "'ISTJ'", ",", "'INFJ'", ",", "'INTJ'", ",", "'ISTP'", ",", "'ISFP'", ",", "'INFP'", ",", "'INTP'", ",", "'ESTP'", ",", "'ESFP'", ",", "'ENFP'", ",", "'ENTP'", ",", "'ESTJ'", ",", "'ESFJ'", ",", "'ENFJ'", ",", "'ENTJ'", ")", "if", "category", ".", "lower", "(", ")", "==", "'rheti'", ":", "return", "self", ".", "random", ".", "randint", "(", "1", ",", "10", ")", "return", "self", ".", "random", ".", "choice", "(", "mbtis", ")" ]
Generate a type of personality. :param category: Category. :return: Personality type. :rtype: str or int :Example: ISFJ.
[ "Generate", "a", "type", "of", "personality", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/builtins/en.py#L72-L90
228,025
lk-geimfari/mimesis
mimesis/providers/units.py
UnitSystem.unit
def unit(self, name: Optional[UnitName] = None, symbol=False): """Get unit name. :param name: Enum object UnitName. :param symbol: Return only symbol :return: Unit. """ result = self._validate_enum(item=name, enum=UnitName) if symbol: return result[1] return result[0]
python
def unit(self, name: Optional[UnitName] = None, symbol=False): """Get unit name. :param name: Enum object UnitName. :param symbol: Return only symbol :return: Unit. """ result = self._validate_enum(item=name, enum=UnitName) if symbol: return result[1] return result[0]
[ "def", "unit", "(", "self", ",", "name", ":", "Optional", "[", "UnitName", "]", "=", "None", ",", "symbol", "=", "False", ")", ":", "result", "=", "self", ".", "_validate_enum", "(", "item", "=", "name", ",", "enum", "=", "UnitName", ")", "if", "symbol", ":", "return", "result", "[", "1", "]", "return", "result", "[", "0", "]" ]
Get unit name. :param name: Enum object UnitName. :param symbol: Return only symbol :return: Unit.
[ "Get", "unit", "name", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/units.py#L22-L33
228,026
lk-geimfari/mimesis
mimesis/providers/units.py
UnitSystem.prefix
def prefix(self, sign: Optional[PrefixSign] = None, symbol: bool = False) -> str: """Get a random prefix for the International System of Units. :param sign: Sing of number. :param symbol: Return symbol of prefix. :return: Prefix for SI. :raises NonEnumerableError: if sign is not supported. :Example: mega """ prefixes = SI_PREFIXES_SYM if \ symbol else SI_PREFIXES key = self._validate_enum(item=sign, enum=PrefixSign) return self.random.choice(prefixes[key])
python
def prefix(self, sign: Optional[PrefixSign] = None, symbol: bool = False) -> str: """Get a random prefix for the International System of Units. :param sign: Sing of number. :param symbol: Return symbol of prefix. :return: Prefix for SI. :raises NonEnumerableError: if sign is not supported. :Example: mega """ prefixes = SI_PREFIXES_SYM if \ symbol else SI_PREFIXES key = self._validate_enum(item=sign, enum=PrefixSign) return self.random.choice(prefixes[key])
[ "def", "prefix", "(", "self", ",", "sign", ":", "Optional", "[", "PrefixSign", "]", "=", "None", ",", "symbol", ":", "bool", "=", "False", ")", "->", "str", ":", "prefixes", "=", "SI_PREFIXES_SYM", "if", "symbol", "else", "SI_PREFIXES", "key", "=", "self", ".", "_validate_enum", "(", "item", "=", "sign", ",", "enum", "=", "PrefixSign", ")", "return", "self", ".", "random", ".", "choice", "(", "prefixes", "[", "key", "]", ")" ]
Get a random prefix for the International System of Units. :param sign: Sing of number. :param symbol: Return symbol of prefix. :return: Prefix for SI. :raises NonEnumerableError: if sign is not supported. :Example: mega
[ "Get", "a", "random", "prefix", "for", "the", "International", "System", "of", "Units", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/units.py#L35-L51
228,027
lk-geimfari/mimesis
mimesis/builtins/nl.py
NetherlandsSpecProvider.bsn
def bsn(self) -> str: """Generate a random, but valid ``Burgerservicenummer``. :returns: Random BSN. :Example: 255159705 """ def _is_valid_bsn(number: str) -> bool: total = 0 multiplier = 9 for char in number: multiplier = -multiplier if multiplier == 1 else multiplier total += int(char) * multiplier multiplier -= 1 result = total % 11 == 0 return result a, b = (100000000, 999999999) sample = str(self.random.randint(a, b)) while not _is_valid_bsn(sample): sample = str(self.random.randint(a, b)) return sample
python
def bsn(self) -> str: """Generate a random, but valid ``Burgerservicenummer``. :returns: Random BSN. :Example: 255159705 """ def _is_valid_bsn(number: str) -> bool: total = 0 multiplier = 9 for char in number: multiplier = -multiplier if multiplier == 1 else multiplier total += int(char) * multiplier multiplier -= 1 result = total % 11 == 0 return result a, b = (100000000, 999999999) sample = str(self.random.randint(a, b)) while not _is_valid_bsn(sample): sample = str(self.random.randint(a, b)) return sample
[ "def", "bsn", "(", "self", ")", "->", "str", ":", "def", "_is_valid_bsn", "(", "number", ":", "str", ")", "->", "bool", ":", "total", "=", "0", "multiplier", "=", "9", "for", "char", "in", "number", ":", "multiplier", "=", "-", "multiplier", "if", "multiplier", "==", "1", "else", "multiplier", "total", "+=", "int", "(", "char", ")", "*", "multiplier", "multiplier", "-=", "1", "result", "=", "total", "%", "11", "==", "0", "return", "result", "a", ",", "b", "=", "(", "100000000", ",", "999999999", ")", "sample", "=", "str", "(", "self", ".", "random", ".", "randint", "(", "a", ",", "b", ")", ")", "while", "not", "_is_valid_bsn", "(", "sample", ")", ":", "sample", "=", "str", "(", "self", ".", "random", ".", "randint", "(", "a", ",", "b", ")", ")", "return", "sample" ]
Generate a random, but valid ``Burgerservicenummer``. :returns: Random BSN. :Example: 255159705
[ "Generate", "a", "random", "but", "valid", "Burgerservicenummer", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/builtins/nl.py#L23-L49
228,028
lk-geimfari/mimesis
mimesis/schema.py
Schema.create
def create(self, iterations: int = 1) -> List[JSON]: """Return filled schema. Create a list of a filled schemas with elements in an amount of **iterations**. :param iterations: Amount of iterations. :return: List of willed schemas. """ return [self.schema() for _ in range(iterations)]
python
def create(self, iterations: int = 1) -> List[JSON]: """Return filled schema. Create a list of a filled schemas with elements in an amount of **iterations**. :param iterations: Amount of iterations. :return: List of willed schemas. """ return [self.schema() for _ in range(iterations)]
[ "def", "create", "(", "self", ",", "iterations", ":", "int", "=", "1", ")", "->", "List", "[", "JSON", "]", ":", "return", "[", "self", ".", "schema", "(", ")", "for", "_", "in", "range", "(", "iterations", ")", "]" ]
Return filled schema. Create a list of a filled schemas with elements in an amount of **iterations**. :param iterations: Amount of iterations. :return: List of willed schemas.
[ "Return", "filled", "schema", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/schema.py#L133-L142
228,029
lk-geimfari/mimesis
mimesis/providers/base.py
BaseProvider.reseed
def reseed(self, seed: Seed = None) -> None: """Reseed the internal random generator. In case we use the default seed, we need to create a per instance random generator, in this case two providers with the same seed will always return the same values. :param seed: Seed for random. When set to `None` the current system time is used. """ if self.random is random: self.random = Random() self.seed = seed self.random.seed(self.seed)
python
def reseed(self, seed: Seed = None) -> None: """Reseed the internal random generator. In case we use the default seed, we need to create a per instance random generator, in this case two providers with the same seed will always return the same values. :param seed: Seed for random. When set to `None` the current system time is used. """ if self.random is random: self.random = Random() self.seed = seed self.random.seed(self.seed)
[ "def", "reseed", "(", "self", ",", "seed", ":", "Seed", "=", "None", ")", "->", "None", ":", "if", "self", ".", "random", "is", "random", ":", "self", ".", "random", "=", "Random", "(", ")", "self", ".", "seed", "=", "seed", "self", ".", "random", ".", "seed", "(", "self", ".", "seed", ")" ]
Reseed the internal random generator. In case we use the default seed, we need to create a per instance random generator, in this case two providers with the same seed will always return the same values. :param seed: Seed for random. When set to `None` the current system time is used.
[ "Reseed", "the", "internal", "random", "generator", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/base.py#L35-L49
228,030
lk-geimfari/mimesis
mimesis/providers/base.py
BaseProvider._validate_enum
def _validate_enum(self, item: Any, enum: Any) -> Any: """Validate enum parameter of method in subclasses of BaseProvider. :param item: Item of enum object. :param enum: Enum object. :return: Value of item. :raises NonEnumerableError: if ``item`` not in ``enum``. """ if item is None: result = get_random_item(enum, self.random) elif item and isinstance(item, enum): result = item else: raise NonEnumerableError(enum) return result.value
python
def _validate_enum(self, item: Any, enum: Any) -> Any: """Validate enum parameter of method in subclasses of BaseProvider. :param item: Item of enum object. :param enum: Enum object. :return: Value of item. :raises NonEnumerableError: if ``item`` not in ``enum``. """ if item is None: result = get_random_item(enum, self.random) elif item and isinstance(item, enum): result = item else: raise NonEnumerableError(enum) return result.value
[ "def", "_validate_enum", "(", "self", ",", "item", ":", "Any", ",", "enum", ":", "Any", ")", "->", "Any", ":", "if", "item", "is", "None", ":", "result", "=", "get_random_item", "(", "enum", ",", "self", ".", "random", ")", "elif", "item", "and", "isinstance", "(", "item", ",", "enum", ")", ":", "result", "=", "item", "else", ":", "raise", "NonEnumerableError", "(", "enum", ")", "return", "result", ".", "value" ]
Validate enum parameter of method in subclasses of BaseProvider. :param item: Item of enum object. :param enum: Enum object. :return: Value of item. :raises NonEnumerableError: if ``item`` not in ``enum``.
[ "Validate", "enum", "parameter", "of", "method", "in", "subclasses", "of", "BaseProvider", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/base.py#L51-L66
228,031
lk-geimfari/mimesis
mimesis/providers/base.py
BaseDataProvider._setup_locale
def _setup_locale(self, locale: str = locales.DEFAULT_LOCALE) -> None: """Set up locale after pre-check. :param str locale: Locale :raises UnsupportedLocale: When locale is not supported. :return: Nothing. """ if not locale: locale = locales.DEFAULT_LOCALE locale = locale.lower() if locale not in locales.SUPPORTED_LOCALES: raise UnsupportedLocale(locale) self.locale = locale
python
def _setup_locale(self, locale: str = locales.DEFAULT_LOCALE) -> None: """Set up locale after pre-check. :param str locale: Locale :raises UnsupportedLocale: When locale is not supported. :return: Nothing. """ if not locale: locale = locales.DEFAULT_LOCALE locale = locale.lower() if locale not in locales.SUPPORTED_LOCALES: raise UnsupportedLocale(locale) self.locale = locale
[ "def", "_setup_locale", "(", "self", ",", "locale", ":", "str", "=", "locales", ".", "DEFAULT_LOCALE", ")", "->", "None", ":", "if", "not", "locale", ":", "locale", "=", "locales", ".", "DEFAULT_LOCALE", "locale", "=", "locale", ".", "lower", "(", ")", "if", "locale", "not", "in", "locales", ".", "SUPPORTED_LOCALES", ":", "raise", "UnsupportedLocale", "(", "locale", ")", "self", ".", "locale", "=", "locale" ]
Set up locale after pre-check. :param str locale: Locale :raises UnsupportedLocale: When locale is not supported. :return: Nothing.
[ "Set", "up", "locale", "after", "pre", "-", "check", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/base.py#L89-L103
228,032
lk-geimfari/mimesis
mimesis/providers/base.py
BaseDataProvider._update_dict
def _update_dict(self, initial: JSON, other: Mapping) -> JSON: """Recursively update a dictionary. :param initial: Dict to update. :param other: Dict to update from. :return: Updated dict. """ for key, value in other.items(): if isinstance(value, collections.Mapping): r = self._update_dict(initial.get(key, {}), value) initial[key] = r else: initial[key] = other[key] return initial
python
def _update_dict(self, initial: JSON, other: Mapping) -> JSON: """Recursively update a dictionary. :param initial: Dict to update. :param other: Dict to update from. :return: Updated dict. """ for key, value in other.items(): if isinstance(value, collections.Mapping): r = self._update_dict(initial.get(key, {}), value) initial[key] = r else: initial[key] = other[key] return initial
[ "def", "_update_dict", "(", "self", ",", "initial", ":", "JSON", ",", "other", ":", "Mapping", ")", "->", "JSON", ":", "for", "key", ",", "value", "in", "other", ".", "items", "(", ")", ":", "if", "isinstance", "(", "value", ",", "collections", ".", "Mapping", ")", ":", "r", "=", "self", ".", "_update_dict", "(", "initial", ".", "get", "(", "key", ",", "{", "}", ")", ",", "value", ")", "initial", "[", "key", "]", "=", "r", "else", ":", "initial", "[", "key", "]", "=", "other", "[", "key", "]", "return", "initial" ]
Recursively update a dictionary. :param initial: Dict to update. :param other: Dict to update from. :return: Updated dict.
[ "Recursively", "update", "a", "dictionary", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/base.py#L105-L118
228,033
lk-geimfari/mimesis
mimesis/providers/base.py
BaseDataProvider.pull
def pull(self, datafile: str = ''): """Pull the content from the JSON and memorize one. Opens JSON file ``file`` in the folder ``data/locale`` and get content from the file and memorize ones using lru_cache. :param datafile: The name of file. :return: The content of the file. :raises UnsupportedLocale: if locale is not supported. """ locale = self.locale data_dir = self._data_dir if not datafile: datafile = self._datafile def get_data(locale_name: str) -> JSON: """Pull JSON data from file. :param locale_name: Locale name. :return: Content of JSON file as dict. """ file_path = Path(data_dir).joinpath(locale_name, datafile) with open(file_path, 'r', encoding='utf8') as f: return json.load(f) separator = locales.LOCALE_SEPARATOR master_locale = locale.split(separator).pop(0) data = get_data(master_locale) if separator in locale: data = self._update_dict(data, get_data(locale)) self._data = data
python
def pull(self, datafile: str = ''): """Pull the content from the JSON and memorize one. Opens JSON file ``file`` in the folder ``data/locale`` and get content from the file and memorize ones using lru_cache. :param datafile: The name of file. :return: The content of the file. :raises UnsupportedLocale: if locale is not supported. """ locale = self.locale data_dir = self._data_dir if not datafile: datafile = self._datafile def get_data(locale_name: str) -> JSON: """Pull JSON data from file. :param locale_name: Locale name. :return: Content of JSON file as dict. """ file_path = Path(data_dir).joinpath(locale_name, datafile) with open(file_path, 'r', encoding='utf8') as f: return json.load(f) separator = locales.LOCALE_SEPARATOR master_locale = locale.split(separator).pop(0) data = get_data(master_locale) if separator in locale: data = self._update_dict(data, get_data(locale)) self._data = data
[ "def", "pull", "(", "self", ",", "datafile", ":", "str", "=", "''", ")", ":", "locale", "=", "self", ".", "locale", "data_dir", "=", "self", ".", "_data_dir", "if", "not", "datafile", ":", "datafile", "=", "self", ".", "_datafile", "def", "get_data", "(", "locale_name", ":", "str", ")", "->", "JSON", ":", "\"\"\"Pull JSON data from file.\n\n :param locale_name: Locale name.\n :return: Content of JSON file as dict.\n \"\"\"", "file_path", "=", "Path", "(", "data_dir", ")", ".", "joinpath", "(", "locale_name", ",", "datafile", ")", "with", "open", "(", "file_path", ",", "'r'", ",", "encoding", "=", "'utf8'", ")", "as", "f", ":", "return", "json", ".", "load", "(", "f", ")", "separator", "=", "locales", ".", "LOCALE_SEPARATOR", "master_locale", "=", "locale", ".", "split", "(", "separator", ")", ".", "pop", "(", "0", ")", "data", "=", "get_data", "(", "master_locale", ")", "if", "separator", "in", "locale", ":", "data", "=", "self", ".", "_update_dict", "(", "data", ",", "get_data", "(", "locale", ")", ")", "self", ".", "_data", "=", "data" ]
Pull the content from the JSON and memorize one. Opens JSON file ``file`` in the folder ``data/locale`` and get content from the file and memorize ones using lru_cache. :param datafile: The name of file. :return: The content of the file. :raises UnsupportedLocale: if locale is not supported.
[ "Pull", "the", "content", "from", "the", "JSON", "and", "memorize", "one", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/base.py#L121-L155
228,034
lk-geimfari/mimesis
mimesis/providers/base.py
BaseDataProvider._override_locale
def _override_locale(self, locale: str = locales.DEFAULT_LOCALE) -> None: """Overrides current locale with passed and pull data for new locale. :param locale: Locale :return: Nothing. """ self.locale = locale self.pull.cache_clear() self.pull()
python
def _override_locale(self, locale: str = locales.DEFAULT_LOCALE) -> None: """Overrides current locale with passed and pull data for new locale. :param locale: Locale :return: Nothing. """ self.locale = locale self.pull.cache_clear() self.pull()
[ "def", "_override_locale", "(", "self", ",", "locale", ":", "str", "=", "locales", ".", "DEFAULT_LOCALE", ")", "->", "None", ":", "self", ".", "locale", "=", "locale", "self", ".", "pull", ".", "cache_clear", "(", ")", "self", ".", "pull", "(", ")" ]
Overrides current locale with passed and pull data for new locale. :param locale: Locale :return: Nothing.
[ "Overrides", "current", "locale", "with", "passed", "and", "pull", "data", "for", "new", "locale", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/base.py#L167-L175
228,035
lk-geimfari/mimesis
mimesis/providers/address.py
Address.street_number
def street_number(self, maximum: int = 1400) -> str: """Generate a random street number. :param maximum: Maximum value. :return: Street number. """ return str(self.random.randint(1, maximum))
python
def street_number(self, maximum: int = 1400) -> str: """Generate a random street number. :param maximum: Maximum value. :return: Street number. """ return str(self.random.randint(1, maximum))
[ "def", "street_number", "(", "self", ",", "maximum", ":", "int", "=", "1400", ")", "->", "str", ":", "return", "str", "(", "self", ".", "random", ".", "randint", "(", "1", ",", "maximum", ")", ")" ]
Generate a random street number. :param maximum: Maximum value. :return: Street number.
[ "Generate", "a", "random", "street", "number", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/address.py#L66-L72
228,036
lk-geimfari/mimesis
mimesis/providers/address.py
Address.address
def address(self) -> str: """Generate a random full address. :return: Full address. """ fmt = self._data['address_fmt'] st_num = self.street_number() st_name = self.street_name() if self.locale in SHORTENED_ADDRESS_FMT: return fmt.format( st_num=st_num, st_name=st_name, ) if self.locale == 'ja': return fmt.format( self.random.choice(self._data['city']), # Generate list of random integers # in amount of 3, from 1 to 100. *self.random.randints(amount=3, a=1, b=100), ) return fmt.format( st_num=st_num, st_name=st_name, st_sfx=self.street_suffix(), )
python
def address(self) -> str: """Generate a random full address. :return: Full address. """ fmt = self._data['address_fmt'] st_num = self.street_number() st_name = self.street_name() if self.locale in SHORTENED_ADDRESS_FMT: return fmt.format( st_num=st_num, st_name=st_name, ) if self.locale == 'ja': return fmt.format( self.random.choice(self._data['city']), # Generate list of random integers # in amount of 3, from 1 to 100. *self.random.randints(amount=3, a=1, b=100), ) return fmt.format( st_num=st_num, st_name=st_name, st_sfx=self.street_suffix(), )
[ "def", "address", "(", "self", ")", "->", "str", ":", "fmt", "=", "self", ".", "_data", "[", "'address_fmt'", "]", "st_num", "=", "self", ".", "street_number", "(", ")", "st_name", "=", "self", ".", "street_name", "(", ")", "if", "self", ".", "locale", "in", "SHORTENED_ADDRESS_FMT", ":", "return", "fmt", ".", "format", "(", "st_num", "=", "st_num", ",", "st_name", "=", "st_name", ",", ")", "if", "self", ".", "locale", "==", "'ja'", ":", "return", "fmt", ".", "format", "(", "self", ".", "random", ".", "choice", "(", "self", ".", "_data", "[", "'city'", "]", ")", ",", "# Generate list of random integers", "# in amount of 3, from 1 to 100.", "*", "self", ".", "random", ".", "randints", "(", "amount", "=", "3", ",", "a", "=", "1", ",", "b", "=", "100", ")", ",", ")", "return", "fmt", ".", "format", "(", "st_num", "=", "st_num", ",", "st_name", "=", "st_name", ",", "st_sfx", "=", "self", ".", "street_suffix", "(", ")", ",", ")" ]
Generate a random full address. :return: Full address.
[ "Generate", "a", "random", "full", "address", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/address.py#L90-L119
228,037
lk-geimfari/mimesis
mimesis/providers/address.py
Address.state
def state(self, abbr: bool = False) -> str: """Get a random administrative district of country. :param abbr: Return ISO 3166-2 code. :return: Administrative district. """ return self.random.choice( self._data['state']['abbr' if abbr else 'name'])
python
def state(self, abbr: bool = False) -> str: """Get a random administrative district of country. :param abbr: Return ISO 3166-2 code. :return: Administrative district. """ return self.random.choice( self._data['state']['abbr' if abbr else 'name'])
[ "def", "state", "(", "self", ",", "abbr", ":", "bool", "=", "False", ")", "->", "str", ":", "return", "self", ".", "random", ".", "choice", "(", "self", ".", "_data", "[", "'state'", "]", "[", "'abbr'", "if", "abbr", "else", "'name'", "]", ")" ]
Get a random administrative district of country. :param abbr: Return ISO 3166-2 code. :return: Administrative district.
[ "Get", "a", "random", "administrative", "district", "of", "country", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/address.py#L121-L128
228,038
lk-geimfari/mimesis
mimesis/providers/address.py
Address.country_code
def country_code(self, fmt: Optional[CountryCode] = CountryCode.A2) -> str: """Get a random code of country. Default format is :attr:`~enums.CountryCode.A2` (ISO 3166-1-alpha2), you can change it by passing parameter ``fmt`` with enum object :class:`~enums.CountryCode`. :param fmt: Enum object CountryCode. :return: Country code in selected format. :raises KeyError: if fmt is not supported. """ key = self._validate_enum(fmt, CountryCode) return self.random.choice(COUNTRY_CODES[key])
python
def country_code(self, fmt: Optional[CountryCode] = CountryCode.A2) -> str: """Get a random code of country. Default format is :attr:`~enums.CountryCode.A2` (ISO 3166-1-alpha2), you can change it by passing parameter ``fmt`` with enum object :class:`~enums.CountryCode`. :param fmt: Enum object CountryCode. :return: Country code in selected format. :raises KeyError: if fmt is not supported. """ key = self._validate_enum(fmt, CountryCode) return self.random.choice(COUNTRY_CODES[key])
[ "def", "country_code", "(", "self", ",", "fmt", ":", "Optional", "[", "CountryCode", "]", "=", "CountryCode", ".", "A2", ")", "->", "str", ":", "key", "=", "self", ".", "_validate_enum", "(", "fmt", ",", "CountryCode", ")", "return", "self", ".", "random", ".", "choice", "(", "COUNTRY_CODES", "[", "key", "]", ")" ]
Get a random code of country. Default format is :attr:`~enums.CountryCode.A2` (ISO 3166-1-alpha2), you can change it by passing parameter ``fmt`` with enum object :class:`~enums.CountryCode`. :param fmt: Enum object CountryCode. :return: Country code in selected format. :raises KeyError: if fmt is not supported.
[ "Get", "a", "random", "code", "of", "country", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/address.py#L175-L187
228,039
lk-geimfari/mimesis
mimesis/providers/address.py
Address._get_fs
def _get_fs(self, key: str, dms: bool = False) -> Union[str, float]: """Get float number. :param key: Key (`lt` or `lg`). :param dms: DMS format. :return: Float number """ # Default range is a range of longitude. rng = (-90, 90) if key == 'lt' else (-180, 180) result = self.random.uniform(*rng, precision=6) if dms: return self._dd_to_dms(result, key) return result
python
def _get_fs(self, key: str, dms: bool = False) -> Union[str, float]: """Get float number. :param key: Key (`lt` or `lg`). :param dms: DMS format. :return: Float number """ # Default range is a range of longitude. rng = (-90, 90) if key == 'lt' else (-180, 180) result = self.random.uniform(*rng, precision=6) if dms: return self._dd_to_dms(result, key) return result
[ "def", "_get_fs", "(", "self", ",", "key", ":", "str", ",", "dms", ":", "bool", "=", "False", ")", "->", "Union", "[", "str", ",", "float", "]", ":", "# Default range is a range of longitude.", "rng", "=", "(", "-", "90", ",", "90", ")", "if", "key", "==", "'lt'", "else", "(", "-", "180", ",", "180", ")", "result", "=", "self", ".", "random", ".", "uniform", "(", "*", "rng", ",", "precision", "=", "6", ")", "if", "dms", ":", "return", "self", ".", "_dd_to_dms", "(", "result", ",", "key", ")", "return", "result" ]
Get float number. :param key: Key (`lt` or `lg`). :param dms: DMS format. :return: Float number
[ "Get", "float", "number", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/address.py#L205-L219
228,040
lk-geimfari/mimesis
mimesis/providers/address.py
Address.latitude
def latitude(self, dms: bool = False) -> Union[str, float]: """Generate a random value of latitude. :param dms: DMS format. :return: Value of longitude. """ return self._get_fs('lt', dms)
python
def latitude(self, dms: bool = False) -> Union[str, float]: """Generate a random value of latitude. :param dms: DMS format. :return: Value of longitude. """ return self._get_fs('lt', dms)
[ "def", "latitude", "(", "self", ",", "dms", ":", "bool", "=", "False", ")", "->", "Union", "[", "str", ",", "float", "]", ":", "return", "self", ".", "_get_fs", "(", "'lt'", ",", "dms", ")" ]
Generate a random value of latitude. :param dms: DMS format. :return: Value of longitude.
[ "Generate", "a", "random", "value", "of", "latitude", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/address.py#L221-L227
228,041
lk-geimfari/mimesis
mimesis/providers/address.py
Address.coordinates
def coordinates(self, dms: bool = False) -> dict: """Generate random geo coordinates. :param dms: DMS format. :return: Dict with coordinates. """ return { 'longitude': self._get_fs('lg', dms), 'latitude': self._get_fs('lt', dms), }
python
def coordinates(self, dms: bool = False) -> dict: """Generate random geo coordinates. :param dms: DMS format. :return: Dict with coordinates. """ return { 'longitude': self._get_fs('lg', dms), 'latitude': self._get_fs('lt', dms), }
[ "def", "coordinates", "(", "self", ",", "dms", ":", "bool", "=", "False", ")", "->", "dict", ":", "return", "{", "'longitude'", ":", "self", ".", "_get_fs", "(", "'lg'", ",", "dms", ")", ",", "'latitude'", ":", "self", ".", "_get_fs", "(", "'lt'", ",", "dms", ")", ",", "}" ]
Generate random geo coordinates. :param dms: DMS format. :return: Dict with coordinates.
[ "Generate", "random", "geo", "coordinates", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/address.py#L237-L246
228,042
lk-geimfari/mimesis
mimesis/providers/address.py
Address.continent
def continent(self, code: bool = False) -> str: """Get a random continent name or continent code. :param code: Return code of continent. :return: Continent name. """ codes = CONTINENT_CODES if \ code else self._data['continent'] return self.random.choice(codes)
python
def continent(self, code: bool = False) -> str: """Get a random continent name or continent code. :param code: Return code of continent. :return: Continent name. """ codes = CONTINENT_CODES if \ code else self._data['continent'] return self.random.choice(codes)
[ "def", "continent", "(", "self", ",", "code", ":", "bool", "=", "False", ")", "->", "str", ":", "codes", "=", "CONTINENT_CODES", "if", "code", "else", "self", ".", "_data", "[", "'continent'", "]", "return", "self", ".", "random", ".", "choice", "(", "codes", ")" ]
Get a random continent name or continent code. :param code: Return code of continent. :return: Continent name.
[ "Get", "a", "random", "continent", "name", "or", "continent", "code", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/address.py#L248-L257
228,043
lk-geimfari/mimesis
mimesis/providers/business.py
Business.company_type
def company_type(self, abbr: bool = False) -> str: """Get a random type of business entity. :param abbr: Abbreviated company type. :return: Types of business entity. """ key = 'abbr' if abbr else 'title' return self.random.choice( self._data['company']['type'][key], )
python
def company_type(self, abbr: bool = False) -> str: """Get a random type of business entity. :param abbr: Abbreviated company type. :return: Types of business entity. """ key = 'abbr' if abbr else 'title' return self.random.choice( self._data['company']['type'][key], )
[ "def", "company_type", "(", "self", ",", "abbr", ":", "bool", "=", "False", ")", "->", "str", ":", "key", "=", "'abbr'", "if", "abbr", "else", "'title'", "return", "self", ".", "random", ".", "choice", "(", "self", ".", "_data", "[", "'company'", "]", "[", "'type'", "]", "[", "key", "]", ",", ")" ]
Get a random type of business entity. :param abbr: Abbreviated company type. :return: Types of business entity.
[ "Get", "a", "random", "type", "of", "business", "entity", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/business.py#L40-L49
228,044
lk-geimfari/mimesis
mimesis/providers/business.py
Business.currency_iso_code
def currency_iso_code(self, allow_random: bool = False) -> str: """Get code of the currency for current locale. :param allow_random: Get a random ISO code. :return: Currency code. """ if allow_random: return self.random.choice(CURRENCY_ISO_CODES) else: return self._data['currency-code']
python
def currency_iso_code(self, allow_random: bool = False) -> str: """Get code of the currency for current locale. :param allow_random: Get a random ISO code. :return: Currency code. """ if allow_random: return self.random.choice(CURRENCY_ISO_CODES) else: return self._data['currency-code']
[ "def", "currency_iso_code", "(", "self", ",", "allow_random", ":", "bool", "=", "False", ")", "->", "str", ":", "if", "allow_random", ":", "return", "self", ".", "random", ".", "choice", "(", "CURRENCY_ISO_CODES", ")", "else", ":", "return", "self", ".", "_data", "[", "'currency-code'", "]" ]
Get code of the currency for current locale. :param allow_random: Get a random ISO code. :return: Currency code.
[ "Get", "code", "of", "the", "currency", "for", "current", "locale", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/business.py#L61-L70
228,045
lk-geimfari/mimesis
mimesis/providers/business.py
Business.price
def price(self, minimum: float = 10.00, maximum: float = 1000.00) -> str: """Generate a random price. :param minimum: Max value of price. :param maximum: Min value of price. :return: Price. """ price = self.random.uniform(minimum, maximum, precision=2) return '{0} {1}'.format(price, self.currency_symbol())
python
def price(self, minimum: float = 10.00, maximum: float = 1000.00) -> str: """Generate a random price. :param minimum: Max value of price. :param maximum: Min value of price. :return: Price. """ price = self.random.uniform(minimum, maximum, precision=2) return '{0} {1}'.format(price, self.currency_symbol())
[ "def", "price", "(", "self", ",", "minimum", ":", "float", "=", "10.00", ",", "maximum", ":", "float", "=", "1000.00", ")", "->", "str", ":", "price", "=", "self", ".", "random", ".", "uniform", "(", "minimum", ",", "maximum", ",", "precision", "=", "2", ")", "return", "'{0} {1}'", ".", "format", "(", "price", ",", "self", ".", "currency_symbol", "(", ")", ")" ]
Generate a random price. :param minimum: Max value of price. :param maximum: Min value of price. :return: Price.
[ "Generate", "a", "random", "price", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/business.py#L93-L102
228,046
lk-geimfari/mimesis
mimesis/providers/business.py
Business.price_in_btc
def price_in_btc(self, minimum: float = 0, maximum: float = 2) -> str: """Generate random price in BTC. :param minimum: Minimum value of price. :param maximum: Maximum value of price. :return: Price in BTC. """ return '{} BTC'.format( self.random.uniform( minimum, maximum, precision=7, ), )
python
def price_in_btc(self, minimum: float = 0, maximum: float = 2) -> str: """Generate random price in BTC. :param minimum: Minimum value of price. :param maximum: Maximum value of price. :return: Price in BTC. """ return '{} BTC'.format( self.random.uniform( minimum, maximum, precision=7, ), )
[ "def", "price_in_btc", "(", "self", ",", "minimum", ":", "float", "=", "0", ",", "maximum", ":", "float", "=", "2", ")", "->", "str", ":", "return", "'{} BTC'", ".", "format", "(", "self", ".", "random", ".", "uniform", "(", "minimum", ",", "maximum", ",", "precision", "=", "7", ",", ")", ",", ")" ]
Generate random price in BTC. :param minimum: Minimum value of price. :param maximum: Maximum value of price. :return: Price in BTC.
[ "Generate", "random", "price", "in", "BTC", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/business.py#L104-L117
228,047
lk-geimfari/mimesis
mimesis/builtins/it.py
ItalySpecProvider.fiscal_code
def fiscal_code(self, gender: Optional[Gender] = None) -> str: """Return a random fiscal code. :param gender: Gender's enum object. :return: Fiscal code. Example: RSSMRA66R05D612U """ code = ''.join(self.random.choices(string.ascii_uppercase, k=6)) code += self.random.custom_code(mask='##') month_codes = self._data['fiscal_code']['month_codes'] code += self.random.choice(month_codes) birth_day = self.random.randint(101, 131) self._validate_enum(gender, Gender) if gender == Gender.FEMALE: birth_day += 40 code += str(birth_day)[1:] city_letters = self._data['fiscal_code']['city_letters'] code += self.random.choice(city_letters) code += self.random.custom_code(mask='###@') return code
python
def fiscal_code(self, gender: Optional[Gender] = None) -> str: """Return a random fiscal code. :param gender: Gender's enum object. :return: Fiscal code. Example: RSSMRA66R05D612U """ code = ''.join(self.random.choices(string.ascii_uppercase, k=6)) code += self.random.custom_code(mask='##') month_codes = self._data['fiscal_code']['month_codes'] code += self.random.choice(month_codes) birth_day = self.random.randint(101, 131) self._validate_enum(gender, Gender) if gender == Gender.FEMALE: birth_day += 40 code += str(birth_day)[1:] city_letters = self._data['fiscal_code']['city_letters'] code += self.random.choice(city_letters) code += self.random.custom_code(mask='###@') return code
[ "def", "fiscal_code", "(", "self", ",", "gender", ":", "Optional", "[", "Gender", "]", "=", "None", ")", "->", "str", ":", "code", "=", "''", ".", "join", "(", "self", ".", "random", ".", "choices", "(", "string", ".", "ascii_uppercase", ",", "k", "=", "6", ")", ")", "code", "+=", "self", ".", "random", ".", "custom_code", "(", "mask", "=", "'##'", ")", "month_codes", "=", "self", ".", "_data", "[", "'fiscal_code'", "]", "[", "'month_codes'", "]", "code", "+=", "self", ".", "random", ".", "choice", "(", "month_codes", ")", "birth_day", "=", "self", ".", "random", ".", "randint", "(", "101", ",", "131", ")", "self", ".", "_validate_enum", "(", "gender", ",", "Gender", ")", "if", "gender", "==", "Gender", ".", "FEMALE", ":", "birth_day", "+=", "40", "code", "+=", "str", "(", "birth_day", ")", "[", "1", ":", "]", "city_letters", "=", "self", ".", "_data", "[", "'fiscal_code'", "]", "[", "'city_letters'", "]", "code", "+=", "self", ".", "random", ".", "choice", "(", "city_letters", ")", "code", "+=", "self", ".", "random", ".", "custom_code", "(", "mask", "=", "'###@'", ")", "return", "code" ]
Return a random fiscal code. :param gender: Gender's enum object. :return: Fiscal code. Example: RSSMRA66R05D612U
[ "Return", "a", "random", "fiscal", "code", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/builtins/it.py#L28-L54
228,048
lk-geimfari/mimesis
mimesis/random.py
get_random_item
def get_random_item(enum: Any, rnd: Optional[Random] = None) -> Any: """Get random item of enum object. :param enum: Enum object. :param rnd: Custom random object. :return: Random item of enum. """ if rnd and isinstance(rnd, Random): return rnd.choice(list(enum)) return random_module.choice(list(enum))
python
def get_random_item(enum: Any, rnd: Optional[Random] = None) -> Any: """Get random item of enum object. :param enum: Enum object. :param rnd: Custom random object. :return: Random item of enum. """ if rnd and isinstance(rnd, Random): return rnd.choice(list(enum)) return random_module.choice(list(enum))
[ "def", "get_random_item", "(", "enum", ":", "Any", ",", "rnd", ":", "Optional", "[", "Random", "]", "=", "None", ")", "->", "Any", ":", "if", "rnd", "and", "isinstance", "(", "rnd", ",", "Random", ")", ":", "return", "rnd", ".", "choice", "(", "list", "(", "enum", ")", ")", "return", "random_module", ".", "choice", "(", "list", "(", "enum", ")", ")" ]
Get random item of enum object. :param enum: Enum object. :param rnd: Custom random object. :return: Random item of enum.
[ "Get", "random", "item", "of", "enum", "object", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/random.py#L103-L112
228,049
lk-geimfari/mimesis
mimesis/random.py
Random.randints
def randints(self, amount: int = 3, a: int = 1, b: int = 100) -> List[int]: """Generate list of random integers. :param amount: Amount of elements. :param a: Minimum value of range. :param b: Maximum value of range. :return: List of random integers. :raises ValueError: if amount less or equal to zero. """ if amount <= 0: raise ValueError('Amount out of range.') return [int(self.random() * (b - a)) + a for _ in range(amount)]
python
def randints(self, amount: int = 3, a: int = 1, b: int = 100) -> List[int]: """Generate list of random integers. :param amount: Amount of elements. :param a: Minimum value of range. :param b: Maximum value of range. :return: List of random integers. :raises ValueError: if amount less or equal to zero. """ if amount <= 0: raise ValueError('Amount out of range.') return [int(self.random() * (b - a)) + a for _ in range(amount)]
[ "def", "randints", "(", "self", ",", "amount", ":", "int", "=", "3", ",", "a", ":", "int", "=", "1", ",", "b", ":", "int", "=", "100", ")", "->", "List", "[", "int", "]", ":", "if", "amount", "<=", "0", ":", "raise", "ValueError", "(", "'Amount out of range.'", ")", "return", "[", "int", "(", "self", ".", "random", "(", ")", "*", "(", "b", "-", "a", ")", ")", "+", "a", "for", "_", "in", "range", "(", "amount", ")", "]" ]
Generate list of random integers. :param amount: Amount of elements. :param a: Minimum value of range. :param b: Maximum value of range. :return: List of random integers. :raises ValueError: if amount less or equal to zero.
[ "Generate", "list", "of", "random", "integers", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/random.py#L29-L43
228,050
lk-geimfari/mimesis
mimesis/random.py
Random.urandom
def urandom(*args: Any, **kwargs: Any) -> bytes: """Return a bytes object containing random bytes. :return: Bytes. """ return os.urandom(*args, **kwargs)
python
def urandom(*args: Any, **kwargs: Any) -> bytes: """Return a bytes object containing random bytes. :return: Bytes. """ return os.urandom(*args, **kwargs)
[ "def", "urandom", "(", "*", "args", ":", "Any", ",", "*", "*", "kwargs", ":", "Any", ")", "->", "bytes", ":", "return", "os", ".", "urandom", "(", "*", "args", ",", "*", "*", "kwargs", ")" ]
Return a bytes object containing random bytes. :return: Bytes.
[ "Return", "a", "bytes", "object", "containing", "random", "bytes", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/random.py#L46-L51
228,051
lk-geimfari/mimesis
mimesis/random.py
Random.schoice
def schoice(self, seq: str, end: int = 10) -> str: """Choice function which returns string created from sequence. :param seq: Sequence of letters or digits. :type seq: tuple or list :param end: Max value. :return: Single string. """ return ''.join(self.choice(list(seq)) for _ in range(end))
python
def schoice(self, seq: str, end: int = 10) -> str: """Choice function which returns string created from sequence. :param seq: Sequence of letters or digits. :type seq: tuple or list :param end: Max value. :return: Single string. """ return ''.join(self.choice(list(seq)) for _ in range(end))
[ "def", "schoice", "(", "self", ",", "seq", ":", "str", ",", "end", ":", "int", "=", "10", ")", "->", "str", ":", "return", "''", ".", "join", "(", "self", ".", "choice", "(", "list", "(", "seq", ")", ")", "for", "_", "in", "range", "(", "end", ")", ")" ]
Choice function which returns string created from sequence. :param seq: Sequence of letters or digits. :type seq: tuple or list :param end: Max value. :return: Single string.
[ "Choice", "function", "which", "returns", "string", "created", "from", "sequence", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/random.py#L53-L62
228,052
lk-geimfari/mimesis
mimesis/random.py
Random.custom_code
def custom_code(self, mask: str = '@###', char: str = '@', digit: str = '#') -> str: """Generate custom code using ascii uppercase and random integers. :param mask: Mask of code. :param char: Placeholder for characters. :param digit: Placeholder for digits. :return: Custom code. """ char_code = ord(char) digit_code = ord(digit) code = bytearray(len(mask)) def random_int(a: int, b: int) -> int: b = b - a return int(self.random() * b) + a _mask = mask.encode() for i, p in enumerate(_mask): if p == char_code: a = random_int(65, 91) # A-Z elif p == digit_code: a = random_int(48, 58) # 0-9 else: a = p code[i] = a return code.decode()
python
def custom_code(self, mask: str = '@###', char: str = '@', digit: str = '#') -> str: """Generate custom code using ascii uppercase and random integers. :param mask: Mask of code. :param char: Placeholder for characters. :param digit: Placeholder for digits. :return: Custom code. """ char_code = ord(char) digit_code = ord(digit) code = bytearray(len(mask)) def random_int(a: int, b: int) -> int: b = b - a return int(self.random() * b) + a _mask = mask.encode() for i, p in enumerate(_mask): if p == char_code: a = random_int(65, 91) # A-Z elif p == digit_code: a = random_int(48, 58) # 0-9 else: a = p code[i] = a return code.decode()
[ "def", "custom_code", "(", "self", ",", "mask", ":", "str", "=", "'@###'", ",", "char", ":", "str", "=", "'@'", ",", "digit", ":", "str", "=", "'#'", ")", "->", "str", ":", "char_code", "=", "ord", "(", "char", ")", "digit_code", "=", "ord", "(", "digit", ")", "code", "=", "bytearray", "(", "len", "(", "mask", ")", ")", "def", "random_int", "(", "a", ":", "int", ",", "b", ":", "int", ")", "->", "int", ":", "b", "=", "b", "-", "a", "return", "int", "(", "self", ".", "random", "(", ")", "*", "b", ")", "+", "a", "_mask", "=", "mask", ".", "encode", "(", ")", "for", "i", ",", "p", "in", "enumerate", "(", "_mask", ")", ":", "if", "p", "==", "char_code", ":", "a", "=", "random_int", "(", "65", ",", "91", ")", "# A-Z", "elif", "p", "==", "digit_code", ":", "a", "=", "random_int", "(", "48", ",", "58", ")", "# 0-9", "else", ":", "a", "=", "p", "code", "[", "i", "]", "=", "a", "return", "code", ".", "decode", "(", ")" ]
Generate custom code using ascii uppercase and random integers. :param mask: Mask of code. :param char: Placeholder for characters. :param digit: Placeholder for digits. :return: Custom code.
[ "Generate", "custom", "code", "using", "ascii", "uppercase", "and", "random", "integers", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/random.py#L64-L90
228,053
lk-geimfari/mimesis
mimesis/providers/path.py
Path.user
def user(self) -> str: """Generate a random user. :return: Path to user. :Example: /home/oretha """ user = self.random.choice(USERNAMES) user = user.capitalize() if 'win' in self.platform else user.lower() return str(self._pathlib_home / user)
python
def user(self) -> str: """Generate a random user. :return: Path to user. :Example: /home/oretha """ user = self.random.choice(USERNAMES) user = user.capitalize() if 'win' in self.platform else user.lower() return str(self._pathlib_home / user)
[ "def", "user", "(", "self", ")", "->", "str", ":", "user", "=", "self", ".", "random", ".", "choice", "(", "USERNAMES", ")", "user", "=", "user", ".", "capitalize", "(", ")", "if", "'win'", "in", "self", ".", "platform", "else", "user", ".", "lower", "(", ")", "return", "str", "(", "self", ".", "_pathlib_home", "/", "user", ")" ]
Generate a random user. :return: Path to user. :Example: /home/oretha
[ "Generate", "a", "random", "user", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/path.py#L61-L71
228,054
lk-geimfari/mimesis
mimesis/providers/path.py
Path.users_folder
def users_folder(self) -> str: """Generate a random path to user's folders. :return: Path. :Example: /home/taneka/Pictures """ user = self.user() folder = self.random.choice(FOLDERS) return str(self._pathlib_home / user / folder)
python
def users_folder(self) -> str: """Generate a random path to user's folders. :return: Path. :Example: /home/taneka/Pictures """ user = self.user() folder = self.random.choice(FOLDERS) return str(self._pathlib_home / user / folder)
[ "def", "users_folder", "(", "self", ")", "->", "str", ":", "user", "=", "self", ".", "user", "(", ")", "folder", "=", "self", ".", "random", ".", "choice", "(", "FOLDERS", ")", "return", "str", "(", "self", ".", "_pathlib_home", "/", "user", "/", "folder", ")" ]
Generate a random path to user's folders. :return: Path. :Example: /home/taneka/Pictures
[ "Generate", "a", "random", "path", "to", "user", "s", "folders", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/path.py#L73-L83
228,055
lk-geimfari/mimesis
mimesis/providers/path.py
Path.dev_dir
def dev_dir(self) -> str: """Generate a random path to development directory. :return: Path. :Example: /home/sherrell/Development/Python """ user = self.user() folder = self.random.choice(['Development', 'Dev']) stack = self.random.choice(PROGRAMMING_LANGS) return str(self._pathlib_home / user / folder / stack)
python
def dev_dir(self) -> str: """Generate a random path to development directory. :return: Path. :Example: /home/sherrell/Development/Python """ user = self.user() folder = self.random.choice(['Development', 'Dev']) stack = self.random.choice(PROGRAMMING_LANGS) return str(self._pathlib_home / user / folder / stack)
[ "def", "dev_dir", "(", "self", ")", "->", "str", ":", "user", "=", "self", ".", "user", "(", ")", "folder", "=", "self", ".", "random", ".", "choice", "(", "[", "'Development'", ",", "'Dev'", "]", ")", "stack", "=", "self", ".", "random", ".", "choice", "(", "PROGRAMMING_LANGS", ")", "return", "str", "(", "self", ".", "_pathlib_home", "/", "user", "/", "folder", "/", "stack", ")" ]
Generate a random path to development directory. :return: Path. :Example: /home/sherrell/Development/Python
[ "Generate", "a", "random", "path", "to", "development", "directory", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/path.py#L85-L96
228,056
lk-geimfari/mimesis
mimesis/providers/path.py
Path.project_dir
def project_dir(self) -> str: """Generate a random path to project directory. :return: Path to project. :Example: /home/sherika/Development/Falcon/mercenary """ dev_dir = self.dev_dir() project = self.random.choice(PROJECT_NAMES) return str(self._pathlib_home / dev_dir / project)
python
def project_dir(self) -> str: """Generate a random path to project directory. :return: Path to project. :Example: /home/sherika/Development/Falcon/mercenary """ dev_dir = self.dev_dir() project = self.random.choice(PROJECT_NAMES) return str(self._pathlib_home / dev_dir / project)
[ "def", "project_dir", "(", "self", ")", "->", "str", ":", "dev_dir", "=", "self", ".", "dev_dir", "(", ")", "project", "=", "self", ".", "random", ".", "choice", "(", "PROJECT_NAMES", ")", "return", "str", "(", "self", ".", "_pathlib_home", "/", "dev_dir", "/", "project", ")" ]
Generate a random path to project directory. :return: Path to project. :Example: /home/sherika/Development/Falcon/mercenary
[ "Generate", "a", "random", "path", "to", "project", "directory", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/path.py#L98-L108
228,057
lk-geimfari/mimesis
mimesis/providers/file.py
File.__sub
def __sub(self, string: str = '') -> str: """Replace spaces in string. :param string: String. :return: String without spaces. """ replacer = self.random.choice(['_', '-']) return re.sub(r'\s+', replacer, string.strip())
python
def __sub(self, string: str = '') -> str: """Replace spaces in string. :param string: String. :return: String without spaces. """ replacer = self.random.choice(['_', '-']) return re.sub(r'\s+', replacer, string.strip())
[ "def", "__sub", "(", "self", ",", "string", ":", "str", "=", "''", ")", "->", "str", ":", "replacer", "=", "self", ".", "random", ".", "choice", "(", "[", "'_'", ",", "'-'", "]", ")", "return", "re", ".", "sub", "(", "r'\\s+'", ",", "replacer", ",", "string", ".", "strip", "(", ")", ")" ]
Replace spaces in string. :param string: String. :return: String without spaces.
[ "Replace", "spaces", "in", "string", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/file.py#L33-L40
228,058
lk-geimfari/mimesis
mimesis/providers/file.py
File.extension
def extension(self, file_type: Optional[FileType] = None) -> str: """Get a random file extension from list. :param file_type: Enum object FileType. :return: Extension of the file. :Example: .py """ key = self._validate_enum(item=file_type, enum=FileType) extensions = EXTENSIONS[key] return self.random.choice(extensions)
python
def extension(self, file_type: Optional[FileType] = None) -> str: """Get a random file extension from list. :param file_type: Enum object FileType. :return: Extension of the file. :Example: .py """ key = self._validate_enum(item=file_type, enum=FileType) extensions = EXTENSIONS[key] return self.random.choice(extensions)
[ "def", "extension", "(", "self", ",", "file_type", ":", "Optional", "[", "FileType", "]", "=", "None", ")", "->", "str", ":", "key", "=", "self", ".", "_validate_enum", "(", "item", "=", "file_type", ",", "enum", "=", "FileType", ")", "extensions", "=", "EXTENSIONS", "[", "key", "]", "return", "self", ".", "random", ".", "choice", "(", "extensions", ")" ]
Get a random file extension from list. :param file_type: Enum object FileType. :return: Extension of the file. :Example: .py
[ "Get", "a", "random", "file", "extension", "from", "list", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/file.py#L42-L53
228,059
lk-geimfari/mimesis
mimesis/providers/file.py
File.mime_type
def mime_type(self, type_: Optional[MimeType] = None) -> str: """Get a random mime type from list. :param type_: Enum object MimeType. :return: Mime type. """ key = self._validate_enum(item=type_, enum=MimeType) types = MIME_TYPES[key] return self.random.choice(types)
python
def mime_type(self, type_: Optional[MimeType] = None) -> str: """Get a random mime type from list. :param type_: Enum object MimeType. :return: Mime type. """ key = self._validate_enum(item=type_, enum=MimeType) types = MIME_TYPES[key] return self.random.choice(types)
[ "def", "mime_type", "(", "self", ",", "type_", ":", "Optional", "[", "MimeType", "]", "=", "None", ")", "->", "str", ":", "key", "=", "self", ".", "_validate_enum", "(", "item", "=", "type_", ",", "enum", "=", "MimeType", ")", "types", "=", "MIME_TYPES", "[", "key", "]", "return", "self", ".", "random", ".", "choice", "(", "types", ")" ]
Get a random mime type from list. :param type_: Enum object MimeType. :return: Mime type.
[ "Get", "a", "random", "mime", "type", "from", "list", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/file.py#L55-L63
228,060
lk-geimfari/mimesis
mimesis/providers/file.py
File.file_name
def file_name(self, file_type: Optional[FileType] = None) -> str: """Get a random file name with some extension. :param file_type: Enum object FileType :return: File name. :Example: legislative.txt """ name = self.__text.word() ext = self.extension(file_type) return '{name}{ext}'.format( name=self.__sub(name), ext=ext, )
python
def file_name(self, file_type: Optional[FileType] = None) -> str: """Get a random file name with some extension. :param file_type: Enum object FileType :return: File name. :Example: legislative.txt """ name = self.__text.word() ext = self.extension(file_type) return '{name}{ext}'.format( name=self.__sub(name), ext=ext, )
[ "def", "file_name", "(", "self", ",", "file_type", ":", "Optional", "[", "FileType", "]", "=", "None", ")", "->", "str", ":", "name", "=", "self", ".", "__text", ".", "word", "(", ")", "ext", "=", "self", ".", "extension", "(", "file_type", ")", "return", "'{name}{ext}'", ".", "format", "(", "name", "=", "self", ".", "__sub", "(", "name", ")", ",", "ext", "=", "ext", ",", ")" ]
Get a random file name with some extension. :param file_type: Enum object FileType :return: File name. :Example: legislative.txt
[ "Get", "a", "random", "file", "name", "with", "some", "extension", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/file.py#L84-L99
228,061
lk-geimfari/mimesis
mimesis/builtins/de.py
GermanySpecProvider.noun
def noun(self, plural: bool = False) -> str: """Return a random noun in German. :param plural: Return noun in plural. :return: Noun. """ key = 'plural' if \ plural else 'noun' return self.random.choice(self._data[key])
python
def noun(self, plural: bool = False) -> str: """Return a random noun in German. :param plural: Return noun in plural. :return: Noun. """ key = 'plural' if \ plural else 'noun' return self.random.choice(self._data[key])
[ "def", "noun", "(", "self", ",", "plural", ":", "bool", "=", "False", ")", "->", "str", ":", "key", "=", "'plural'", "if", "plural", "else", "'noun'", "return", "self", ".", "random", ".", "choice", "(", "self", ".", "_data", "[", "key", "]", ")" ]
Return a random noun in German. :param plural: Return noun in plural. :return: Noun.
[ "Return", "a", "random", "noun", "in", "German", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/builtins/de.py#L24-L33
228,062
lk-geimfari/mimesis
mimesis/providers/payment.py
Payment.bitcoin_address
def bitcoin_address(self) -> str: """Generate a random bitcoin address. :return: Bitcoin address. :Example: 3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX """ type_ = self.random.choice(['1', '3']) letters = string.ascii_letters + string.digits return type_ + ''.join( self.random.choice(letters) for _ in range(33))
python
def bitcoin_address(self) -> str: """Generate a random bitcoin address. :return: Bitcoin address. :Example: 3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX """ type_ = self.random.choice(['1', '3']) letters = string.ascii_letters + string.digits return type_ + ''.join( self.random.choice(letters) for _ in range(33))
[ "def", "bitcoin_address", "(", "self", ")", "->", "str", ":", "type_", "=", "self", ".", "random", ".", "choice", "(", "[", "'1'", ",", "'3'", "]", ")", "letters", "=", "string", ".", "ascii_letters", "+", "string", ".", "digits", "return", "type_", "+", "''", ".", "join", "(", "self", ".", "random", ".", "choice", "(", "letters", ")", "for", "_", "in", "range", "(", "33", ")", ")" ]
Generate a random bitcoin address. :return: Bitcoin address. :Example: 3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX
[ "Generate", "a", "random", "bitcoin", "address", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/payment.py#L57-L68
228,063
lk-geimfari/mimesis
mimesis/providers/payment.py
Payment.ethereum_address
def ethereum_address(self) -> str: """Generate a random Ethereum address. .. Note: The address will look like Ethereum address, but keep in mind that it is not the valid address. :return: Ethereum address. :Example: 0xe8ece9e6ff7dba52d4c07d37418036a89af9698d """ bits = self.random.getrandbits(160) address = bits.to_bytes(20, byteorder='big') return '0x' + address.hex()
python
def ethereum_address(self) -> str: """Generate a random Ethereum address. .. Note: The address will look like Ethereum address, but keep in mind that it is not the valid address. :return: Ethereum address. :Example: 0xe8ece9e6ff7dba52d4c07d37418036a89af9698d """ bits = self.random.getrandbits(160) address = bits.to_bytes(20, byteorder='big') return '0x' + address.hex()
[ "def", "ethereum_address", "(", "self", ")", "->", "str", ":", "bits", "=", "self", ".", "random", ".", "getrandbits", "(", "160", ")", "address", "=", "bits", ".", "to_bytes", "(", "20", ",", "byteorder", "=", "'big'", ")", "return", "'0x'", "+", "address", ".", "hex", "(", ")" ]
Generate a random Ethereum address. .. Note: The address will look like Ethereum address, but keep in mind that it is not the valid address. :return: Ethereum address. :Example: 0xe8ece9e6ff7dba52d4c07d37418036a89af9698d
[ "Generate", "a", "random", "Ethereum", "address", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/payment.py#L70-L83
228,064
lk-geimfari/mimesis
mimesis/providers/payment.py
Payment.credit_card_number
def credit_card_number(self, card_type: Optional[CardType] = None) -> str: """Generate a random credit card number. :param card_type: Issuing Network. Default is Visa. :return: Credit card number. :raises NotImplementedError: if cart_type is not supported. :Example: 4455 5299 1152 2450 """ length = 16 regex = re.compile(r'(\d{4})(\d{4})(\d{4})(\d{4})') if card_type is None: card_type = get_random_item(CardType, rnd=self.random) if card_type == CardType.VISA: number = self.random.randint(4000, 4999) elif card_type == CardType.MASTER_CARD: number = self.random.choice([ self.random.randint(2221, 2720), self.random.randint(5100, 5599), ]) elif card_type == CardType.AMERICAN_EXPRESS: number = self.random.choice([34, 37]) length = 15 regex = re.compile(r'(\d{4})(\d{6})(\d{5})') else: raise NonEnumerableError(CardType) str_num = str(number) while len(str_num) < length - 1: str_num += self.random.choice(string.digits) groups = regex.search( # type: ignore str_num + luhn_checksum(str_num), ).groups() card = ' '.join(groups) return card
python
def credit_card_number(self, card_type: Optional[CardType] = None) -> str: """Generate a random credit card number. :param card_type: Issuing Network. Default is Visa. :return: Credit card number. :raises NotImplementedError: if cart_type is not supported. :Example: 4455 5299 1152 2450 """ length = 16 regex = re.compile(r'(\d{4})(\d{4})(\d{4})(\d{4})') if card_type is None: card_type = get_random_item(CardType, rnd=self.random) if card_type == CardType.VISA: number = self.random.randint(4000, 4999) elif card_type == CardType.MASTER_CARD: number = self.random.choice([ self.random.randint(2221, 2720), self.random.randint(5100, 5599), ]) elif card_type == CardType.AMERICAN_EXPRESS: number = self.random.choice([34, 37]) length = 15 regex = re.compile(r'(\d{4})(\d{6})(\d{5})') else: raise NonEnumerableError(CardType) str_num = str(number) while len(str_num) < length - 1: str_num += self.random.choice(string.digits) groups = regex.search( # type: ignore str_num + luhn_checksum(str_num), ).groups() card = ' '.join(groups) return card
[ "def", "credit_card_number", "(", "self", ",", "card_type", ":", "Optional", "[", "CardType", "]", "=", "None", ")", "->", "str", ":", "length", "=", "16", "regex", "=", "re", ".", "compile", "(", "r'(\\d{4})(\\d{4})(\\d{4})(\\d{4})'", ")", "if", "card_type", "is", "None", ":", "card_type", "=", "get_random_item", "(", "CardType", ",", "rnd", "=", "self", ".", "random", ")", "if", "card_type", "==", "CardType", ".", "VISA", ":", "number", "=", "self", ".", "random", ".", "randint", "(", "4000", ",", "4999", ")", "elif", "card_type", "==", "CardType", ".", "MASTER_CARD", ":", "number", "=", "self", ".", "random", ".", "choice", "(", "[", "self", ".", "random", ".", "randint", "(", "2221", ",", "2720", ")", ",", "self", ".", "random", ".", "randint", "(", "5100", ",", "5599", ")", ",", "]", ")", "elif", "card_type", "==", "CardType", ".", "AMERICAN_EXPRESS", ":", "number", "=", "self", ".", "random", ".", "choice", "(", "[", "34", ",", "37", "]", ")", "length", "=", "15", "regex", "=", "re", ".", "compile", "(", "r'(\\d{4})(\\d{6})(\\d{5})'", ")", "else", ":", "raise", "NonEnumerableError", "(", "CardType", ")", "str_num", "=", "str", "(", "number", ")", "while", "len", "(", "str_num", ")", "<", "length", "-", "1", ":", "str_num", "+=", "self", ".", "random", ".", "choice", "(", "string", ".", "digits", ")", "groups", "=", "regex", ".", "search", "(", "# type: ignore", "str_num", "+", "luhn_checksum", "(", "str_num", ")", ",", ")", ".", "groups", "(", ")", "card", "=", "' '", ".", "join", "(", "groups", ")", "return", "card" ]
Generate a random credit card number. :param card_type: Issuing Network. Default is Visa. :return: Credit card number. :raises NotImplementedError: if cart_type is not supported. :Example: 4455 5299 1152 2450
[ "Generate", "a", "random", "credit", "card", "number", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/payment.py#L95-L133
228,065
lk-geimfari/mimesis
mimesis/providers/payment.py
Payment.credit_card_expiration_date
def credit_card_expiration_date(self, minimum: int = 16, maximum: int = 25) -> str: """Generate a random expiration date for credit card. :param minimum: Date of issue. :param maximum: Maximum of expiration_date. :return: Expiration date of credit card. :Example: 03/19. """ month = self.random.randint(1, 12) year = self.random.randint(minimum, maximum) return '{0:02d}/{1}'.format(month, year)
python
def credit_card_expiration_date(self, minimum: int = 16, maximum: int = 25) -> str: """Generate a random expiration date for credit card. :param minimum: Date of issue. :param maximum: Maximum of expiration_date. :return: Expiration date of credit card. :Example: 03/19. """ month = self.random.randint(1, 12) year = self.random.randint(minimum, maximum) return '{0:02d}/{1}'.format(month, year)
[ "def", "credit_card_expiration_date", "(", "self", ",", "minimum", ":", "int", "=", "16", ",", "maximum", ":", "int", "=", "25", ")", "->", "str", ":", "month", "=", "self", ".", "random", ".", "randint", "(", "1", ",", "12", ")", "year", "=", "self", ".", "random", ".", "randint", "(", "minimum", ",", "maximum", ")", "return", "'{0:02d}/{1}'", ".", "format", "(", "month", ",", "year", ")" ]
Generate a random expiration date for credit card. :param minimum: Date of issue. :param maximum: Maximum of expiration_date. :return: Expiration date of credit card. :Example: 03/19.
[ "Generate", "a", "random", "expiration", "date", "for", "credit", "card", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/payment.py#L135-L148
228,066
lk-geimfari/mimesis
mimesis/providers/payment.py
Payment.credit_card_owner
def credit_card_owner(self, gender: Optional[Gender] = None) -> dict: """Generate credit card owner. :param gender: Gender of credit card owner. :type gender: Gender's enum object. :return: """ owner = { 'credit_card': self.credit_card_number(), 'expiration_date': self.credit_card_expiration_date(), 'owner': self.__person.full_name(gender=gender).upper(), } return owner
python
def credit_card_owner(self, gender: Optional[Gender] = None) -> dict: """Generate credit card owner. :param gender: Gender of credit card owner. :type gender: Gender's enum object. :return: """ owner = { 'credit_card': self.credit_card_number(), 'expiration_date': self.credit_card_expiration_date(), 'owner': self.__person.full_name(gender=gender).upper(), } return owner
[ "def", "credit_card_owner", "(", "self", ",", "gender", ":", "Optional", "[", "Gender", "]", "=", "None", ")", "->", "dict", ":", "owner", "=", "{", "'credit_card'", ":", "self", ".", "credit_card_number", "(", ")", ",", "'expiration_date'", ":", "self", ".", "credit_card_expiration_date", "(", ")", ",", "'owner'", ":", "self", ".", "__person", ".", "full_name", "(", "gender", "=", "gender", ")", ".", "upper", "(", ")", ",", "}", "return", "owner" ]
Generate credit card owner. :param gender: Gender of credit card owner. :type gender: Gender's enum object. :return:
[ "Generate", "credit", "card", "owner", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/payment.py#L160-L172
228,067
lk-geimfari/mimesis
mimesis/providers/text.py
Text.alphabet
def alphabet(self, lower_case: bool = False) -> list: """Get an alphabet for current locale. :param lower_case: Return alphabet in lower case. :return: Alphabet. """ case = 'uppercase' if \ not lower_case else 'lowercase' alpha = self._data['alphabet'].get(case) return alpha
python
def alphabet(self, lower_case: bool = False) -> list: """Get an alphabet for current locale. :param lower_case: Return alphabet in lower case. :return: Alphabet. """ case = 'uppercase' if \ not lower_case else 'lowercase' alpha = self._data['alphabet'].get(case) return alpha
[ "def", "alphabet", "(", "self", ",", "lower_case", ":", "bool", "=", "False", ")", "->", "list", ":", "case", "=", "'uppercase'", "if", "not", "lower_case", "else", "'lowercase'", "alpha", "=", "self", ".", "_data", "[", "'alphabet'", "]", ".", "get", "(", "case", ")", "return", "alpha" ]
Get an alphabet for current locale. :param lower_case: Return alphabet in lower case. :return: Alphabet.
[ "Get", "an", "alphabet", "for", "current", "locale", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/text.py#L31-L41
228,068
lk-geimfari/mimesis
mimesis/providers/text.py
Text.level
def level(self) -> str: """Generate a random level of danger or something else. :return: Level. :Example: critical. """ levels = self._data['level'] return self.random.choice(levels)
python
def level(self) -> str: """Generate a random level of danger or something else. :return: Level. :Example: critical. """ levels = self._data['level'] return self.random.choice(levels)
[ "def", "level", "(", "self", ")", "->", "str", ":", "levels", "=", "self", ".", "_data", "[", "'level'", "]", "return", "self", ".", "random", ".", "choice", "(", "levels", ")" ]
Generate a random level of danger or something else. :return: Level. :Example: critical.
[ "Generate", "a", "random", "level", "of", "danger", "or", "something", "else", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/text.py#L43-L52
228,069
lk-geimfari/mimesis
mimesis/providers/text.py
Text.text
def text(self, quantity: int = 5) -> str: """Generate the text. :param quantity: Quantity of sentences. :return: Text. """ text = '' for _ in range(quantity): text += ' ' + self.random.choice(self._data['text']) return text.strip()
python
def text(self, quantity: int = 5) -> str: """Generate the text. :param quantity: Quantity of sentences. :return: Text. """ text = '' for _ in range(quantity): text += ' ' + self.random.choice(self._data['text']) return text.strip()
[ "def", "text", "(", "self", ",", "quantity", ":", "int", "=", "5", ")", "->", "str", ":", "text", "=", "''", "for", "_", "in", "range", "(", "quantity", ")", ":", "text", "+=", "' '", "+", "self", ".", "random", ".", "choice", "(", "self", ".", "_data", "[", "'text'", "]", ")", "return", "text", ".", "strip", "(", ")" ]
Generate the text. :param quantity: Quantity of sentences. :return: Text.
[ "Generate", "the", "text", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/text.py#L54-L63
228,070
lk-geimfari/mimesis
mimesis/providers/text.py
Text.words
def words(self, quantity: int = 5) -> List[str]: """Generate lis of the random words. :param quantity: Quantity of words. Default is 5. :return: Word list. :Example: [science, network, god, octopus, love] """ words = self._data['words'].get('normal') words_list = [self.random.choice(words) for _ in range(quantity)] return words_list
python
def words(self, quantity: int = 5) -> List[str]: """Generate lis of the random words. :param quantity: Quantity of words. Default is 5. :return: Word list. :Example: [science, network, god, octopus, love] """ words = self._data['words'].get('normal') words_list = [self.random.choice(words) for _ in range(quantity)] return words_list
[ "def", "words", "(", "self", ",", "quantity", ":", "int", "=", "5", ")", "->", "List", "[", "str", "]", ":", "words", "=", "self", ".", "_data", "[", "'words'", "]", ".", "get", "(", "'normal'", ")", "words_list", "=", "[", "self", ".", "random", ".", "choice", "(", "words", ")", "for", "_", "in", "range", "(", "quantity", ")", "]", "return", "words_list" ]
Generate lis of the random words. :param quantity: Quantity of words. Default is 5. :return: Word list. :Example: [science, network, god, octopus, love]
[ "Generate", "lis", "of", "the", "random", "words", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/text.py#L79-L90
228,071
lk-geimfari/mimesis
mimesis/providers/text.py
Text.swear_word
def swear_word(self) -> str: """Get a random swear word. :return: Swear word. :Example: Damn. """ bad_words = self._data['words'].get('bad') return self.random.choice(bad_words)
python
def swear_word(self) -> str: """Get a random swear word. :return: Swear word. :Example: Damn. """ bad_words = self._data['words'].get('bad') return self.random.choice(bad_words)
[ "def", "swear_word", "(", "self", ")", "->", "str", ":", "bad_words", "=", "self", ".", "_data", "[", "'words'", "]", ".", "get", "(", "'bad'", ")", "return", "self", ".", "random", ".", "choice", "(", "bad_words", ")" ]
Get a random swear word. :return: Swear word. :Example: Damn.
[ "Get", "a", "random", "swear", "word", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/text.py#L102-L111
228,072
lk-geimfari/mimesis
mimesis/providers/text.py
Text.quote
def quote(self) -> str: """Get a random quote. :return: Quote from movie. :Example: "Bond... James Bond." """ quotes = self._data['quotes'] return self.random.choice(quotes)
python
def quote(self) -> str: """Get a random quote. :return: Quote from movie. :Example: "Bond... James Bond." """ quotes = self._data['quotes'] return self.random.choice(quotes)
[ "def", "quote", "(", "self", ")", "->", "str", ":", "quotes", "=", "self", ".", "_data", "[", "'quotes'", "]", "return", "self", ".", "random", ".", "choice", "(", "quotes", ")" ]
Get a random quote. :return: Quote from movie. :Example: "Bond... James Bond."
[ "Get", "a", "random", "quote", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/text.py#L113-L122
228,073
lk-geimfari/mimesis
mimesis/providers/text.py
Text.color
def color(self) -> str: """Get a random name of color. :return: Color name. :Example: Red. """ colors = self._data['color'] return self.random.choice(colors)
python
def color(self) -> str: """Get a random name of color. :return: Color name. :Example: Red. """ colors = self._data['color'] return self.random.choice(colors)
[ "def", "color", "(", "self", ")", "->", "str", ":", "colors", "=", "self", ".", "_data", "[", "'color'", "]", "return", "self", ".", "random", ".", "choice", "(", "colors", ")" ]
Get a random name of color. :return: Color name. :Example: Red.
[ "Get", "a", "random", "name", "of", "color", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/text.py#L124-L133
228,074
lk-geimfari/mimesis
mimesis/providers/text.py
Text._hex_to_rgb
def _hex_to_rgb(color: str) -> Tuple[int, ...]: """Convert hex color to RGB format. :param color: Hex color. :return: RGB tuple. """ if color.startswith('#'): color = color.lstrip('#') return tuple(int(color[i:i + 2], 16) for i in (0, 2, 4))
python
def _hex_to_rgb(color: str) -> Tuple[int, ...]: """Convert hex color to RGB format. :param color: Hex color. :return: RGB tuple. """ if color.startswith('#'): color = color.lstrip('#') return tuple(int(color[i:i + 2], 16) for i in (0, 2, 4))
[ "def", "_hex_to_rgb", "(", "color", ":", "str", ")", "->", "Tuple", "[", "int", ",", "...", "]", ":", "if", "color", ".", "startswith", "(", "'#'", ")", ":", "color", "=", "color", ".", "lstrip", "(", "'#'", ")", "return", "tuple", "(", "int", "(", "color", "[", "i", ":", "i", "+", "2", "]", ",", "16", ")", "for", "i", "in", "(", "0", ",", "2", ",", "4", ")", ")" ]
Convert hex color to RGB format. :param color: Hex color. :return: RGB tuple.
[ "Convert", "hex", "color", "to", "RGB", "format", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/text.py#L136-L144
228,075
lk-geimfari/mimesis
mimesis/providers/text.py
Text.hex_color
def hex_color(self, safe: bool = False) -> str: """Generate a random hex color. :param safe: Get safe Flat UI hex color. :return: Hex color code. :Example: #d8346b """ if safe: return self.random.choice(SAFE_COLORS) return '#{:06x}'.format( self.random.randint(0x000000, 0xffffff))
python
def hex_color(self, safe: bool = False) -> str: """Generate a random hex color. :param safe: Get safe Flat UI hex color. :return: Hex color code. :Example: #d8346b """ if safe: return self.random.choice(SAFE_COLORS) return '#{:06x}'.format( self.random.randint(0x000000, 0xffffff))
[ "def", "hex_color", "(", "self", ",", "safe", ":", "bool", "=", "False", ")", "->", "str", ":", "if", "safe", ":", "return", "self", ".", "random", ".", "choice", "(", "SAFE_COLORS", ")", "return", "'#{:06x}'", ".", "format", "(", "self", ".", "random", ".", "randint", "(", "0x000000", ",", "0xffffff", ")", ")" ]
Generate a random hex color. :param safe: Get safe Flat UI hex color. :return: Hex color code. :Example: #d8346b
[ "Generate", "a", "random", "hex", "color", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/text.py#L146-L159
228,076
lk-geimfari/mimesis
mimesis/providers/text.py
Text.rgb_color
def rgb_color(self, safe: bool = False) -> Tuple[int, ...]: """Generate a random rgb color tuple. :param safe: Get safe RGB tuple. :return: RGB tuple. :Example: (252, 85, 32) """ color = self.hex_color(safe) return self._hex_to_rgb(color)
python
def rgb_color(self, safe: bool = False) -> Tuple[int, ...]: """Generate a random rgb color tuple. :param safe: Get safe RGB tuple. :return: RGB tuple. :Example: (252, 85, 32) """ color = self.hex_color(safe) return self._hex_to_rgb(color)
[ "def", "rgb_color", "(", "self", ",", "safe", ":", "bool", "=", "False", ")", "->", "Tuple", "[", "int", ",", "...", "]", ":", "color", "=", "self", ".", "hex_color", "(", "safe", ")", "return", "self", ".", "_hex_to_rgb", "(", "color", ")" ]
Generate a random rgb color tuple. :param safe: Get safe RGB tuple. :return: RGB tuple. :Example: (252, 85, 32)
[ "Generate", "a", "random", "rgb", "color", "tuple", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/text.py#L161-L171
228,077
lk-geimfari/mimesis
mimesis/providers/text.py
Text.answer
def answer(self) -> str: """Get a random answer in current language. :return: An answer. :Example: No """ answers = self._data['answers'] return self.random.choice(answers)
python
def answer(self) -> str: """Get a random answer in current language. :return: An answer. :Example: No """ answers = self._data['answers'] return self.random.choice(answers)
[ "def", "answer", "(", "self", ")", "->", "str", ":", "answers", "=", "self", ".", "_data", "[", "'answers'", "]", "return", "self", ".", "random", ".", "choice", "(", "answers", ")" ]
Get a random answer in current language. :return: An answer. :Example: No
[ "Get", "a", "random", "answer", "in", "current", "language", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/text.py#L173-L182
228,078
lk-geimfari/mimesis
mimesis/providers/code.py
Code.issn
def issn(self, mask: str = '####-####') -> str: """Generate a random ISSN. :param mask: Mask of ISSN. :return: ISSN. """ return self.random.custom_code(mask=mask)
python
def issn(self, mask: str = '####-####') -> str: """Generate a random ISSN. :param mask: Mask of ISSN. :return: ISSN. """ return self.random.custom_code(mask=mask)
[ "def", "issn", "(", "self", ",", "mask", ":", "str", "=", "'####-####'", ")", "->", "str", ":", "return", "self", ".", "random", ".", "custom_code", "(", "mask", "=", "mask", ")" ]
Generate a random ISSN. :param mask: Mask of ISSN. :return: ISSN.
[ "Generate", "a", "random", "ISSN", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/code.py#L46-L52
228,079
lk-geimfari/mimesis
mimesis/providers/code.py
Code.isbn
def isbn(self, fmt: Optional[ISBNFormat] = None, locale: str = 'en') -> str: """Generate ISBN for current locale. To change ISBN format, pass parameter ``fmt`` with needed value of the enum object :class:`~mimesis.enums.ISBNFormat` :param fmt: ISBN format. :param locale: Locale code. :return: ISBN. :raises NonEnumerableError: if fmt is not enum ISBNFormat. """ fmt_value = self._validate_enum(item=fmt, enum=ISBNFormat) mask = ISBN_MASKS[fmt_value].format( ISBN_GROUPS[locale]) return self.random.custom_code(mask)
python
def isbn(self, fmt: Optional[ISBNFormat] = None, locale: str = 'en') -> str: """Generate ISBN for current locale. To change ISBN format, pass parameter ``fmt`` with needed value of the enum object :class:`~mimesis.enums.ISBNFormat` :param fmt: ISBN format. :param locale: Locale code. :return: ISBN. :raises NonEnumerableError: if fmt is not enum ISBNFormat. """ fmt_value = self._validate_enum(item=fmt, enum=ISBNFormat) mask = ISBN_MASKS[fmt_value].format( ISBN_GROUPS[locale]) return self.random.custom_code(mask)
[ "def", "isbn", "(", "self", ",", "fmt", ":", "Optional", "[", "ISBNFormat", "]", "=", "None", ",", "locale", ":", "str", "=", "'en'", ")", "->", "str", ":", "fmt_value", "=", "self", ".", "_validate_enum", "(", "item", "=", "fmt", ",", "enum", "=", "ISBNFormat", ")", "mask", "=", "ISBN_MASKS", "[", "fmt_value", "]", ".", "format", "(", "ISBN_GROUPS", "[", "locale", "]", ")", "return", "self", ".", "random", ".", "custom_code", "(", "mask", ")" ]
Generate ISBN for current locale. To change ISBN format, pass parameter ``fmt`` with needed value of the enum object :class:`~mimesis.enums.ISBNFormat` :param fmt: ISBN format. :param locale: Locale code. :return: ISBN. :raises NonEnumerableError: if fmt is not enum ISBNFormat.
[ "Generate", "ISBN", "for", "current", "locale", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/code.py#L54-L69
228,080
lk-geimfari/mimesis
mimesis/providers/code.py
Code.ean
def ean(self, fmt: Optional[EANFormat] = None) -> str: """Generate EAN. To change EAN format, pass parameter ``fmt`` with needed value of the enum object :class:`~mimesis.enums.EANFormat`. :param fmt: Format of EAN. :return: EAN. :raises NonEnumerableError: if fmt is not enum EANFormat. """ key = self._validate_enum( item=fmt, enum=EANFormat, ) mask = EAN_MASKS[key] return self.random.custom_code(mask=mask)
python
def ean(self, fmt: Optional[EANFormat] = None) -> str: """Generate EAN. To change EAN format, pass parameter ``fmt`` with needed value of the enum object :class:`~mimesis.enums.EANFormat`. :param fmt: Format of EAN. :return: EAN. :raises NonEnumerableError: if fmt is not enum EANFormat. """ key = self._validate_enum( item=fmt, enum=EANFormat, ) mask = EAN_MASKS[key] return self.random.custom_code(mask=mask)
[ "def", "ean", "(", "self", ",", "fmt", ":", "Optional", "[", "EANFormat", "]", "=", "None", ")", "->", "str", ":", "key", "=", "self", ".", "_validate_enum", "(", "item", "=", "fmt", ",", "enum", "=", "EANFormat", ",", ")", "mask", "=", "EAN_MASKS", "[", "key", "]", "return", "self", ".", "random", ".", "custom_code", "(", "mask", "=", "mask", ")" ]
Generate EAN. To change EAN format, pass parameter ``fmt`` with needed value of the enum object :class:`~mimesis.enums.EANFormat`. :param fmt: Format of EAN. :return: EAN. :raises NonEnumerableError: if fmt is not enum EANFormat.
[ "Generate", "EAN", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/code.py#L71-L86
228,081
lk-geimfari/mimesis
mimesis/providers/code.py
Code.imei
def imei(self) -> str: """Generate a random IMEI. :return: IMEI. """ num = self.random.choice(IMEI_TACS) num = num + str(self.random.randint(100000, 999999)) return num + luhn_checksum(num)
python
def imei(self) -> str: """Generate a random IMEI. :return: IMEI. """ num = self.random.choice(IMEI_TACS) num = num + str(self.random.randint(100000, 999999)) return num + luhn_checksum(num)
[ "def", "imei", "(", "self", ")", "->", "str", ":", "num", "=", "self", ".", "random", ".", "choice", "(", "IMEI_TACS", ")", "num", "=", "num", "+", "str", "(", "self", ".", "random", ".", "randint", "(", "100000", ",", "999999", ")", ")", "return", "num", "+", "luhn_checksum", "(", "num", ")" ]
Generate a random IMEI. :return: IMEI.
[ "Generate", "a", "random", "IMEI", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/code.py#L88-L95
228,082
lk-geimfari/mimesis
mimesis/providers/code.py
Code.pin
def pin(self, mask: str = '####') -> str: """Generate a random PIN code. :param mask: Mask of pin code. :return: PIN code. """ return self.random.custom_code(mask=mask)
python
def pin(self, mask: str = '####') -> str: """Generate a random PIN code. :param mask: Mask of pin code. :return: PIN code. """ return self.random.custom_code(mask=mask)
[ "def", "pin", "(", "self", ",", "mask", ":", "str", "=", "'####'", ")", "->", "str", ":", "return", "self", ".", "random", ".", "custom_code", "(", "mask", "=", "mask", ")" ]
Generate a random PIN code. :param mask: Mask of pin code. :return: PIN code.
[ "Generate", "a", "random", "PIN", "code", "." ]
4b16ee7a8dba6281a904654a88dbb4b052869fc5
https://github.com/lk-geimfari/mimesis/blob/4b16ee7a8dba6281a904654a88dbb4b052869fc5/mimesis/providers/code.py#L97-L103
228,083
sassoftware/saspy
saspy/sasbase.py
SASsession.submit
def submit(self, code: str, results: str = '', prompt: dict = None) -> dict: ''' This method is used to submit any SAS code. It returns the Log and Listing as a python dictionary. - code - the SAS statements you want to execute - results - format of results. 'HTML' by default, alternatively 'TEXT' - prompt - dict of names:flags to prompt for; create macro variables (used in submitted code), then keep or delete the keys which are the names of the macro variables. The boolean flag is to either hide what you type and delete the macros, or show what you type and keep the macros (they will still be available later). for example (what you type for pw will not be displayed, user and dsname will): .. code-block:: python results_dict = sas.submit( """ libname tera teradata server=teracop1 user=&user pw=&pw; proc print data=tera.&dsname (obs=10); run; """ , prompt = {'user': False, 'pw': True, 'dsname': False} ) Returns - a Dict containing two keys:values, [LOG, LST]. LOG is text and LST is 'results' (HTML or TEXT) NOTE: to view HTML results in the ipykernel, issue: from IPython.display import HTML and use HTML() instead of print() In Zeppelin, the html LST results can be displayed via print("%html "+ ll['LST']) to diplay as HTML. i.e,: results = sas.submit("data a; x=1; run; proc print;run') print(results['LOG']) HTML(results['LST']) ''' if self.nosub: return dict(LOG=code, LST='') prompt = prompt if prompt is not None else {} if results == '': if self.results.upper() == 'PANDAS': results = 'HTML' else: results = self.results ll = self._io.submit(code, results, prompt) return ll
python
def submit(self, code: str, results: str = '', prompt: dict = None) -> dict: ''' This method is used to submit any SAS code. It returns the Log and Listing as a python dictionary. - code - the SAS statements you want to execute - results - format of results. 'HTML' by default, alternatively 'TEXT' - prompt - dict of names:flags to prompt for; create macro variables (used in submitted code), then keep or delete the keys which are the names of the macro variables. The boolean flag is to either hide what you type and delete the macros, or show what you type and keep the macros (they will still be available later). for example (what you type for pw will not be displayed, user and dsname will): .. code-block:: python results_dict = sas.submit( """ libname tera teradata server=teracop1 user=&user pw=&pw; proc print data=tera.&dsname (obs=10); run; """ , prompt = {'user': False, 'pw': True, 'dsname': False} ) Returns - a Dict containing two keys:values, [LOG, LST]. LOG is text and LST is 'results' (HTML or TEXT) NOTE: to view HTML results in the ipykernel, issue: from IPython.display import HTML and use HTML() instead of print() In Zeppelin, the html LST results can be displayed via print("%html "+ ll['LST']) to diplay as HTML. i.e,: results = sas.submit("data a; x=1; run; proc print;run') print(results['LOG']) HTML(results['LST']) ''' if self.nosub: return dict(LOG=code, LST='') prompt = prompt if prompt is not None else {} if results == '': if self.results.upper() == 'PANDAS': results = 'HTML' else: results = self.results ll = self._io.submit(code, results, prompt) return ll
[ "def", "submit", "(", "self", ",", "code", ":", "str", ",", "results", ":", "str", "=", "''", ",", "prompt", ":", "dict", "=", "None", ")", "->", "dict", ":", "if", "self", ".", "nosub", ":", "return", "dict", "(", "LOG", "=", "code", ",", "LST", "=", "''", ")", "prompt", "=", "prompt", "if", "prompt", "is", "not", "None", "else", "{", "}", "if", "results", "==", "''", ":", "if", "self", ".", "results", ".", "upper", "(", ")", "==", "'PANDAS'", ":", "results", "=", "'HTML'", "else", ":", "results", "=", "self", ".", "results", "ll", "=", "self", ".", "_io", ".", "submit", "(", "code", ",", "results", ",", "prompt", ")", "return", "ll" ]
This method is used to submit any SAS code. It returns the Log and Listing as a python dictionary. - code - the SAS statements you want to execute - results - format of results. 'HTML' by default, alternatively 'TEXT' - prompt - dict of names:flags to prompt for; create macro variables (used in submitted code), then keep or delete the keys which are the names of the macro variables. The boolean flag is to either hide what you type and delete the macros, or show what you type and keep the macros (they will still be available later). for example (what you type for pw will not be displayed, user and dsname will): .. code-block:: python results_dict = sas.submit( """ libname tera teradata server=teracop1 user=&user pw=&pw; proc print data=tera.&dsname (obs=10); run; """ , prompt = {'user': False, 'pw': True, 'dsname': False} ) Returns - a Dict containing two keys:values, [LOG, LST]. LOG is text and LST is 'results' (HTML or TEXT) NOTE: to view HTML results in the ipykernel, issue: from IPython.display import HTML and use HTML() instead of print() In Zeppelin, the html LST results can be displayed via print("%html "+ ll['LST']) to diplay as HTML. i.e,: results = sas.submit("data a; x=1; run; proc print;run') print(results['LOG']) HTML(results['LST'])
[ "This", "method", "is", "used", "to", "submit", "any", "SAS", "code", ".", "It", "returns", "the", "Log", "and", "Listing", "as", "a", "python", "dictionary", "." ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L446-L492
228,084
sassoftware/saspy
saspy/sasbase.py
SASsession.exist
def exist(self, table: str, libref: str = "") -> bool: """ Does the SAS data set currently exist :param table: the name of the SAS Data Set :param libref: the libref for the Data Set, defaults to WORK, or USER if assigned :return: Boolean True it the Data Set exists and False if it does not :rtype: bool """ return self._io.exist(table, libref)
python
def exist(self, table: str, libref: str = "") -> bool: """ Does the SAS data set currently exist :param table: the name of the SAS Data Set :param libref: the libref for the Data Set, defaults to WORK, or USER if assigned :return: Boolean True it the Data Set exists and False if it does not :rtype: bool """ return self._io.exist(table, libref)
[ "def", "exist", "(", "self", ",", "table", ":", "str", ",", "libref", ":", "str", "=", "\"\"", ")", "->", "bool", ":", "return", "self", ".", "_io", ".", "exist", "(", "table", ",", "libref", ")" ]
Does the SAS data set currently exist :param table: the name of the SAS Data Set :param libref: the libref for the Data Set, defaults to WORK, or USER if assigned :return: Boolean True it the Data Set exists and False if it does not :rtype: bool
[ "Does", "the", "SAS", "data", "set", "currently", "exist" ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L540-L549
228,085
sassoftware/saspy
saspy/sasbase.py
SASsession.sasstat
def sasstat(self) -> 'SASstat': """ This methods creates a SASstat object which you can use to run various analytics. See the sasstat.py module. :return: sasstat object """ if not self._loaded_macros: self._loadmacros() self._loaded_macros = True return SASstat(self)
python
def sasstat(self) -> 'SASstat': """ This methods creates a SASstat object which you can use to run various analytics. See the sasstat.py module. :return: sasstat object """ if not self._loaded_macros: self._loadmacros() self._loaded_macros = True return SASstat(self)
[ "def", "sasstat", "(", "self", ")", "->", "'SASstat'", ":", "if", "not", "self", ".", "_loaded_macros", ":", "self", ".", "_loadmacros", "(", ")", "self", ".", "_loaded_macros", "=", "True", "return", "SASstat", "(", "self", ")" ]
This methods creates a SASstat object which you can use to run various analytics. See the sasstat.py module. :return: sasstat object
[ "This", "methods", "creates", "a", "SASstat", "object", "which", "you", "can", "use", "to", "run", "various", "analytics", ".", "See", "the", "sasstat", ".", "py", "module", "." ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L562-L573
228,086
sassoftware/saspy
saspy/sasbase.py
SASsession.sasml
def sasml(self) -> 'SASml': """ This methods creates a SASML object which you can use to run various analytics. See the sasml.py module. :return: sasml object """ if not self._loaded_macros: self._loadmacros() self._loaded_macros = True return SASml(self)
python
def sasml(self) -> 'SASml': """ This methods creates a SASML object which you can use to run various analytics. See the sasml.py module. :return: sasml object """ if not self._loaded_macros: self._loadmacros() self._loaded_macros = True return SASml(self)
[ "def", "sasml", "(", "self", ")", "->", "'SASml'", ":", "if", "not", "self", ".", "_loaded_macros", ":", "self", ".", "_loadmacros", "(", ")", "self", ".", "_loaded_macros", "=", "True", "return", "SASml", "(", "self", ")" ]
This methods creates a SASML object which you can use to run various analytics. See the sasml.py module. :return: sasml object
[ "This", "methods", "creates", "a", "SASML", "object", "which", "you", "can", "use", "to", "run", "various", "analytics", ".", "See", "the", "sasml", ".", "py", "module", "." ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L575-L585
228,087
sassoftware/saspy
saspy/sasbase.py
SASsession.sasqc
def sasqc(self) -> 'SASqc': """ This methods creates a SASqc object which you can use to run various analytics. See the sasqc.py module. :return: sasqc object """ if not self._loaded_macros: self._loadmacros() self._loaded_macros = True return SASqc(self)
python
def sasqc(self) -> 'SASqc': """ This methods creates a SASqc object which you can use to run various analytics. See the sasqc.py module. :return: sasqc object """ if not self._loaded_macros: self._loadmacros() self._loaded_macros = True return SASqc(self)
[ "def", "sasqc", "(", "self", ")", "->", "'SASqc'", ":", "if", "not", "self", ".", "_loaded_macros", ":", "self", ".", "_loadmacros", "(", ")", "self", ".", "_loaded_macros", "=", "True", "return", "SASqc", "(", "self", ")" ]
This methods creates a SASqc object which you can use to run various analytics. See the sasqc.py module. :return: sasqc object
[ "This", "methods", "creates", "a", "SASqc", "object", "which", "you", "can", "use", "to", "run", "various", "analytics", ".", "See", "the", "sasqc", ".", "py", "module", "." ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L587-L597
228,088
sassoftware/saspy
saspy/sasbase.py
SASsession.sasutil
def sasutil(self) -> 'SASutil': """ This methods creates a SASutil object which you can use to run various analytics. See the sasutil.py module. :return: sasutil object """ if not self._loaded_macros: self._loadmacros() self._loaded_macros = True return SASutil(self)
python
def sasutil(self) -> 'SASutil': """ This methods creates a SASutil object which you can use to run various analytics. See the sasutil.py module. :return: sasutil object """ if not self._loaded_macros: self._loadmacros() self._loaded_macros = True return SASutil(self)
[ "def", "sasutil", "(", "self", ")", "->", "'SASutil'", ":", "if", "not", "self", ".", "_loaded_macros", ":", "self", ".", "_loadmacros", "(", ")", "self", ".", "_loaded_macros", "=", "True", "return", "SASutil", "(", "self", ")" ]
This methods creates a SASutil object which you can use to run various analytics. See the sasutil.py module. :return: sasutil object
[ "This", "methods", "creates", "a", "SASutil", "object", "which", "you", "can", "use", "to", "run", "various", "analytics", ".", "See", "the", "sasutil", ".", "py", "module", "." ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L599-L610
228,089
sassoftware/saspy
saspy/sasbase.py
SASsession.sasviyaml
def sasviyaml(self) -> 'SASViyaML': """ This methods creates a SASViyaML object which you can use to run various analytics. See the SASViyaML.py module. :return: SASViyaML object """ if not self._loaded_macros: self._loadmacros() self._loaded_macros = True return SASViyaML(self)
python
def sasviyaml(self) -> 'SASViyaML': """ This methods creates a SASViyaML object which you can use to run various analytics. See the SASViyaML.py module. :return: SASViyaML object """ if not self._loaded_macros: self._loadmacros() self._loaded_macros = True return SASViyaML(self)
[ "def", "sasviyaml", "(", "self", ")", "->", "'SASViyaML'", ":", "if", "not", "self", ".", "_loaded_macros", ":", "self", ".", "_loadmacros", "(", ")", "self", ".", "_loaded_macros", "=", "True", "return", "SASViyaML", "(", "self", ")" ]
This methods creates a SASViyaML object which you can use to run various analytics. See the SASViyaML.py module. :return: SASViyaML object
[ "This", "methods", "creates", "a", "SASViyaML", "object", "which", "you", "can", "use", "to", "run", "various", "analytics", ".", "See", "the", "SASViyaML", ".", "py", "module", "." ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L612-L623
228,090
sassoftware/saspy
saspy/sasbase.py
SASsession._loadmacros
def _loadmacros(self): """ Load the SAS macros at the start of the session :return: """ macro_path = os.path.dirname(os.path.realpath(__file__)) fd = os.open(macro_path + '/' + 'libname_gen.sas', os.O_RDONLY) code = b'options nosource;\n' code += os.read(fd, 32767) code += b'\noptions source;' self._io._asubmit(code.decode(), results='text') os.close(fd)
python
def _loadmacros(self): """ Load the SAS macros at the start of the session :return: """ macro_path = os.path.dirname(os.path.realpath(__file__)) fd = os.open(macro_path + '/' + 'libname_gen.sas', os.O_RDONLY) code = b'options nosource;\n' code += os.read(fd, 32767) code += b'\noptions source;' self._io._asubmit(code.decode(), results='text') os.close(fd)
[ "def", "_loadmacros", "(", "self", ")", ":", "macro_path", "=", "os", ".", "path", ".", "dirname", "(", "os", ".", "path", ".", "realpath", "(", "__file__", ")", ")", "fd", "=", "os", ".", "open", "(", "macro_path", "+", "'/'", "+", "'libname_gen.sas'", ",", "os", ".", "O_RDONLY", ")", "code", "=", "b'options nosource;\\n'", "code", "+=", "os", ".", "read", "(", "fd", ",", "32767", ")", "code", "+=", "b'\\noptions source;'", "self", ".", "_io", ".", "_asubmit", "(", "code", ".", "decode", "(", ")", ",", "results", "=", "'text'", ")", "os", ".", "close", "(", "fd", ")" ]
Load the SAS macros at the start of the session :return:
[ "Load", "the", "SAS", "macros", "at", "the", "start", "of", "the", "session" ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L625-L638
228,091
sassoftware/saspy
saspy/sasbase.py
SASsession.sasdata
def sasdata(self, table: str, libref: str = '', results: str = '', dsopts: dict = None) -> 'SASdata': """ Method to define an existing SAS dataset so that it can be accessed via SASPy :param table: the name of the SAS Data Set :param libref: the libref for the Data Set, defaults to WORK, or USER if assigned :param results: format of results, SASsession.results is default, Pandas, HTML and TEXT are the valid options :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :return: SASdata object """ dsopts = dsopts if dsopts is not None else {} if results == '': results = self.results sd = SASdata(self, libref, table, results, dsopts) if not self.exist(sd.table, sd.libref): if not self.batch: print( "Table " + sd.libref + '.' + sd.table + " does not exist. This SASdata object will not be useful until the data set is created.") return sd
python
def sasdata(self, table: str, libref: str = '', results: str = '', dsopts: dict = None) -> 'SASdata': """ Method to define an existing SAS dataset so that it can be accessed via SASPy :param table: the name of the SAS Data Set :param libref: the libref for the Data Set, defaults to WORK, or USER if assigned :param results: format of results, SASsession.results is default, Pandas, HTML and TEXT are the valid options :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :return: SASdata object """ dsopts = dsopts if dsopts is not None else {} if results == '': results = self.results sd = SASdata(self, libref, table, results, dsopts) if not self.exist(sd.table, sd.libref): if not self.batch: print( "Table " + sd.libref + '.' + sd.table + " does not exist. This SASdata object will not be useful until the data set is created.") return sd
[ "def", "sasdata", "(", "self", ",", "table", ":", "str", ",", "libref", ":", "str", "=", "''", ",", "results", ":", "str", "=", "''", ",", "dsopts", ":", "dict", "=", "None", ")", "->", "'SASdata'", ":", "dsopts", "=", "dsopts", "if", "dsopts", "is", "not", "None", "else", "{", "}", "if", "results", "==", "''", ":", "results", "=", "self", ".", "results", "sd", "=", "SASdata", "(", "self", ",", "libref", ",", "table", ",", "results", ",", "dsopts", ")", "if", "not", "self", ".", "exist", "(", "sd", ".", "table", ",", "sd", ".", "libref", ")", ":", "if", "not", "self", ".", "batch", ":", "print", "(", "\"Table \"", "+", "sd", ".", "libref", "+", "'.'", "+", "sd", ".", "table", "+", "\" does not exist. This SASdata object will not be useful until the data set is created.\"", ")", "return", "sd" ]
Method to define an existing SAS dataset so that it can be accessed via SASPy :param table: the name of the SAS Data Set :param libref: the libref for the Data Set, defaults to WORK, or USER if assigned :param results: format of results, SASsession.results is default, Pandas, HTML and TEXT are the valid options :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :return: SASdata object
[ "Method", "to", "define", "an", "existing", "SAS", "dataset", "so", "that", "it", "can", "be", "accessed", "via", "SASPy" ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L640-L677
228,092
sassoftware/saspy
saspy/sasbase.py
SASsession.datasets
def datasets(self, libref: str = '') -> str: """ This method is used to query a libref. The results show information about the libref including members. :param libref: the libref to query :return: """ code = "proc datasets" if libref: code += " dd=" + libref code += "; quit;" if self.nosub: print(code) else: if self.results.lower() == 'html': ll = self._io.submit(code, "html") if not self.batch: self.DISPLAY(self.HTML(ll['LST'])) else: return ll else: ll = self._io.submit(code, "text") if self.batch: return ll['LOG'].rsplit(";*\';*\";*/;\n")[0] else: print(ll['LOG'].rsplit(";*\';*\";*/;\n")[0])
python
def datasets(self, libref: str = '') -> str: """ This method is used to query a libref. The results show information about the libref including members. :param libref: the libref to query :return: """ code = "proc datasets" if libref: code += " dd=" + libref code += "; quit;" if self.nosub: print(code) else: if self.results.lower() == 'html': ll = self._io.submit(code, "html") if not self.batch: self.DISPLAY(self.HTML(ll['LST'])) else: return ll else: ll = self._io.submit(code, "text") if self.batch: return ll['LOG'].rsplit(";*\';*\";*/;\n")[0] else: print(ll['LOG'].rsplit(";*\';*\";*/;\n")[0])
[ "def", "datasets", "(", "self", ",", "libref", ":", "str", "=", "''", ")", "->", "str", ":", "code", "=", "\"proc datasets\"", "if", "libref", ":", "code", "+=", "\" dd=\"", "+", "libref", "code", "+=", "\"; quit;\"", "if", "self", ".", "nosub", ":", "print", "(", "code", ")", "else", ":", "if", "self", ".", "results", ".", "lower", "(", ")", "==", "'html'", ":", "ll", "=", "self", ".", "_io", ".", "submit", "(", "code", ",", "\"html\"", ")", "if", "not", "self", ".", "batch", ":", "self", ".", "DISPLAY", "(", "self", ".", "HTML", "(", "ll", "[", "'LST'", "]", ")", ")", "else", ":", "return", "ll", "else", ":", "ll", "=", "self", ".", "_io", ".", "submit", "(", "code", ",", "\"text\"", ")", "if", "self", ".", "batch", ":", "return", "ll", "[", "'LOG'", "]", ".", "rsplit", "(", "\";*\\';*\\\";*/;\\n\"", ")", "[", "0", "]", "else", ":", "print", "(", "ll", "[", "'LOG'", "]", ".", "rsplit", "(", "\";*\\';*\\\";*/;\\n\"", ")", "[", "0", "]", ")" ]
This method is used to query a libref. The results show information about the libref including members. :param libref: the libref to query :return:
[ "This", "method", "is", "used", "to", "query", "a", "libref", ".", "The", "results", "show", "information", "about", "the", "libref", "including", "members", "." ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L705-L731
228,093
sassoftware/saspy
saspy/sasbase.py
SASsession.upload
def upload(self, localfile: str, remotefile: str, overwrite: bool = True, permission: str = '', **kwargs): """ This method uploads a local file to the SAS servers file system. :param localfile: path to the local file :param remotefile: path to remote file to create or overwrite :param overwrite: overwrite the output file if it exists? :param permission: permissions to set on the new file. See SAS Filename Statement Doc for syntax :return: SAS Log """ if self.nosub: print("too complicated to show the code, read the source :), sorry.") return None else: log = self._io.upload(localfile, remotefile, overwrite, permission, **kwargs) return log
python
def upload(self, localfile: str, remotefile: str, overwrite: bool = True, permission: str = '', **kwargs): """ This method uploads a local file to the SAS servers file system. :param localfile: path to the local file :param remotefile: path to remote file to create or overwrite :param overwrite: overwrite the output file if it exists? :param permission: permissions to set on the new file. See SAS Filename Statement Doc for syntax :return: SAS Log """ if self.nosub: print("too complicated to show the code, read the source :), sorry.") return None else: log = self._io.upload(localfile, remotefile, overwrite, permission, **kwargs) return log
[ "def", "upload", "(", "self", ",", "localfile", ":", "str", ",", "remotefile", ":", "str", ",", "overwrite", ":", "bool", "=", "True", ",", "permission", ":", "str", "=", "''", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "nosub", ":", "print", "(", "\"too complicated to show the code, read the source :), sorry.\"", ")", "return", "None", "else", ":", "log", "=", "self", ".", "_io", ".", "upload", "(", "localfile", ",", "remotefile", ",", "overwrite", ",", "permission", ",", "*", "*", "kwargs", ")", "return", "log" ]
This method uploads a local file to the SAS servers file system. :param localfile: path to the local file :param remotefile: path to remote file to create or overwrite :param overwrite: overwrite the output file if it exists? :param permission: permissions to set on the new file. See SAS Filename Statement Doc for syntax :return: SAS Log
[ "This", "method", "uploads", "a", "local", "file", "to", "the", "SAS", "servers", "file", "system", "." ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L792-L808
228,094
sassoftware/saspy
saspy/sasbase.py
SASsession.df2sd
def df2sd(self, df: 'pd.DataFrame', table: str = '_df', libref: str = '', results: str = '', keep_outer_quotes: bool = False) -> 'SASdata': """ This is an alias for 'dataframe2sasdata'. Why type all that? :param df: :class:`pandas.DataFrame` Pandas Data Frame to import to a SAS Data Set :param table: the name of the SAS Data Set to create :param libref: the libref for the SAS Data Set being created. Defaults to WORK, or USER if assigned :param results: format of results, SASsession.results is default, PANDAS, HTML or TEXT are the alternatives :param keep_outer_quotes: the defualt is for SAS to strip outer quotes from delimitted data. This lets you keep them :return: SASdata object """ return self.dataframe2sasdata(df, table, libref, results, keep_outer_quotes)
python
def df2sd(self, df: 'pd.DataFrame', table: str = '_df', libref: str = '', results: str = '', keep_outer_quotes: bool = False) -> 'SASdata': """ This is an alias for 'dataframe2sasdata'. Why type all that? :param df: :class:`pandas.DataFrame` Pandas Data Frame to import to a SAS Data Set :param table: the name of the SAS Data Set to create :param libref: the libref for the SAS Data Set being created. Defaults to WORK, or USER if assigned :param results: format of results, SASsession.results is default, PANDAS, HTML or TEXT are the alternatives :param keep_outer_quotes: the defualt is for SAS to strip outer quotes from delimitted data. This lets you keep them :return: SASdata object """ return self.dataframe2sasdata(df, table, libref, results, keep_outer_quotes)
[ "def", "df2sd", "(", "self", ",", "df", ":", "'pd.DataFrame'", ",", "table", ":", "str", "=", "'_df'", ",", "libref", ":", "str", "=", "''", ",", "results", ":", "str", "=", "''", ",", "keep_outer_quotes", ":", "bool", "=", "False", ")", "->", "'SASdata'", ":", "return", "self", ".", "dataframe2sasdata", "(", "df", ",", "table", ",", "libref", ",", "results", ",", "keep_outer_quotes", ")" ]
This is an alias for 'dataframe2sasdata'. Why type all that? :param df: :class:`pandas.DataFrame` Pandas Data Frame to import to a SAS Data Set :param table: the name of the SAS Data Set to create :param libref: the libref for the SAS Data Set being created. Defaults to WORK, or USER if assigned :param results: format of results, SASsession.results is default, PANDAS, HTML or TEXT are the alternatives :param keep_outer_quotes: the defualt is for SAS to strip outer quotes from delimitted data. This lets you keep them :return: SASdata object
[ "This", "is", "an", "alias", "for", "dataframe2sasdata", ".", "Why", "type", "all", "that?" ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L827-L839
228,095
sassoftware/saspy
saspy/sasbase.py
SASsession.dataframe2sasdata
def dataframe2sasdata(self, df: 'pd.DataFrame', table: str = '_df', libref: str = '', results: str = '', keep_outer_quotes: bool = False) -> 'SASdata': """ This method imports a Pandas Data Frame to a SAS Data Set, returning the SASdata object for the new Data Set. :param df: Pandas Data Frame to import to a SAS Data Set :param table: the name of the SAS Data Set to create :param libref: the libref for the SAS Data Set being created. Defaults to WORK, or USER if assigned :param results: format of results, SASsession.results is default, PANDAS, HTML or TEXT are the alternatives :param keep_outer_quotes: the defualt is for SAS to strip outer quotes from delimitted data. This lets you keep them :return: SASdata object """ if libref != '': if libref.upper() not in self.assigned_librefs(): print("The libref specified is not assigned in this SAS Session.") return None if results == '': results = self.results if self.nosub: print("too complicated to show the code, read the source :), sorry.") return None else: self._io.dataframe2sasdata(df, table, libref, keep_outer_quotes) if self.exist(table, libref): return SASdata(self, libref, table, results) else: return None
python
def dataframe2sasdata(self, df: 'pd.DataFrame', table: str = '_df', libref: str = '', results: str = '', keep_outer_quotes: bool = False) -> 'SASdata': """ This method imports a Pandas Data Frame to a SAS Data Set, returning the SASdata object for the new Data Set. :param df: Pandas Data Frame to import to a SAS Data Set :param table: the name of the SAS Data Set to create :param libref: the libref for the SAS Data Set being created. Defaults to WORK, or USER if assigned :param results: format of results, SASsession.results is default, PANDAS, HTML or TEXT are the alternatives :param keep_outer_quotes: the defualt is for SAS to strip outer quotes from delimitted data. This lets you keep them :return: SASdata object """ if libref != '': if libref.upper() not in self.assigned_librefs(): print("The libref specified is not assigned in this SAS Session.") return None if results == '': results = self.results if self.nosub: print("too complicated to show the code, read the source :), sorry.") return None else: self._io.dataframe2sasdata(df, table, libref, keep_outer_quotes) if self.exist(table, libref): return SASdata(self, libref, table, results) else: return None
[ "def", "dataframe2sasdata", "(", "self", ",", "df", ":", "'pd.DataFrame'", ",", "table", ":", "str", "=", "'_df'", ",", "libref", ":", "str", "=", "''", ",", "results", ":", "str", "=", "''", ",", "keep_outer_quotes", ":", "bool", "=", "False", ")", "->", "'SASdata'", ":", "if", "libref", "!=", "''", ":", "if", "libref", ".", "upper", "(", ")", "not", "in", "self", ".", "assigned_librefs", "(", ")", ":", "print", "(", "\"The libref specified is not assigned in this SAS Session.\"", ")", "return", "None", "if", "results", "==", "''", ":", "results", "=", "self", ".", "results", "if", "self", ".", "nosub", ":", "print", "(", "\"too complicated to show the code, read the source :), sorry.\"", ")", "return", "None", "else", ":", "self", ".", "_io", ".", "dataframe2sasdata", "(", "df", ",", "table", ",", "libref", ",", "keep_outer_quotes", ")", "if", "self", ".", "exist", "(", "table", ",", "libref", ")", ":", "return", "SASdata", "(", "self", ",", "libref", ",", "table", ",", "results", ")", "else", ":", "return", "None" ]
This method imports a Pandas Data Frame to a SAS Data Set, returning the SASdata object for the new Data Set. :param df: Pandas Data Frame to import to a SAS Data Set :param table: the name of the SAS Data Set to create :param libref: the libref for the SAS Data Set being created. Defaults to WORK, or USER if assigned :param results: format of results, SASsession.results is default, PANDAS, HTML or TEXT are the alternatives :param keep_outer_quotes: the defualt is for SAS to strip outer quotes from delimitted data. This lets you keep them :return: SASdata object
[ "This", "method", "imports", "a", "Pandas", "Data", "Frame", "to", "a", "SAS", "Data", "Set", "returning", "the", "SASdata", "object", "for", "the", "new", "Data", "Set", "." ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L841-L869
228,096
sassoftware/saspy
saspy/sasbase.py
SASsession.sd2df
def sd2df(self, table: str, libref: str = '', dsopts: dict = None, method: str = 'MEMORY', **kwargs) -> 'pd.DataFrame': """ This is an alias for 'sasdata2dataframe'. Why type all that? SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame :param table: the name of the SAS Data Set you want to export to a Pandas Data Frame :param libref: the libref for the SAS Data Set. :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :param method: defaults to MEMORY; the original method. CSV is the other choice which uses an intermediary csv file; faster for large data :param kwargs: dictionary :return: Pandas data frame """ dsopts = dsopts if dsopts is not None else {} return self.sasdata2dataframe(table, libref, dsopts, method, **kwargs)
python
def sd2df(self, table: str, libref: str = '', dsopts: dict = None, method: str = 'MEMORY', **kwargs) -> 'pd.DataFrame': """ This is an alias for 'sasdata2dataframe'. Why type all that? SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame :param table: the name of the SAS Data Set you want to export to a Pandas Data Frame :param libref: the libref for the SAS Data Set. :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :param method: defaults to MEMORY; the original method. CSV is the other choice which uses an intermediary csv file; faster for large data :param kwargs: dictionary :return: Pandas data frame """ dsopts = dsopts if dsopts is not None else {} return self.sasdata2dataframe(table, libref, dsopts, method, **kwargs)
[ "def", "sd2df", "(", "self", ",", "table", ":", "str", ",", "libref", ":", "str", "=", "''", ",", "dsopts", ":", "dict", "=", "None", ",", "method", ":", "str", "=", "'MEMORY'", ",", "*", "*", "kwargs", ")", "->", "'pd.DataFrame'", ":", "dsopts", "=", "dsopts", "if", "dsopts", "is", "not", "None", "else", "{", "}", "return", "self", ".", "sasdata2dataframe", "(", "table", ",", "libref", ",", "dsopts", ",", "method", ",", "*", "*", "kwargs", ")" ]
This is an alias for 'sasdata2dataframe'. Why type all that? SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame :param table: the name of the SAS Data Set you want to export to a Pandas Data Frame :param libref: the libref for the SAS Data Set. :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :param method: defaults to MEMORY; the original method. CSV is the other choice which uses an intermediary csv file; faster for large data :param kwargs: dictionary :return: Pandas data frame
[ "This", "is", "an", "alias", "for", "sasdata2dataframe", ".", "Why", "type", "all", "that?", "SASdata", "object", "that", "refers", "to", "the", "Sas", "Data", "Set", "you", "want", "to", "export", "to", "a", "Pandas", "Data", "Frame" ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L871-L902
228,097
sassoftware/saspy
saspy/sasbase.py
SASsession.sd2df_CSV
def sd2df_CSV(self, table: str, libref: str = '', dsopts: dict = None, tempfile: str = None, tempkeep: bool = False, **kwargs) -> 'pd.DataFrame': """ This is an alias for 'sasdata2dataframe' specifying method='CSV'. Why type all that? SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame :param table: the name of the SAS Data Set you want to export to a Pandas Data Frame :param libref: the libref for the SAS Data Set. :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :param tempfile: [optional] an OS path for a file to use for the local CSV file; default it a temporary file that's cleaned up :param tempkeep: if you specify your own file to use with tempfile=, this controls whether it's cleaned up after using it :param kwargs: dictionary :return: Pandas data frame """ dsopts = dsopts if dsopts is not None else {} return self.sasdata2dataframe(table, libref, dsopts, method='CSV', tempfile=tempfile, tempkeep=tempkeep, **kwargs)
python
def sd2df_CSV(self, table: str, libref: str = '', dsopts: dict = None, tempfile: str = None, tempkeep: bool = False, **kwargs) -> 'pd.DataFrame': """ This is an alias for 'sasdata2dataframe' specifying method='CSV'. Why type all that? SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame :param table: the name of the SAS Data Set you want to export to a Pandas Data Frame :param libref: the libref for the SAS Data Set. :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :param tempfile: [optional] an OS path for a file to use for the local CSV file; default it a temporary file that's cleaned up :param tempkeep: if you specify your own file to use with tempfile=, this controls whether it's cleaned up after using it :param kwargs: dictionary :return: Pandas data frame """ dsopts = dsopts if dsopts is not None else {} return self.sasdata2dataframe(table, libref, dsopts, method='CSV', tempfile=tempfile, tempkeep=tempkeep, **kwargs)
[ "def", "sd2df_CSV", "(", "self", ",", "table", ":", "str", ",", "libref", ":", "str", "=", "''", ",", "dsopts", ":", "dict", "=", "None", ",", "tempfile", ":", "str", "=", "None", ",", "tempkeep", ":", "bool", "=", "False", ",", "*", "*", "kwargs", ")", "->", "'pd.DataFrame'", ":", "dsopts", "=", "dsopts", "if", "dsopts", "is", "not", "None", "else", "{", "}", "return", "self", ".", "sasdata2dataframe", "(", "table", ",", "libref", ",", "dsopts", ",", "method", "=", "'CSV'", ",", "tempfile", "=", "tempfile", ",", "tempkeep", "=", "tempkeep", ",", "*", "*", "kwargs", ")" ]
This is an alias for 'sasdata2dataframe' specifying method='CSV'. Why type all that? SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame :param table: the name of the SAS Data Set you want to export to a Pandas Data Frame :param libref: the libref for the SAS Data Set. :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :param tempfile: [optional] an OS path for a file to use for the local CSV file; default it a temporary file that's cleaned up :param tempkeep: if you specify your own file to use with tempfile=, this controls whether it's cleaned up after using it :param kwargs: dictionary :return: Pandas data frame
[ "This", "is", "an", "alias", "for", "sasdata2dataframe", "specifying", "method", "=", "CSV", ".", "Why", "type", "all", "that?", "SASdata", "object", "that", "refers", "to", "the", "Sas", "Data", "Set", "you", "want", "to", "export", "to", "a", "Pandas", "Data", "Frame" ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L904-L937
228,098
sassoftware/saspy
saspy/sasbase.py
SASsession.sasdata2dataframe
def sasdata2dataframe(self, table: str, libref: str = '', dsopts: dict = None, method: str = 'MEMORY', **kwargs) -> 'pd.DataFrame': """ This method exports the SAS Data Set to a Pandas Data Frame, returning the Data Frame object. SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame :param table: the name of the SAS Data Set you want to export to a Pandas Data Frame :param libref: the libref for the SAS Data Set. :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :param method: defaults to MEMORY; the original method. CSV is the other choice which uses an intermediary csv file; faster for large data :param kwargs: dictionary :return: Pandas data frame """ dsopts = dsopts if dsopts is not None else {} if self.exist(table, libref) == 0: print('The SAS Data Set ' + libref + '.' + table + ' does not exist') return None if self.nosub: print("too complicated to show the code, read the source :), sorry.") return None else: return self._io.sasdata2dataframe(table, libref, dsopts, method=method, **kwargs)
python
def sasdata2dataframe(self, table: str, libref: str = '', dsopts: dict = None, method: str = 'MEMORY', **kwargs) -> 'pd.DataFrame': """ This method exports the SAS Data Set to a Pandas Data Frame, returning the Data Frame object. SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame :param table: the name of the SAS Data Set you want to export to a Pandas Data Frame :param libref: the libref for the SAS Data Set. :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :param method: defaults to MEMORY; the original method. CSV is the other choice which uses an intermediary csv file; faster for large data :param kwargs: dictionary :return: Pandas data frame """ dsopts = dsopts if dsopts is not None else {} if self.exist(table, libref) == 0: print('The SAS Data Set ' + libref + '.' + table + ' does not exist') return None if self.nosub: print("too complicated to show the code, read the source :), sorry.") return None else: return self._io.sasdata2dataframe(table, libref, dsopts, method=method, **kwargs)
[ "def", "sasdata2dataframe", "(", "self", ",", "table", ":", "str", ",", "libref", ":", "str", "=", "''", ",", "dsopts", ":", "dict", "=", "None", ",", "method", ":", "str", "=", "'MEMORY'", ",", "*", "*", "kwargs", ")", "->", "'pd.DataFrame'", ":", "dsopts", "=", "dsopts", "if", "dsopts", "is", "not", "None", "else", "{", "}", "if", "self", ".", "exist", "(", "table", ",", "libref", ")", "==", "0", ":", "print", "(", "'The SAS Data Set '", "+", "libref", "+", "'.'", "+", "table", "+", "' does not exist'", ")", "return", "None", "if", "self", ".", "nosub", ":", "print", "(", "\"too complicated to show the code, read the source :), sorry.\"", ")", "return", "None", "else", ":", "return", "self", ".", "_io", ".", "sasdata2dataframe", "(", "table", ",", "libref", ",", "dsopts", ",", "method", "=", "method", ",", "*", "*", "kwargs", ")" ]
This method exports the SAS Data Set to a Pandas Data Frame, returning the Data Frame object. SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame :param table: the name of the SAS Data Set you want to export to a Pandas Data Frame :param libref: the libref for the SAS Data Set. :param dsopts: a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs): - where is a string - keep are strings or list of strings. - drop are strings or list of strings. - obs is a numbers - either string or int - first obs is a numbers - either string or int - format is a string or dictionary { var: format } .. code-block:: python {'where' : 'msrp < 20000 and make = "Ford"' 'keep' : 'msrp enginesize Cylinders Horsepower Weight' 'drop' : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight'] 'obs' : 10 'firstobs' : '12' 'format' : {'money': 'dollar10', 'time': 'tod5.'} } :param method: defaults to MEMORY; the original method. CSV is the other choice which uses an intermediary csv file; faster for large data :param kwargs: dictionary :return: Pandas data frame
[ "This", "method", "exports", "the", "SAS", "Data", "Set", "to", "a", "Pandas", "Data", "Frame", "returning", "the", "Data", "Frame", "object", ".", "SASdata", "object", "that", "refers", "to", "the", "Sas", "Data", "Set", "you", "want", "to", "export", "to", "a", "Pandas", "Data", "Frame" ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L939-L979
228,099
sassoftware/saspy
saspy/sasbase.py
SASsession.disconnect
def disconnect(self): """ This method disconnects an IOM session to allow for reconnecting when switching networks See the Advanced topics section of the doc for details """ if self.sascfg.mode != 'IOM': res = "This method is only available with the IOM access method" else: res = self._io.disconnect() return res
python
def disconnect(self): """ This method disconnects an IOM session to allow for reconnecting when switching networks See the Advanced topics section of the doc for details """ if self.sascfg.mode != 'IOM': res = "This method is only available with the IOM access method" else: res = self._io.disconnect() return res
[ "def", "disconnect", "(", "self", ")", ":", "if", "self", ".", "sascfg", ".", "mode", "!=", "'IOM'", ":", "res", "=", "\"This method is only available with the IOM access method\"", "else", ":", "res", "=", "self", ".", "_io", ".", "disconnect", "(", ")", "return", "res" ]
This method disconnects an IOM session to allow for reconnecting when switching networks See the Advanced topics section of the doc for details
[ "This", "method", "disconnects", "an", "IOM", "session", "to", "allow", "for", "reconnecting", "when", "switching", "networks", "See", "the", "Advanced", "topics", "section", "of", "the", "doc", "for", "details" ]
e433f71990f249d3a6c3db323ceb11cb2d462cf9
https://github.com/sassoftware/saspy/blob/e433f71990f249d3a6c3db323ceb11cb2d462cf9/saspy/sasbase.py#L1159-L1168