Python string.uppercase() Examples

The following are 30 code examples for showing how to use string.uppercase(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module string , or try the search function .

Example 1
Project: phpsploit   Author: nil0x42   File: httpServerLogParser.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 
Example 2
Project: oss-ftp   Author: aliyun   File: texi2html.py    License: MIT License 6 votes vote down vote up
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 
Example 3
Project: yaql   Author: openstack   File: strings.py    License: Apache License 2.0 6 votes vote down vote up
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() 
Example 4
Project: security-scripts   Author: Und3rf10w   File: pattern.py    License: GNU General Public License v2.0 6 votes vote down vote up
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 
Example 5
Project: code   Author: ActiveState   File: recipe-578396.py    License: MIT License 6 votes vote down vote up
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))) 
Example 6
Project: Ossian   Author: CSTR-Edinburgh   File: naive_util.py    License: Apache License 2.0 6 votes vote down vote up
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 
Example 7
Project: addon   Author: alfa-addon   File: utils.py    License: GNU General Public License v3.0 6 votes vote down vote up
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' 
Example 8
Project: libvirt-test-API   Author: libvirt   File: dir_vol_download.py    License: GNU General Public License v2.0 6 votes vote down vote up
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() 
Example 9
Project: pacu   Author: RhinoSecurityLabs   File: main.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example 10
Project: datafari   Author: francelabs   File: texi2html.py    License: Apache License 2.0 6 votes vote down vote up
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 
Example 11
Project: stdm   Author: gltn   File: common.py    License: GNU General Public License v2.0 6 votes vote down vote up
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 
Example 12
Project: chordrec   Author: fdlm   File: targets.py    License: MIT License 6 votes vote down vote up
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) 
Example 13
Project: pelisalacarta-ce   Author: pelisalacarta-ce   File: utils.py    License: GNU General Public License v3.0 6 votes vote down vote up
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' 
Example 14
Project: xunfengES   Author: superhuahua   File: utils.py    License: GNU General Public License v3.0 6 votes vote down vote up
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' 
Example 15
Project: xunfengES   Author: superhuahua   File: utils.py    License: GNU General Public License v3.0 6 votes vote down vote up
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' 
Example 16
Project: biskit   Author: graik   File: ChainSeparator.py    License: GNU General Public License v3.0 6 votes vote down vote up
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") 
Example 17
Project: Carnets   Author: holzschu   File: texi2html.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example 18
Project: canvas   Author: canvasnetworks   File: models.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 :(" 
Example 19
Project: canvas   Author: canvasnetworks   File: models.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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." 
Example 20
Project: CVE-2017-7494   Author: joxeankoret   File: nmb.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _do_first_level_encoding(m):
    s = ord(m.group(0))
    return string.uppercase[s >> 4] + string.uppercase[s & 0x0f] 
Example 21
Project: ironpython2   Author: IronLanguages   File: makegwenum.py    License: Apache License 2.0 5 votes vote down vote up
def is_interface_enum(enumtype):
  return not (enumtype[0] in string.uppercase and enumtype[2] in string.uppercase) 
Example 22
Project: ironpython2   Author: IronLanguages   File: test_string.py    License: Apache License 2.0 5 votes vote down vote up
def test_attrs(self):
        string.whitespace
        string.lowercase
        string.uppercase
        string.letters
        string.digits
        string.hexdigits
        string.octdigits
        string.punctuation
        string.printable 
Example 23
Project: BinderFilter   Author: dxwu   File: test_string.py    License: MIT License 5 votes vote down vote up
def test_attrs(self):
        string.whitespace
        string.lowercase
        string.uppercase
        string.letters
        string.digits
        string.hexdigits
        string.octdigits
        string.punctuation
        string.printable 
Example 24
Project: oss-ftp   Author: aliyun   File: test_string.py    License: MIT License 5 votes vote down vote up
def test_attrs(self):
        string.whitespace
        string.lowercase
        string.uppercase
        string.letters
        string.digits
        string.hexdigits
        string.octdigits
        string.punctuation
        string.printable 
Example 25
Project: cracke-dit   Author: eth0izzle   File: nmb.py    License: MIT License 5 votes vote down vote up
def _do_first_level_encoding(m):
    s = ord(m.group(0))
    return string.uppercase[s >> 4] + string.uppercase[s & 0x0f] 
Example 26
Project: hask   Author: billpmurphy   File: syntax.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __getattr__(self, value):
        if not value[0] in string.uppercase:
            raise SyntaxError("Type constructor name must be capitalized")
        return __new_tcon_enum__(value) 
Example 27
Project: hask   Author: billpmurphy   File: syntax.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __getattr__(self, value):
        if not value[0] in string.uppercase:
            raise SyntaxError("Data constructor name must be capitalized")
        return __new_dcon_enum__(value) 
Example 28
Project: tvalacarta   Author: tvalacarta   File: nmb.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _do_first_level_encoding(m):
    s = ord(m.group(0))
    return string.uppercase[s >> 4] + string.uppercase[s & 0x0f] 
Example 29
Project: MoAL   Author: christabor   File: restful_eve.py    License: Apache License 2.0 5 votes vote down vote up
def _random_robot():
    return {'model': '{}{}-{}'.format(choice(uc), choice(uc), rr(0, 9999))} 
Example 30
Project: script-languages   Author: exasol   File: script_import.py    License: MIT License 5 votes vote down vote up
def test_import_is_semi_case_sensitive(self):
        def check(name, classname, n):
            self.query(udf.fixindent('''
                CREATE OR REPLACE java SCALAR SCRIPT
                foo()
                RETURNS INT AS
                %%import %s;
                class FOO {
                    static int run(ExaMetadata exa, ExaIterator ctx) throws Exception {
                        return %s.f();
                    }
                }
                /''' % (name, classname)))
            self.assertRowsEqual([(n,)],
                self.query('SELECT foo() FROM DUAL'))

        for name in 'bar', 'Bar', 'BAR':
            self.query(udf.fixindent('''
                CREATE java SCALAR SCRIPT
                "%s"()
                RETURNS INT AS
                class %s {
                    static int f() {
                            return %d;
                    }
                }
                /''' % (name, name, sum(x in string.uppercase for x in name))
                ))

        check("bar", "BAR", 3)
        check("Bar", "BAR", 3)
        check("\"Bar\"", "Bar", 1)
        check("\"bar\"", "bar", 0)