本文整理汇总了Python中string.uppercase方法的典型用法代码示例。如果您正苦于以下问题:Python string.uppercase方法的具体用法?Python string.uppercase怎么用?Python string.uppercase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string
的用法示例。
在下文中一共展示了string.uppercase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getLogLineBNF
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def getLogLineBNF():
global logLineBNF
if logLineBNF is None:
integer = Word( nums )
ipAddress = delimitedList( integer, ".", combine=True )
timeZoneOffset = Word("+-",nums)
month = Word(string.uppercase, string.lowercase, exact=3)
serverDateTime = Group( Suppress("[") +
Combine( integer + "/" + month + "/" + integer +
":" + integer + ":" + integer + ":" + integer ) +
timeZoneOffset +
Suppress("]") )
logLineBNF = ( ipAddress.setResultsName("ipAddr") +
Suppress("-") +
("-" | Word( alphas+nums+"@._" )).setResultsName("auth") +
serverDateTime.setResultsName("timestamp") +
dblQuotedString.setResultsName("cmd").setParseAction(getCmdFields) +
(integer | "-").setResultsName("statusCode") +
(integer | "-").setResultsName("numBytesSent") +
dblQuotedString.setResultsName("referrer").setParseAction(removeQuotes) +
dblQuotedString.setResultsName("clientSfw").setParseAction(removeQuotes) )
return logLineBNF
示例2: increment
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def increment(s):
if not s:
return '1'
for sequence in string.digits, string.lowercase, string.uppercase:
lastc = s[-1]
if lastc in sequence:
i = sequence.index(lastc) + 1
if i >= len(sequence):
if len(s) == 1:
s = sequence[0]*2
if s == '00':
s = '10'
else:
s = increment(s[:-1]) + sequence[0]
else:
s = s[:-1] + sequence[i]
return s
return s # Don't increment
示例3: to_upper
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def to_upper(string):
""":yaql:toUpper
Returns a string with all case-based characters uppercase.
:signature: string.toUpper()
:receiverArg string: value to uppercase
:argType string: string
:returnType: string
.. code::
yaql> "aB1c".toUpper()
"AB1C"
"""
return string.upper()
示例4: pattern_gen
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def pattern_gen(length):
"""
Generate a pattern of a given length up to a maximum
of 20280 - after this the pattern would repeat
"""
if length >= MAX_PATTERN_LENGTH:
print 'ERROR: Pattern length exceeds maximum of %d' % MAX_PATTERN_LENGTH
sys.exit(1)
pattern = ''
for upper in uppercase:
for lower in lowercase:
for digit in digits:
if len(pattern) < length:
pattern += upper+lower+digit
else:
out = pattern[:length]
print out
return
示例5: main
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def main(argv):
if (len(sys.argv) != 5):
sys.exit('Usage: simple_pass.py <upper_case> <lower_case> <digit> <special_characters>')
password = ''
for i in range(len(argv)):
for j in range(int(argv[i])):
if i == 0:
password += string.uppercase[random.randint(0,len(string.uppercase)-1)]
elif i == 1:
password += string.lowercase[random.randint(0,len(string.lowercase)-1)]
elif i == 2:
password += string.digits[random.randint(0,len(string.digits)-1)]
elif i == 3:
password += string.punctuation[random.randint(0,len(string.punctuation)-1)]
print 'You new password is: ' + ''.join(random.sample(password,len(password)))
示例6: int_to_alphabetic
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def int_to_alphabetic(number):
"""Convert non-negative integer to base 26 representation using uppercase A-Z
as symbols. Can use this instead of numbers in feature delimiters because:
-- gives shorter full context model names (esp. with many features)
-- trivially, split-context-balanced.py expects delimiters to contain no digits
"""
assert number >= 0,"Function not intended to handle negative input values"
if number == 0:
return string.uppercase[0]
alphabetic = ""
current = number
while current!=0:
remainder = current % 26
remainder_string = string.uppercase[remainder]
alphabetic = remainder_string + alphabetic
current = current / 26
return alphabetic
示例7: encode_name
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def encode_name(name, type, scope = None):
"""
Perform first and second level encoding of name as specified in RFC 1001 (Section 4)
"""
if name == '*':
name = name + '\0' * 15
elif len(name) > 15:
name = name[:15] + chr(type)
else:
name = string.ljust(name, 15) + chr(type)
def _do_first_level_encoding(m):
s = ord(m.group(0))
return string.uppercase[s >> 4] + string.uppercase[s & 0x0f]
encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
if scope:
encoded_scope = ''
for s in string.split(scope, '.'):
encoded_scope = encoded_scope + chr(len(s)) + s
return encoded_name + encoded_scope + '\0'
else:
return encoded_name + '\0'
示例8: write_file
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def write_file(path, capacity):
"""write test data to file
"""
logger.info("write %s data into file %s" % (capacity, path))
out = utils.get_capacity_suffix_size(capacity)
f = open(path, 'w')
if sys.version_info[0] < 3:
datastr = ''.join(string.lowercase + string.uppercase +
string.digits + '.' + '\n')
else:
datastr = ''.join(string.ascii_lowercase + string.ascii_uppercase +
string.digits + '.' + '\n')
repeat = int(out['capacity_byte'] / 64)
data = ''.join(repeat * datastr)
f.write(data)
f.close()
示例9: create_valid_password
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def create_valid_password(password_policy):
symbols = '!@#$%^&*()_+=-\][{}|;:",./?><`~'
password = ''.join(choice(string.ascii_lowercase) for _ in range(3))
try:
if password_policy['RequireNumbers'] is True:
password += ''.join(choice(string.digits) for _ in range(3))
if password_policy['RequireSymbols'] is True:
password += ''.join(choice(symbols) for _ in range(3))
if password_policy['RequireUppercaseCharacters'] is True:
password += ''.join(choice(string.uppercase) for _ in range(3))
if password_policy['MinimumPasswordLength'] > 0:
while len(password) < password_policy['MinimumPasswordLength']:
password += choice(string.digits)
except:
# Password policy couldn't be grabbed for some reason, make a max-length
# password with all types of characters, so no matter what, it will be accepted.
characters = string.ascii_lowercase + string.ascii_uppercase + string.digits + symbols
password = ''.join(choice(characters) for _ in range(128))
return password
示例10: computeSize
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def computeSize(self, *args):
barWidth = self.barWidth
oa, oA = ord('a') - 1, ord('A') - 1
w = 0.0
for c in self.decomposed:
oc = ord(c)
if c in string.lowercase:
w = w + barWidth * (oc - oa)
elif c in string.uppercase:
w = w + barWidth * (oc - oA)
if self.barHeight is None:
self.barHeight = w * 0.15
self.barHeight = max(0.25 * inch, self.barHeight)
if self.quiet:
w += self.lquiet + self.rquiet
self._height = self.barHeight
self._width = w
示例11: _targets_to_annotations
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def _targets_to_annotations(self, targets):
natural = zip([0, 2, 3, 5, 7, 8, 10], string.uppercase[:7])
sharp = map(lambda v: ((v[0] + 1) % 12, v[1] + '#'), natural)
semitone_to_label = dict(sharp + natural + [(12, 'N')])
spf = 1. / self.fps
labels = [(i * spf, semitone_to_label[p])
for i, p in enumerate(targets)]
# join same consequtive predictions
prev_label = (None, None)
uniq_labels = []
for label in labels:
if label[1] != prev_label[1]:
uniq_labels.append(label)
prev_label = label
# end time of last label is one frame duration after
# the last prediction time
start_times, chord_labels = zip(*uniq_labels)
end_times = start_times[1:] + (labels[-1][0] + spf,)
return zip(start_times, end_times, chord_labels)
示例12: _assign_seg_ids
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def _assign_seg_ids(self):
"""
Assign new segment id to each chain.
"""
counter = self.chainIdOffset
for chain in self.chains:
## Assemble segid from pdb code + one letter out of A to Z
chain.segment_id = self.pdbname()[:3] + string.uppercase[counter]
counter = counter + 1
try: # report changed segement ids
chain_id = chain.chain_id
self.log.add("changed segment ID of chain "+chain_id+\
" to "+chain.segment_id)
except:
T.errWriteln("_assign_seg_ids(): logerror")
示例13: validate_username
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def validate_username(cls, username):
""" Returns None if the username is valid and does not exist. """
un = username.lower()
if (un in Config['blocked_usernames']
or any(fragment in un for fragment in Config['blocked_username_fragments'])
or any(fragment in un for fragment in Config['autoflag_words'])):
return "Sorry, this username is not allowed."
if len(un) < 3:
return "Username must be 3 or more characters."
if len(un) > 16:
return "Username must be 16 characters or less."
alphabet = string.lowercase + string.uppercase + string.digits + '_'
if not all(char in alphabet for char in username):
return "Usernames can only contain letters, digits and underscores."
if User.objects.filter(username__iexact=username):
return "This username is taken :("
示例14: validate_username
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def validate_username(cls, username, skip_uniqueness_check=False):
""" Returns None if the username is valid and does not exist. """
un = username.lower()
if (un in Config['blocked_usernames']
or any(fragment in un for fragment in Config['blocked_username_fragments'])
or any(fragment in un for fragment in Config['autoflag_words'])):
return "Sorry, this username is not allowed."
if not un:
return "Please enter a username."
elif len(un) < 3:
return "Username must be 3 or more characters."
elif len(un) > 16:
return "Username must be 16 characters or less."
alphabet = string.lowercase + string.uppercase + string.digits + '_'
if not all(char in alphabet for char in username):
return "Usernames can only contain letters, digits and underscores."
if not skip_uniqueness_check:
if cls.objects.filter(username__iexact=username):
return "Sorry! This username is taken. Please pick a different username."
示例15: _do_first_level_encoding
# 需要导入模块: import string [as 别名]
# 或者: from string import uppercase [as 别名]
def _do_first_level_encoding(m):
s = ord(m.group(0))
return string.uppercase[s >> 4] + string.uppercase[s & 0x0f]