python类digits()的实例源码

tests.py 文件源码 项目:flora 作者: Lamden 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def random_string(length):
    pool = string.ascii_letters + string.digits
    return ''.join(random.choice(pool) for i in range(length))
api.py 文件源码 项目:flora 作者: Lamden 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def random_string(length):
    pool = string.ascii_letters + string.digits
    return ''.join(random.choice(pool) for i in range(length))
GameController.py 文件源码 项目:HTP 作者: nklose 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def valid_filename(filename):
    allowed_chars = string.ascii_lowercase + string.digits + '.-_'
    return all(c in allowed_chars for c in filename)

# checks if a given directory name matches naming requirements
GameController.py 文件源码 项目:HTP 作者: nklose 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def valid_dirname(dirname):
    allowed_chars = string.ascii_lowercase + string.digits + '-_'
    return all(c in allowed_chars for c in dirname)
Utils.py 文件源码 项目:newsreap 作者: caronc 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def random_str(count=16, seed=ascii_uppercase + digits + ascii_lowercase):
    """
    Generates a random string. This code is based on a great stackoverflow
    post here: http://stackoverflow.com/questions/2257441/\
                    random-string-generation-with-upper-case-\
                    letters-and-digits-in-python
    """
    return ''.join(choice(seed) for _ in range(count))
vrmilter.py 文件源码 项目:sipxecs-voicemail-transcription 作者: andrewsauder 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def random_string(size=6, chars=string.ascii_uppercase + string.digits):
    """Get a random string of numbers and uppercase letters"""
    return ''.join(random.choice(chars) for _ in range(size))
util.py 文件源码 项目:timeblob 作者: dkieffer 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def create_rand_string(length):
    return ''.join(random.choice(string.ascii_letters + string.digits + " ") for _ in range(length))
user.py 文件源码 项目:picoCTF 作者: picoCTF 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _check_username(username):
    return all([c in string.digits + string.ascii_lowercase for c in username.lower()])
challenge.py 文件源码 项目:picoCTF 作者: picoCTF 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def initialize(self):
        # generate random 32 hexadecimal characters
        self.enc_key = ''.join(self.random.choice(string.digits + 'abcdef') for _ in range(32))

        self.welcome_message = "Welcome to Secure Encryption Service version 1.{}".format(self.random.randint(0,10))
nmap-scanner.py 文件源码 项目:nweb 作者: pierce403 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def scan(target):

  server="http://127.0.0.1:5000"
  print("target is "+target)

  # scan server
  rand = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10))
  print("random value is "+rand)
  process = subprocess.Popen(["nmap","-oA","data/nweb."+rand,"-A","-open",target],stdout=subprocess.PIPE)
  try:
    out, err = process.communicate(timeout=360) # 6 minutes
  except:
    try:
      print("killing slacker process")
      process.kill()
    except:
      print("okay, seems like it was already dead")

  print("scan complete, nice")

  result={}
  for ext in 'nmap','gnmap','xml':
    result[ext+"_data"]=open("data/nweb."+rand+"."+ext).read()
    os.remove("data/nweb."+rand+"."+ext)
    print("sending and deleting nweb."+rand+"."+ext)

  if len(result['nmap_data']) < 250:
    print("this data looks crappy")
    return
  else:
    print("size was "+str(len(result['nmap_data'])))

  # submit result
  response=requests.post(server+"/submit",json=json.dumps(result)).text
  print("response is:\n"+response)
prop_helpers.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _cleanId(prop):
    translation = 48*"_"+_string.digits+7*"_"+_string.ascii_uppercase+6*"_"+_string.ascii_lowercase+133*"_"
    prop_id = prop.get_name()
    if prop_id is None:
        prop_id = prop.get_id()
    return str(prop_id).translate(translation)
host.py 文件源码 项目:charm-swift-proxy 作者: openstack 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def pwgen(length=None):
    """Generate a random pasword."""
    if length is None:
        # A random length is ok to use a weak PRNG
        length = random.choice(range(35, 45))
    alphanumeric_chars = [
        l for l in (string.ascii_letters + string.digits)
        if l not in 'l0QD1vAEIOUaeiou']
    # Use a crypto-friendly PRNG (e.g. /dev/urandom) for making the
    # actual password
    random_generator = random.SystemRandom()
    random_chars = [
        random_generator.choice(alphanumeric_chars) for _ in range(length)]
    return(''.join(random_chars))
host.py 文件源码 项目:charm-swift-proxy 作者: openstack 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def pwgen(length=None):
    """Generate a random pasword."""
    if length is None:
        # A random length is ok to use a weak PRNG
        length = random.choice(range(35, 45))
    alphanumeric_chars = [
        l for l in (string.ascii_letters + string.digits)
        if l not in 'l0QD1vAEIOUaeiou']
    # Use a crypto-friendly PRNG (e.g. /dev/urandom) for making the
    # actual password
    random_generator = random.SystemRandom()
    random_chars = [
        random_generator.choice(alphanumeric_chars) for _ in range(length)]
    return(''.join(random_chars))
cyphermain.py 文件源码 项目:Cypher 作者: NullArray 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def gen_client_ID(size=12, chars=string.ascii_uppercase + string.digits):
    return ''.join(random.choice(chars) for _ in range(size))

# Set `SMTP` to False in order to force the program to use HTTP and it's own C&C Web App.
helper.py 文件源码 项目:tornado-ssdb-project 作者: ego008 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def random_str(n=8):
    allow = list(string.uppercase + string.digits)
    r = []
    for i in range(n):
        r.append(random.choice(allow))
    return ''.join(r)
    # return ''.join(random.sample(allow, n))


# ??ssdb_008.py ???????????
tockloader.py 文件源码 项目:tockloader 作者: helena-project 项目源码 文件源码 阅读 23 收藏 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
    ############################################################################
ntpath.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def expanduser(path):
    """Expand ~ and ~user constructs.

    If user or $HOME is unknown, do nothing."""
    if path[:1] != '~':
        return path
    i, n = 1, len(path)
    while i < n and path[i] not in '/\\':
        i = i + 1

    if 'HOME' in os.environ:
        userhome = os.environ['HOME']
    elif 'USERPROFILE' in os.environ:
        userhome = os.environ['USERPROFILE']
    elif not 'HOMEPATH' in os.environ:
        return path
    else:
        try:
            drive = os.environ['HOMEDRIVE']
        except KeyError:
            drive = ''
        userhome = join(drive, os.environ['HOMEPATH'])

    if i != 1: #~user
        userhome = join(dirname(userhome), path[1:i])

    return userhome + path[i:]


# Expand paths containing shell variable substitutions.
# The following rules apply:
#       - no expansion within single quotes
#       - '$$' is translated into '$'
#       - '%%' is translated into '%' if '%%' are not seen in %var1%%var2%
#       - ${varname} is accepted.
#       - $varname is accepted.
#       - %varname% is accepted.
#       - varnames can be made out of letters, digits and the characters '_-'
#         (though is not verified in the ${varname} and %varname% cases)
# XXX With COMMAND.COM you can use any characters in a variable name,
# XXX except '^|<>='.
live_response_api.py 文件源码 项目:cbapi-python 作者: carbonblack 项目源码 文件源码 阅读 26 收藏 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 项目源码 文件源码 阅读 29 收藏 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)])


问题


面经


文章

微信
公众号

扫码关注公众号