當前位置: 首頁>>代碼示例>>Python>>正文


Python string.ascii_uppercase方法代碼示例

本文整理匯總了Python中string.ascii_uppercase方法的典型用法代碼示例。如果您正苦於以下問題:Python string.ascii_uppercase方法的具體用法?Python string.ascii_uppercase怎麽用?Python string.ascii_uppercase使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在string的用法示例。


在下文中一共展示了string.ascii_uppercase方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: gen_dummy_object

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [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: lambda_handler

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [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

示例3: random_string

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [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

示例4: setup_passwords

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [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

示例5: login

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [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

示例6: test_info_memory_usage_bug_on_multiindex

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [as 別名]
def test_info_memory_usage_bug_on_multiindex(self):
        # GH 14308
        # memory usage introspection should not materialize .values

        from string import ascii_uppercase as uppercase

        def memory_usage(f):
            return f.memory_usage(deep=True).sum()

        N = 100
        M = len(uppercase)
        index = pd.MultiIndex.from_product([list(uppercase),
                                            pd.date_range('20160101',
                                                          periods=N)],
                                           names=['id', 'date'])
        df = DataFrame({'value': np.random.randn(N * M)}, index=index)

        unstacked = df.unstack('id')
        assert df.values.nbytes == unstacked.values.nbytes
        assert memory_usage(df) > memory_usage(unstacked)

        # high upper bound
        assert memory_usage(unstacked) - memory_usage(df) < 2000 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_repr_info.py

示例7: convert_to_label_chars

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [as 別名]
def convert_to_label_chars(s):
  """Turn the specified name and value into a valid Google label."""

  # We want the results to be user-friendly, not just functional.
  # So we can't base-64 encode it.
  #   * If upper-case: lower-case it
  #   * If the char is not a standard letter or digit. make it a dash

  # March 2019 note: underscores are now allowed in labels.
  # However, removing the conversion of underscores to dashes here would
  # create inconsistencies between old jobs and new jobs.
  # With existing code, $USER "jane_doe" has a user-id label of "jane-doe".
  # If we remove the conversion, the user-id label for new jobs is "jane_doe".
  # This makes looking up old jobs more complicated.

  accepted_characters = string.ascii_lowercase + string.digits + '-'

  def label_char_transform(char):
    if char in accepted_characters:
      return char
    if char in string.ascii_uppercase:
      return char.lower()
    return '-'

  return ''.join(label_char_transform(c) for c in s) 
開發者ID:DataBiosphere,項目名稱:dsub,代碼行數:27,代碼來源:job_model.py

示例8: generate_uuid

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [as 別名]
def generate_uuid(size=6, chars=(string.ascii_uppercase + string.digits)):
    """
    Generate convenient universally unique id (UUID)

    Parameters
    ----------
    size : int, optional, default=6
       Number of alphanumeric characters to generate.
    chars : list of chars, optional, default is all uppercase characters and digits
       Characters to use for generating UUIDs

    NOTE
    ----
    This is not really universally unique, but it is convenient.

    """
    return ''.join(random.choice(chars) for _ in range(size)) 
開發者ID:choderalab,項目名稱:assaytools,代碼行數:19,代碼來源:experiments.py

示例9: get_snap

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [as 別名]
def get_snap(self, timeout: int = 3) -> Image or None:
        """
        Gets a "snap" of the current camera video data and returns a Pillow Image or None
        :param timeout: Request timeout to camera in seconds
        :return: Image or None
        """
        randomstr = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
        snap = self.url + "?cmd=Snap&channel=0&rs=" \
               + randomstr \
               + "&user=" + self.username \
               + "&password=" + self.password
        try:
            req = request.Request(snap)
            req.set_proxy(Request.proxies, 'http')
            reader = request.urlopen(req, timeout)
            if reader.status == 200:
                b = bytearray(reader.read())
                return Image.open(io.BytesIO(b))
            print("Could not retrieve data from camera successfully. Status:", reader.status)
            return None

        except Exception as e:
            print("Could not get Image data\n", e)
            raise 
開發者ID:Benehiko,項目名稱:ReolinkCameraAPI,代碼行數:26,代碼來源:recording.py

示例10: rand_password

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [as 別名]
def rand_password(length=15):
    """Generate a random password

    :param int length: The length of password that you expect to set
                       (If it's smaller than 3, it's same as 3.)
    :return: a random password. The format is
             '<random upper letter>-<random number>-<random special character>
              -<random ascii letters or digit characters or special symbols>'
             (e.g. 'G2*ac8&lKFFgh%2')
    :rtype: string
    """
    upper = random.choice(string.ascii_uppercase)
    ascii_char = string.ascii_letters
    digits = string.digits
    digit = random.choice(string.digits)
    puncs = '~!@#$%^&*_=+'
    punc = random.choice(puncs)
    seed = ascii_char + digits + puncs
    pre = upper + digit + punc
    password = pre + ''.join(random.choice(seed) for x in range(length - 3))
    return password 
開發者ID:openstack,項目名稱:tempest-lib,代碼行數:23,代碼來源:data_utils.py

示例11: test_recordio_pack_label

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [as 別名]
def test_recordio_pack_label():
    frec = tempfile.mktemp()
    N = 255

    for i in range(1, N):
        for j in range(N):
            content = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(j))
            content = content.encode('utf-8')
            label = np.random.uniform(size=i).astype(np.float32)
            header = (0, label, 0, 0)
            s = mx.recordio.pack(header, content)
            rheader, rcontent = mx.recordio.unpack(s)
            assert (label == rheader.label).all()
            assert content == rcontent 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:16,代碼來源:test_recordio.py

示例12: gen_random_string

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [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

示例13: generate_password

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [as 別名]
def generate_password(length=16):
    while True:
        password = [random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(length)]
        password.insert(8, "-")
        if not any(c in string.ascii_uppercase for c in password):
            continue
        if not any(c in string.ascii_lowercase for c in password):
            continue
        if not any(c in string.digits for c in password):
            continue
        return ''.join(password) 
開發者ID:kislyuk,項目名稱:aegea,代碼行數:13,代碼來源:iam.py

示例14: generate_token

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [as 別名]
def generate_token(length=60):
    chars = string.ascii_uppercase + string.digits
    return ''.join(random.choice(chars) for _ in range(length)) 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:5,代碼來源:services.py

示例15: patch_toon

# 需要導入模塊: import string [as 別名]
# 或者: from string import ascii_uppercase [as 別名]
def patch_toon(self):
        (port, clean_up, reboot) = (
            self._port, self._cleanup_payload, self._reboot_after)
        log.info("Patching Toon")
        log.debug(port.read_until("/ # "))
        password = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8))
        port.write("sh payload/patch_toon.sh \"{}\"\n".format(password))
        try:
            while True:
                line = read_until(port, ["/ # ", "\n"])
                if line == "/ # ":
                    break
                if line.startswith(">>>"):
                    log.info(line.strip())
                else:
                    log.debug(line.strip())
        except:
            log.exception("Script failed")
            sleep(5)
        if clean_up:
            log.info("Cleaning up")
            port.write("rm -r payload\n")
            log.debug(port.read_until("/ # "))
        if reboot:
            log.info("Rebooting")
            port.write("/etc/init.d/reboot\n") 
開發者ID:martenjacobs,項目名稱:ToonRooter,代碼行數:28,代碼來源:rooter.py


注:本文中的string.ascii_uppercase方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。