当前位置: 首页>>代码示例>>Python>>正文


Python string.digits方法代码示例

本文整理汇总了Python中string.digits方法的典型用法代码示例。如果您正苦于以下问题:Python string.digits方法的具体用法?Python string.digits怎么用?Python string.digits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在string的用法示例。


在下文中一共展示了string.digits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gen_dummy_object

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def gen_dummy_object(class_title, doc):
    """Create a dummy object based on the definitions in the API Doc.
    :param class_title: Title of the class whose object is being created.
    :param doc: ApiDoc.
    :return: A dummy object of class `class_title`.
    """
    object_ = {
        "@type": class_title
    }
    for class_path in doc.parsed_classes:
        if class_title == doc.parsed_classes[class_path]["class"].title:
            for prop in doc.parsed_classes[class_path]["class"].supportedProperty:
                if isinstance(prop.prop, HydraLink) or prop.write is False:
                    continue
                if "vocab:" in prop.prop:
                    prop_class = prop.prop.replace("vocab:", "")
                    object_[prop.title] = gen_dummy_object(prop_class, doc)
                else:
                    object_[prop.title] = ''.join(random.choice(
                        string.ascii_uppercase + string.digits) for _ in range(6))
            return object_ 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:23,代码来源:test_app.py

示例2: scp

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def scp(args):
    """
    Transfer files to or from EC2 instance.
    """
    scp_opts, host_opts = extract_passthrough_opts(args, "scp"), []
    user_or_hostname_chars = string.ascii_letters + string.digits
    ssm_init_complete = False
    for i, arg in enumerate(args.scp_args):
        if arg[0] in user_or_hostname_chars and ":" in arg:
            hostname, colon, path = arg.partition(":")
            username, at, hostname = hostname.rpartition("@")
            if args.use_ssm and not ssm_init_complete:
                scp_opts += init_ssm(get_instance(hostname).id)
                ssm_init_complete = True
            host_opts, hostname = prepare_ssh_host_opts(username=username, hostname=hostname,
                                                        bless_config_filename=args.bless_config,
                                                        use_kms_auth=args.use_kms_auth, use_ssm=args.use_ssm)
            args.scp_args[i] = hostname + colon + path
    os.execvp("scp", ["scp"] + scp_opts + host_opts + args.scp_args) 
开发者ID:kislyuk,项目名称:aegea,代码行数:21,代码来源:ssh.py

示例3: api_config

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def api_config():
    """Request API config from user and set"""
    code, hash_value = DIALOG.inputbox("Enter your API Hash")
    if code == DIALOG.OK:
        if len(hash_value) != 32 or any(it not in string.hexdigits for it in hash_value):
            DIALOG.msgbox("Invalid hash")
            return
        string1 = "HASH = \"" + hash_value + "\""
        code, id_value = DIALOG.inputbox("Enter your API ID")
        if not id_value or any(it not in string.digits for it in id_value):
            DIALOG.msgbox("Invalid ID")
            return
        string2 = "ID = \"" + id_value + "\""
        with open(os.path.join(utils.get_base_dir(), "api_token.py"), "w") as file:
            file.write(string1 + "\n" + string2 + "\n")
        DIALOG.msgbox("API Token and ID set.") 
开发者ID:friendly-telegram,项目名称:friendly-telegram,代码行数:18,代码来源:configurator.py

示例4: cmh_autotune

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def cmh_autotune(self, module, message, additional_data, cm):
		message = message[len(self.CONTROL_AUTOTUNE)+2:]
		# get tune type, requested record type, length and encoding for crafting the answer
		(query_type, RRtype, length, encode_class) = struct.unpack("<BHHH", message[0:7])
		if self.DNS_proto.get_RR_type(RRtype)[0] == None:
			return True
		
		# extra parameters added to be able to response in the proper way
		additional_data = additional_data + (True, self.download_encoding_list[encode_class], self.DNS_proto.get_RR_type(RRtype)[0])		
		if (query_type == 0) or (query_type == 3):
			# record && downstream length discovery
			message = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
		if query_type == 1:
			# A record name length discovery
			message = struct.pack("<i", binascii.crc32(message[7:]))
		if query_type == 2:
			# checking download encoding, echoing back request payload
			message = message[7:]

		module.send(common.CONTROL_CHANNEL_BYTE, self.CONTROL_AUTOTUNE_CLIENT+message, additional_data)
		return True

	# tune control message handler
	# client sets the record type and encodings by calling this
	# server side 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:27,代码来源:DNS.py

示例5: lambda_handler

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def lambda_handler(event,context):
    # Grab data from environment
    jobqueue = os.environ['JobQueue']
    jobdef = os.environ['JobDefinition']

    # Create unique name for the job (this does not need to be unique)
    job1Name = 'job1' + ''.join(random.choices(string.ascii_uppercase + string.digits, k=4))

    # Set up a batch client 
    session = boto3.session.Session()
    client = session.client('batch')

    # Submit the job
    job1 = client.submit_job(
        jobName=job1Name,
        jobQueue=jobqueue,
        jobDefinition=jobdef
    )
    print("Started Job: {}".format(job1['jobName'])) 
开发者ID:dejonghe,项目名称:aws-batch-example,代码行数:21,代码来源:lambda_function.py

示例6: random_string

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def random_string(n):
    if n == 0:
        return ""

    x = random.random()
    if x > 0.5:
        pad = " " * n
    elif x > 0.3:
        pad = "".join(random.choices(digits + " \t\n", k=n))
    elif x > 0.2:
        pad = "".join(random.choices(ascii_uppercase + " \t\n", k=n))
    elif x > 0.1:
        pad = "".join(random.choices(ascii_uppercase + digits + " \t\n", k=n))
    else:
        pad = "".join(
            random.choices(ascii_uppercase + digits + punctuation + " \t\n", k=n)
        )

    return pad 
开发者ID:zzzDavid,项目名称:ICDAR-2019-SROIE,代码行数:21,代码来源:my_utils.py

示例7: gen_salt

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def gen_salt(self, set_=True):
        """
            Generate a random salt
        """

        min_char = 8
        max_char = 12
        allchar = string.ascii_letters + string.punctuation + string.digits
        salt = "".join(choice(allchar)
                       for x in range(randint(min_char, max_char))).encode()

        # Set the salt in the same instance if required
        if set_:
            self.set_salt(salt)

        return salt 
开发者ID:gabfl,项目名称:vault,代码行数:18,代码来源:Encryption.py

示例8: _library_name

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def _library_name(self):
        libname = "jemalloc"
        if self.settings.compiler == "Visual Studio":
            if self.options.shared:
                if self.settings.build_type == "Debug":
                    libname += "d"
            else:
                toolset = msvs_toolset(self.settings)
                toolset_number = "".join(c for c in toolset if c in string.digits)
                libname += "-vc{}-{}".format(toolset_number, self._msvc_build_type)
        else:
            if self.settings.os == "Windows":
                if not self.options.shared:
                    libname += "_s"
            else:
                if not self.options.shared and self.options.fPIC:
                    libname += "_pic"
        return libname 
开发者ID:conan-io,项目名称:conan-center-index,代码行数:20,代码来源:conanfile.py

示例9: s_cname

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def s_cname(s, t):
  CNAME0 = string.ascii_letters + "_.!:"
  CNAME1 = string.ascii_letters + string.digits + "_."

  token = ""
  if s.peek() not in CNAME0:
    return False

  token = s.get()

  try:
    while s.peek() in CNAME1:
      token += s.get()
  except StreamException:
    pass

  t.append((TokenTypes.IDENTIFIER, token))  # TODO: maybe add more info on type

  return True 
开发者ID:gynvael,项目名称:stream,代码行数:21,代码来源:casm.py

示例10: s_ctype

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def s_ctype(s, t):
  CTYPE0 = string.ascii_letters + "_.!:"
  CTYPE1 = string.ascii_letters + string.digits + "_."

  token = ""
  if s.peek() not in CTYPE0:
    return False

  token = s.get()

  try:
    while s.peek() in CTYPE1:
      token += s.get()
  except StreamException:
    pass

  t.append(token)  # TODO: maybe add more info on type

  return True 
开发者ID:gynvael,项目名称:stream,代码行数:21,代码来源:casm.py

示例11: __init__

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def __init__(
        self, k, t=None, sep=None, dotted=False
    ):  # type: (str, Optional[KeyType], Optional[str], bool) -> None
        if t is None:
            if any(
                [c not in string.ascii_letters + string.digits + "-" + "_" for c in k]
            ):
                t = KeyType.Basic
            else:
                t = KeyType.Bare

        self.t = t
        if sep is None:
            sep = " = "

        self.sep = sep
        self.key = k
        self._dotted = dotted 
开发者ID:sdispater,项目名称:tomlkit,代码行数:20,代码来源:items.py

示例12: setup_passwords

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def setup_passwords():
    try:
        char_set = string.ascii_lowercase + string.ascii_uppercase + string.digits
        f = open('/etc/ppp/chap-secrets', 'w')
        pw1 = gen_random_text(12)
        pw2 = gen_random_text(12)
        f.write("username1 l2tpd {} *\n".format(pw1))
        f.write("username2 l2tpd {} *".format(pw2))
        f.close()
        f = open('/etc/ipsec.secrets', 'w')
        f.write('1.2.3.4 %any: PSK "{}"'.format(gen_random_text(16)))
        f.close()
    except:
        logger.exception("Exception creating passwords:")
        return False

    return True 
开发者ID:sockeye44,项目名称:instavpn,代码行数:19,代码来源:util.py

示例13: login

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def login(request: web.Request) -> web.Response:
    info, err = await read_client_auth_request(request)
    if err is not None:
        return err
    api, _, username, password, _ = info
    device_id = ''.join(random.choices(string.ascii_uppercase + string.digits, k=8))
    try:
        return web.json_response(await api.request(Method.POST, Path.login, content={
            "type": "m.login.password",
            "identifier": {
                "type": "m.id.user",
                "user": username,
            },
            "password": password,
            "device_id": f"maubot_{device_id}",
        }))
    except MatrixRequestError as e:
        return web.json_response({
            "errcode": e.errcode,
            "error": e.message,
        }, status=e.http_status) 
开发者ID:maubot,项目名称:maubot,代码行数:23,代码来源:client_auth.py

示例14: getRandomStr

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def getRandomStr(types='letter', length=8):
        """ 随机产生length长度的字符串

        :param types: 随机字符串的类型
        types in ['letter', 'ascii'] 返回包含字母的字符串
        types in ['digit', 'num']: 返回包含数字的字符串
        其他:返回混合字母和数字的字符串

        :param length: 返回字符串的长度
        :return: 长度为length,类型为types的字符串

        todo string.punctuation

        """
        import random
        import string
        if types in ['letter', 'ascii']:
            return ''.join(random.sample(string.ascii_letters, length))
        if types in ['digit', 'num']:
            return ''.join(random.sample(string.digits, length))
        else:
            return ''.join(random.sample(string.ascii_letters + string.digits, length)) 
开发者ID:pchaos,项目名称:wanggeService,代码行数:24,代码来源:base.py

示例15: gen_random_string

# 需要导入模块: import string [as 别名]
# 或者: from string import digits [as 别名]
def gen_random_string(n):
    return ''.join(
        random.choice(
            string.ascii_uppercase + string.digits
        ) for _ in range(n)
    ) 
开发者ID:kmac,项目名称:mlbv,代码行数:8,代码来源:mlbsession.py


注:本文中的string.digits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。