Python string.ascii_uppercase() Examples
The following are 30
code examples of string.ascii_uppercase().
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 also want to check out all available functions/classes of the module
string
, or try the search function
.
Example #1
Source File: test_app.py From hydrus with MIT License | 6 votes |
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_
Example #2
Source File: experiments.py From assaytools with GNU Lesser General Public License v2.1 | 6 votes |
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))
Example #3
Source File: client_auth.py From maubot with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #4
Source File: job_model.py From dsub with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: util.py From instavpn with Apache License 2.0 | 6 votes |
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
Example #6
Source File: my_utils.py From ICDAR-2019-SROIE with MIT License | 6 votes |
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
Example #7
Source File: lambda_function.py From aws-batch-example with MIT License | 6 votes |
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']))
Example #8
Source File: recording.py From ReolinkCameraAPI with GNU General Public License v3.0 | 6 votes |
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
Example #9
Source File: data_utils.py From tempest-lib with Apache License 2.0 | 6 votes |
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
Example #10
Source File: test_cli.py From hydrus with MIT License | 6 votes |
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_
Example #11
Source File: test_crud.py From hydrus with MIT License | 6 votes |
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_
Example #12
Source File: vim-matlab-server.py From vim-matlab with Mozilla Public License 2.0 | 5 votes |
def run_code(self, code, run_timer=True): num_retry = 0 rand_var = ''.join( random.choice(string.ascii_uppercase) for _ in range(12)) if run_timer: command = ("{randvar}=tic;{code},try,toc({randvar}),catch,end" ",clear('{randvar}');\n").format(randvar=rand_var, code=code.strip()) else: command = "{}\n".format(code.strip()) # The maximum number of characters allowed on a single line in Matlab's CLI is 4096. delim = ' ...\n' line_size = 4095 - len(delim) command = delim.join([command[i:i+line_size] for i in range(0, len(command), line_size)]) global hide_until_newline while num_retry < 3: try: if use_pexpect: hide_until_newline = True self.proc.send(command) else: self.proc.stdin.write(command) self.proc.stdin.flush() break except Exception as ex: print ex self.launch_process() num_retry += 1 time.sleep(1)
Example #13
Source File: run.py From FunUtils with MIT License | 5 votes |
def generate(): letters = string.ascii_lowercase + string.digits + string.ascii_uppercase try: length = int(input("Enter name length: ")) print(''.join(random.choice(letters) for i in range(length))) except ValueError: print("Please enter a number.") generate()
Example #14
Source File: button_action_demo.py From Odoo_Samples with GNU Affero General Public License v3.0 | 5 votes |
def generate_record_password(self): self.ensure_one() #Generates a random password between 12 and 15 characters long and writes it to the record. self.write({ 'password': ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(randint(12,15))) })
Example #15
Source File: indeed_ads.py From info-flow-experiments with GNU General Public License v3.0 | 5 votes |
def get_random_string(N): return ''.join(random.choice(string.ascii_uppercase) for _ in range(N))
Example #16
Source File: login.py From pagure with GNU General Public License v2.0 | 5 votes |
def id_generator(size=15, chars=string.ascii_uppercase + string.digits): """ Generates a random identifier for the given size and using the specified characters. If no size is specified, it uses 15 as default. If no characters are specified, it uses ascii char upper case and digits. :arg size: the size of the identifier to return. :arg chars: the list of characters that can be used in the idenfitier. """ return "".join(random_choice(chars) for x in range(size))
Example #17
Source File: button_action_demo.py From Odoo_Samples with GNU Affero General Public License v3.0 | 5 votes |
def generate_record_name(self): self.ensure_one() #Generates a random name between 9 and 15 characters long and writes it to the record. self.write({'name': ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(randint(9,15)))})
Example #18
Source File: test_socket.py From RAASNet with GNU General Public License v3.0 | 5 votes |
def gen_string(size=64, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for _ in range(size))
Example #19
Source File: models.py From PrivacyScore with GNU General Public License v3.0 | 5 votes |
def generate_random_token() -> str: """Generate a random token.""" return''.join(random.SystemRandom().choice( string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(50))
Example #20
Source File: test_dataset_modes.py From buzzard with Apache License 2.0 | 5 votes |
def shp3_path(fps): """Create a shapefile without SR containing all single letter polygons from `fps` fixture""" path = '{}/{}.shp'.format(tempfile.gettempdir(), uuid.uuid4()) ds = buzz.Dataset() ds.create_vector('poly', path, 'polygon', sr=None) for letter in string.ascii_uppercase[:9]: ds.poly.insert_data(fps[letter].poly) ds.poly.close() del ds yield path gdal.GetDriverByName('ESRI Shapefile').Delete(path)
Example #21
Source File: test_dataset_modes.py From buzzard with Apache License 2.0 | 5 votes |
def tif2_path(fps): """Create a tif in SR2 with all single letter footprints from `fps` fixture burnt in it""" path = '{}/{}.tif'.format(tempfile.gettempdir(), uuid.uuid4()) ds = buzz.Dataset() with ds.acreate_raster(path, fps.AI, 'int32', 1, sr=SR2['wkt']).close as r: for letter in string.ascii_uppercase[:9]: fp = fps[letter] arr = np.full(fp.shape, ord(letter), dtype=int) r.set_data(arr, fp=fp) yield path gdal.GetDriverByName('GTiff').Delete(path)
Example #22
Source File: test_dataset_modes.py From buzzard with Apache License 2.0 | 5 votes |
def shp2_path(fps): """Create a shapefile in SR2 containing all single letter polygons from `fps` fixture""" path = '{}/{}.shp'.format(tempfile.gettempdir(), uuid.uuid4()) ds = buzz.Dataset() ds.create_vector('poly', path, 'polygon', sr=SR2['wkt']) for letter in string.ascii_uppercase[:9]: ds.poly.insert_data(fps[letter].poly) ds.poly.close() del ds yield path gdal.GetDriverByName('ESRI Shapefile').Delete(path)
Example #23
Source File: test_dataset_modes.py From buzzard with Apache License 2.0 | 5 votes |
def tif1_path(fps): """Create a tif in SR1 with all single letter footprints from `fps` fixture burnt in it""" path = '{}/{}.tif'.format(tempfile.gettempdir(), uuid.uuid4()) ds = buzz.Dataset() ds.create_raster('rast', path, fps.AI, 'int32', 1, sr=SR1['wkt']) for letter in string.ascii_uppercase[:9]: fp = fps[letter] arr = np.full(fp.shape, ord(letter), dtype=int) ds.rast.set_data(arr, fp=fp) ds.rast.close() del ds yield path gdal.GetDriverByName('GTiff').Delete(path)
Example #24
Source File: test_dataset_modes.py From buzzard with Apache License 2.0 | 5 votes |
def shp1_path(fps): """Create a shapefile in SR1 containing all single letter polygons from `fps` fixture""" path = '{}/{}.shp'.format(tempfile.gettempdir(), uuid.uuid4()) ds = buzz.Dataset() ds.create_vector('poly', path, 'polygon', sr=SR1['wkt']) for letter in string.ascii_uppercase[:9]: ds.poly.insert_data(fps[letter].poly) ds.poly.close() del ds yield path gdal.GetDriverByName('ESRI Shapefile').Delete(path)
Example #25
Source File: conftest.py From caldera with Apache License 2.0 | 5 votes |
def adversary(): def _generate_adversary(adversary_id=None, name=None, description=None, phases=None): if not adversary_id: adversary_id = uuid.uuid4() if not name: name = ''.join(random.choice(string.ascii_uppercase) for _ in range(10)) if not description: description = "description" if not phases: phases = dict() return Adversary(adversary_id=adversary_id, name=name, description=description, atomic_ordering=phases) return _generate_adversary
Example #26
Source File: pyro_utils.py From DL4MT with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_random_key(): return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(10))
Example #27
Source File: util.py From browserscope with Apache License 2.0 | 5 votes |
def __init__(self): self.prefix = 'e:' chars = string.ascii_uppercase + string.ascii_lowercase + string.digits \ + '-.' self.code = [x + y for x in chars for y in chars] self.min = 0 self.max = len(self.code) - 1
Example #28
Source File: util.py From browserscope with Apache License 2.0 | 5 votes |
def __init__(self): self.prefix = 's:' self.code = string.ascii_uppercase + string.ascii_lowercase + string.digits self.min = 0 self.max = len(self.code) - 1
Example #29
Source File: utils.py From ADFSpoof with Apache License 2.0 | 5 votes |
def random_string(): return '_' + ''.join(random.choices(string.ascii_uppercase + string.digits, k=6))
Example #30
Source File: tests.py From django-defender with Apache License 2.0 | 5 votes |
def _get_random_str(self): """ Returns a random str """ chars = string.ascii_uppercase + string.digits return "".join(random.choice(chars) for _ in range(20))