def issn(mask: str = '####-####') -> str: """Generate a random International Standard Serial Number (ISSN). :param str mask: Mask of ISSN. :return: ISSN. """ return custom_code(mask=mask)
def test_custom_code(): result = custom_code(mask='@@@-###-@@@', char='@', digit='#') assert len(result) == 11 a, b, c = result.split('-') assert a.isalpha() assert b.isdigit() assert c.isalpha()
def pin(self, mask: str = '####') -> str: """Generate a random PIN code. :param str mask: Mask of pin code. :return: PIN code. :Example: 5241. """ return custom_code(mask=mask)
def imei(self) -> str: """Generate a random IMEI (International Mobile Station Equipment Identity). :return: IMEI. :Example: 353918052107063 """ num = self.random.choice(IMEI_TACS) + custom_code(mask='######') return num + luhn_checksum(num)
def postal_code(self) -> str: """Generate a postal code for current locale. :return: Postal code. :Example: 389213 """ mask = self.data['postal_code_fmt'] return custom_code(mask=mask)
def airplane(self, model_mask: str = '###') -> str: """Generate a dummy airplane model. :param str model_mask: Mask of truck model. Here '@' is a \ placeholder of characters and '#' is a placeholder of digits. :return: Airplane model. :Example: Boeing 727. """ model = custom_code(mask=model_mask) plane = self.random.choice(AIRPLANES) return '{} {}'.format(plane, model)
def truck(self, model_mask: str = '#### @@') -> str: """Generate a truck model. :param str model_mask: Mask of truck model. Here '@' is a \ placeholder of characters and '#' is a placeholder of digits. :return: Dummy truck model. :Example: Caledon-966O. """ model = custom_code(mask=model_mask) truck = self.random.choice(TRUCKS) return '{}-{}'.format(truck, model)
def identifier(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 str mask: The mask. Here '@' is a placeholder for characters and '#' is placeholder for digits. :return: An identifier. :Example: 07-97/04 """ return custom_code(mask=mask)
def ean(fmt: str = 'ean-13') -> str: """Generate EAN (European Article Number) code. Default is EAN-13, but you also can use EAN-8. :param str fmt: Format of EAN. :return: EAN. :Example: 3953753179567. """ mask = '########' if fmt == 'ean-8' \ else '#############' return custom_code(mask=mask)
def ean(self, fmt: Optional[EANFormat] = None) -> str: """Generate EAN (European Article Number) code. Default is EAN-13, but you also can use EAN-8. :param str fmt: Format of EAN. :return: EAN. :raises NonEnumerableError: if fmt is not enum EANFormat. :Example: 3953753179567. """ key = self._validate_enum( item=fmt, enum=EANFormat, ) mask = EAN_MASKS[key] return custom_code(mask=mask)
def telephone(self, mask: str = '', placeholder: str = '#') -> str: """Generate a random phone number. :param str mask: Mask for formatting number. :param str 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 custom_code(mask=mask, digit=placeholder)
def telephone(self, mask: str = '', placeholder: str = '#') -> str: """Generate a random phone number. :param str mask: Mask for formatting number. :param str placeholder: A placeholder for a mask (default is #). :return: Phone number. :Example: +7-(963)-409-11-22. """ # Default default = '+#-(###)-###-####' if not mask: masks = self.data.get('telephone_fmt', default) mask = self.random.choice(masks) return custom_code(mask=mask, digit=placeholder)
def isbn(self, fmt: Optional[ISBNFormat] = None) -> str: """Generate ISBN for current locale. Default is ISBN 10, but you also can use ISBN-13. :param str fmt: ISBN format. :return: ISBN. :raises NonEnumerableError: if fmt is not enum ISBNFormat. :Example: 132-1-15411-375-8. """ fmt_value = self._validate_enum(item=fmt, enum=ISBNFormat) result = ISBN_MASKS[fmt_value] if self.locale in ISBN_GROUPS: mask = result.format(ISBN_GROUPS[self.locale]) else: mask = result.format(ISBN_GROUPS['default']) return custom_code(mask=mask)
def isbn(self, fmt: str = 'isbn-10') -> str: """Generate ISBN for current locale. Default is ISBN 10, but you also can use ISBN-13. :param str fmt: ISBN format. :return: ISBN. :Example: 132-1-15411-375-8. """ groups = ISBN_GROUPS mask = '###-{0}-#####-###-#' if \ fmt == 'isbn-13' else '{0}-#####-###-#' if self.locale in groups: mask = mask.format(groups[self.locale]) else: mask = mask.format(groups['default']) return custom_code(mask=mask)