python类ascii_letters()的实例源码

tockloader.py 文件源码 项目:tockloader 作者: helena-project 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def dump_flash_page (self, page_num):
        '''
        Print one page of flash contents.
        '''
        with self._start_communication_with_board():
            address = 512 * page_num
            print('Page number: {} ({:#08x})'.format(page_num, address))

            flash = self.channel.read_range(address, 512)

            def chunks(l, n):
                for i in range(0, len(l), n):
                    yield l[i:i + n]

            def dump_line (addr, bytes):
                k = binascii.hexlify(bytes).decode('utf-8')
                b = ' '.join(list(chunks(k, 2)))
                if len(b) >= 26:
                    # add middle space
                    b = '{} {}'.format(b[0:24], b[24:])
                printable = string.ascii_letters + string.digits + string.punctuation + ' '
                t = ''.join([chr(i) if chr(i) in printable else '.' for i in bytes])
                print('{:08x}  {}  |{}|'.format(addr, b, t))

            for i,chunk in enumerate(chunks(flash, 16)):
                dump_line(address+(i*16), chunk)

    ############################################################################
    ## Internal Helper Functions for Communicating with Boards
    ############################################################################
nturl2path.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def url2pathname(url):
    """OS-specific conversion from a relative URL of the 'file' scheme
    to a file system path; not recommended for general use."""
    # e.g.
    # ///C|/foo/bar/spam.foo
    # becomes
    # C:\foo\bar\spam.foo
    import string, urllib
    # Windows itself uses ":" even in URLs.
    url = url.replace(':', '|')
    if not '|' in url:
        # No drive specifier, just convert slashes
        if url[:4] == '////':
            # path is something like ////host/path/on/remote/host
            # convert this to \\host\path\on\remote\host
            # (notice halving of slashes at the start of the path)
            url = url[2:]
        components = url.split('/')
        # make sure not to convert quoted slashes :-)
        return urllib.unquote('\\'.join(components))
    comp = url.split('|')
    if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
        error = 'Bad URL: ' + url
        raise IOError, error
    drive = comp[0][-1].upper()
    path = drive + ':'
    components = comp[1].split('/')
    for comp in components:
        if comp:
            path = path + '\\' + urllib.unquote(comp)
    # Issue #11474: url like '/C|/' should convert into 'C:\\'
    if path.endswith(':') and url.endswith('/'):
        path += '\\'
    return path
live_response_api.py 文件源码 项目:cbapi-python 作者: carbonblack 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def _random_file_name(self):
        randfile = ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(12)])
        if self.os_type == 1:
            workdir = 'c:\\windows\\temp'
        else:
            workdir = '/tmp'

        return self.path_join(workdir, 'cblr.%s.tmp' % (randfile,))
base.py 文件源码 项目:cmsplugin-form-handler 作者: mkoistinen 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_random_string(length=10):
        """
        Quick-n-dirty random string generation.
        """
        chars = string.ascii_letters + string.digits
        return ''.join([random.choice(chars) for _ in range(length)])
views.py 文件源码 项目:BackManager 作者: linuxyan 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def GenPassword(length=8,chars=string.ascii_letters+string.digits):
    return ''.join([choice(chars) for i in range(length)])
utils.py 文件源码 项目:Plamber 作者: OlegKlimenko 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def generate_password():
    """
    Generates the random temporary password.

    :rtype str: The new temp password.
    """
    return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(PASSWORD_LENGTH))


# ----------------------------------------------------------------------------------------------------------------------
arch_arm.py 文件源码 项目:isabelle 作者: wisk 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _ARM_GetMnemonic(self, insn):
        fmt = insn['format']
        res = ''
        for c in fmt:
            if not c in string.ascii_letters+string.digits:
                break
            res += c
        return res
csvrotator.py 文件源码 项目:rpi-can-logger 作者: JonnoFTW 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def make_random(self, nchars):
        alphabet = string.ascii_letters + string.digits
        return ''.join(random.choice(alphabet) for _ in range(nchars))
jsonlogrotator.py 文件源码 项目:rpi-can-logger 作者: JonnoFTW 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def make_random(nchars):
        alphabet = string.ascii_letters + string.digits
        return ''.join(random.choice(alphabet) for _ in range(nchars))
test_cli.py 文件源码 项目:run_lambda 作者: ethantkoenig 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def random_string():
        length = random.randint(1, 10)
        return "".join(random.choice(string.ascii_letters)
                       for _ in range(length))

# test lambda functions
__init__.py 文件源码 项目:common-utils 作者: mechaphish 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def create_temp_dir(self):
        """
        Create a temp directory.
        :return: Directory name of the created temp directory.
        """
        dir_name = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(16))
        dir_name = os.path.join("/tmp", dir_name)
        self.run_command('rm -rf ' + str(dir_name))
        self.run_command('mkdir -p ' + str(dir_name))
        return dir_name
generator.py 文件源码 项目:AntiRansom 作者: YJesus 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def randomxls (path) :

    numxls = (randint(2000,5000))

    for i in range(10):

        name = path + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(randint(5,15))]) + ".xlsx"

        workbook = xlsxwriter.Workbook(name)
        worksheet = workbook.add_worksheet()


        numrows = (randint(100,500))

        for i in range(numrows):

            coord = 'A' + str(i)

            textinrow = ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(randint(5,15))])

            worksheet.write(coord , textinrow)


        workbook.close()

        for i in range(numxls):

            dupli =  path + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(randint(5,15))]) + ".xlsx"

            copyfile(name, dupli)


#PDF Files
_service.py 文件源码 项目:bap-ida-python 作者: BinaryAnalysisPlatform 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def is_valid_service_name(name):
    valid_syms = string.ascii_letters + '-_' + string.digits
    return set(name).issubset(valid_syms)
sparphantor.py 文件源码 项目:sparphantor 作者: antitree 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def generate_path(start=None):
    return ''.join(random.choice(ascii_letters) for _ in range(5))
views.py 文件源码 项目:webtzite 作者: materialsproject 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def generate_key(length):
    return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
test_nixio.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def rword(n=10):
        return "".join(np.random.choice(list(string.ascii_letters), n))
wrappers.py 文件源码 项目:django-paydirekt 作者: ParticulateSolutions 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def _get_random(self, length=64):
        valid_chars = string.ascii_letters + string.digits + '-' + '_'
        return ''.join(random.SystemRandom().choice(valid_chars) for x in range(length))
live_response.py 文件源码 项目:Splunk_CBER_App 作者: MHaggis 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def create_process(self, command_string):
        # process is:
        # - create a temporary file name
        # - create the process, writing output to a temporary file
        # - wait for the process to complete
        # - get the temporary file from the endpoint
        # - delete the temporary file

        randfile = ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(12)])
        workdir = 'c:\\windows\\carbonblack'
        randfilename = '%s\\cblr.%s.tmp' % (workdir, randfile)

        session_id = self.live_response_session

        url = "%s/api/v1/cblr/session/%d/command" % (self.cb.server, session_id)
        data = {"session_id": session_id, "name": "create process", "object": command_string,
                "wait": True, "working_directory": workdir, "output_file": randfilename}
        r = requests.post(url, headers=self.cb.token_header, data=json.dumps(data), verify=self.cb.ssl_verify,
                          timeout=120)
        r.raise_for_status()
        resp = r.json()

        command_id = resp.get('id')
        command_state = 'pending'

        while command_state != 'complete':
            time.sleep(.2)
            resp = self.cb.live_response_session_command_get(session_id, command_id)
            command_state = resp.get('status')

        # now the file is ready to be read

        file_content = self.get_file(randfilename)
        # delete the file
        self.cb.live_response_session_command_post(session_id, "delete file", randfilename)

        return file_content
formula_solver.py 文件源码 项目:Formulate 作者: BebeSparkelSparkel 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def no_re_matches(re_pattern, length=5, max_attempts = 100):
  for count in range(max_attempts):
    try_string = ''.join(random.choice(string.ascii_letters) for x in range(length))
    if re_search_better(re_pattern, try_string) is None:
      return try_string
  raise ValueUnitsError('Non-matching pattern cannot be found')


# abstracts the sub-formula contained in parentheses to a unique variable name
# if there are any variables already in formula they need to be selected by the re pattern variables_re so that duplicate variable names are not created
# returns the formula with all the new variables in it and a dictionary with the new variables as keys and the origional expression as the values


问题


面经


文章

微信
公众号

扫码关注公众号