本文整理匯總了Python中exrex.getone方法的典型用法代碼示例。如果您正苦於以下問題:Python exrex.getone方法的具體用法?Python exrex.getone怎麽用?Python exrex.getone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類exrex
的用法示例。
在下文中一共展示了exrex.getone方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: regex_to_str
# 需要導入模塊: import exrex [as 別名]
# 或者: from exrex import getone [as 別名]
def regex_to_str(self, all_combo: bool = False):
"""Convert a regex to a matching string
Args:
all_combo (bool, optional): Generate all combos that match regex. Defaults to False.
Returns:
Chepy: The Chepy object.
"""
if all_combo:
self.state = list(exrex.generate(self._convert_to_str()))
else:
self.state = exrex.getone(self._convert_to_str())
return self
示例2: get_random
# 需要導入模塊: import exrex [as 別名]
# 或者: from exrex import getone [as 別名]
def get_random(self):
"""Returns a random string matching the regex"""
return exrex.getone(self.options['regex'])
示例3: get_random_list
# 需要導入模塊: import exrex [as 別名]
# 或者: from exrex import getone [as 別名]
def get_random_list(self, num_values):
"""Returns a list of num_values random strings matching regex; note that matches may be repeated"""
return [exrex.getone(self.options['regex']) for _ in range(num_values)]
示例4: generate_random_format_string
# 需要導入模塊: import exrex [as 別名]
# 或者: from exrex import getone [as 別名]
def generate_random_format_string(format_string):
try:
return getone(format_string)
except Exception as e:
print(e)
return ""
示例5: _generate_fake_users
# 需要導入模塊: import exrex [as 別名]
# 或者: from exrex import getone [as 別名]
def _generate_fake_users(self):
FAKER = Faker('it_IT')
_users = {}
for idx, _ in enumerate(range(10)):
_is_even = (idx % 2 == 0)
name = FAKER.first_name_male() if _is_even \
else FAKER.first_name_female()
lastname = FAKER.last_name_male() if _is_even \
else FAKER.last_name_female()
fiscal_number = exrex.getone(
r'[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]'
)
spid_code = 'TENV{}'.format(
FAKER.lexify('??????????', string.ascii_letters + string.digits)
)
_users[FAKER.user_name() if idx > 0 else 'test'] = {
'attrs': {
'spidCode': spid_code,
'name': name,
'familyName': lastname,
'gender': 'M' if _is_even else 'F',
'dateOfBirth': FAKER.date(),
'companyName': FAKER.company(),
'registeredOffice': FAKER.address(),
'fiscalNumber': 'TINIT-{}'.format(fiscal_number),
'email': FAKER.email()
},
'pwd': 'test',
'sp': None
}
return _users
示例6: createUsername
# 需要導入模塊: import exrex [as 別名]
# 或者: from exrex import getone [as 別名]
def createUsername():
return exrex.getone('[a-zA-Z]{1}[a-zA-Z0-9._\-]{1,}')