mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-06 22:01:36 +00:00
standardize char choice strings
This commit is contained in:
18
src/gam.py
18
src/gam.py
@@ -43,7 +43,6 @@ import shlex
|
|||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import string
|
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
@@ -134,9 +133,8 @@ google_auth_httplib2.AuthorizedHttp.request = _request_with_user_agent(
|
|||||||
# is landed and released.
|
# is landed and released.
|
||||||
def _authorization_url(self, **kwargs):
|
def _authorization_url(self, **kwargs):
|
||||||
kwargs.setdefault('access_type', 'offline')
|
kwargs.setdefault('access_type', 'offline')
|
||||||
chars = string.ascii_letters+string.digits+'-._~'
|
|
||||||
rnd = SystemRandom()
|
rnd = SystemRandom()
|
||||||
random_verifier = [rnd.choice(chars) for _ in range(128)]
|
random_verifier = [rnd.choice(URL_SAFE_CHARS) for _ in range(128)]
|
||||||
self.code_verifier = ''.join(random_verifier)
|
self.code_verifier = ''.join(random_verifier)
|
||||||
code_hash = hashlib.sha256()
|
code_hash = hashlib.sha256()
|
||||||
code_hash.update(str.encode(self.code_verifier))
|
code_hash.update(str.encode(self.code_verifier))
|
||||||
@@ -3351,7 +3349,7 @@ def encode_multipart(fields, files, boundary=None):
|
|||||||
return '--{0}'.format(boundary), 'Content-Disposition: form-data; name="{0}"'.format(escape_quote(name)), '', str(value)
|
return '--{0}'.format(boundary), 'Content-Disposition: form-data; name="{0}"'.format(escape_quote(name)), '', str(value)
|
||||||
|
|
||||||
if boundary is None:
|
if boundary is None:
|
||||||
boundary = ''.join(random.choice(string.digits+string.ascii_letters) for _ in range(30))
|
boundary = ''.join(random.choice(ALPHANUMERIC_CHARS) for _ in range(30))
|
||||||
lines = []
|
lines = []
|
||||||
for name, value in list(fields.items()):
|
for name, value in list(fields.items()):
|
||||||
if name == 'tags':
|
if name == 'tags':
|
||||||
@@ -3455,7 +3453,6 @@ def doPrintJobFetch():
|
|||||||
result = callGAPI(cp.printers(), 'get',
|
result = callGAPI(cp.printers(), 'get',
|
||||||
printerid=printerid)
|
printerid=printerid)
|
||||||
checkCloudPrintResult(result)
|
checkCloudPrintResult(result)
|
||||||
valid_chars = '-_.() '+string.ascii_letters+string.digits
|
|
||||||
ssd = '{"state": {"type": "DONE"}}'
|
ssd = '{"state": {"type": "DONE"}}'
|
||||||
if ((not sortorder) or (sortorder == 'CREATE_TIME_DESC')) and (older_or_newer == 'newer'):
|
if ((not sortorder) or (sortorder == 'CREATE_TIME_DESC')) and (older_or_newer == 'newer'):
|
||||||
timeExit = True
|
timeExit = True
|
||||||
@@ -3496,7 +3493,7 @@ def doPrintJobFetch():
|
|||||||
continue
|
continue
|
||||||
fileUrl = job['fileUrl']
|
fileUrl = job['fileUrl']
|
||||||
jobid = job['id']
|
jobid = job['id']
|
||||||
fileName = os.path.join(targetFolder, '{0}-{1}'.format(''.join(c if c in valid_chars else '_' for c in job['title']), jobid))
|
fileName = os.path.join(targetFolder, '{0}-{1}'.format(''.join(c if c in FILENAME_SAFE_CHARS else '_' for c in job['title']), jobid))
|
||||||
_, content = cp._http.request(uri=fileUrl, method='GET')
|
_, content = cp._http.request(uri=fileUrl, method='GET')
|
||||||
if writeFile(fileName, content, mode='wb', continueOnError=True):
|
if writeFile(fileName, content, mode='wb', continueOnError=True):
|
||||||
# ticket = callGAPI(cp.jobs(), u'getticket', jobid=jobid, use_cjt=True)
|
# ticket = callGAPI(cp.jobs(), u'getticket', jobid=jobid, use_cjt=True)
|
||||||
@@ -4952,7 +4949,6 @@ def downloadDriveFile(users):
|
|||||||
targetFolder = GC_Values[GC_DRIVE_DIR]
|
targetFolder = GC_Values[GC_DRIVE_DIR]
|
||||||
targetName = None
|
targetName = None
|
||||||
overwrite = showProgress = targetStdout = False
|
overwrite = showProgress = targetStdout = False
|
||||||
safe_filename_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
|
|
||||||
while i < len(sys.argv):
|
while i < len(sys.argv):
|
||||||
myarg = sys.argv[i].lower().replace('_', '')
|
myarg = sys.argv[i].lower().replace('_', '')
|
||||||
if myarg == 'id':
|
if myarg == 'id':
|
||||||
@@ -5058,7 +5054,7 @@ def downloadDriveFile(users):
|
|||||||
if targetName:
|
if targetName:
|
||||||
safe_file_title = targetName
|
safe_file_title = targetName
|
||||||
else:
|
else:
|
||||||
safe_file_title = ''.join(c for c in result['title'] if c in safe_filename_chars)
|
safe_file_title = ''.join(c for c in result['title'] if c in FILENAME_SAFE_CHARS)
|
||||||
if not safe_file_title:
|
if not safe_file_title:
|
||||||
safe_file_title = fileId
|
safe_file_title = fileId
|
||||||
filename = os.path.join(targetFolder, safe_file_title)
|
filename = os.path.join(targetFolder, safe_file_title)
|
||||||
@@ -7497,8 +7493,7 @@ def getUserAttributes(i, cd, updateCmd):
|
|||||||
systemErrorExit(2, '%s is not a valid argument for "gam %s user"' % (sys.argv[i], ['create', 'update'][updateCmd]))
|
systemErrorExit(2, '%s is not a valid argument for "gam %s user"' % (sys.argv[i], ['create', 'update'][updateCmd]))
|
||||||
if need_password:
|
if need_password:
|
||||||
rnd = SystemRandom()
|
rnd = SystemRandom()
|
||||||
valid_chars = string.digits+string.ascii_letters+string.punctuation
|
body['password'] = ''.join(rnd.choice(PASSWORD_SAFE_CHARS) for _ in range(100))
|
||||||
body['password'] = ''.join(rnd.choice(valid_chars) for _ in range(100))
|
|
||||||
if 'password' in body and need_to_hash_password:
|
if 'password' in body and need_to_hash_password:
|
||||||
body['password'] = gen_sha512_hash(body['password'])
|
body['password'] = gen_sha512_hash(body['password'])
|
||||||
body['hashFunction'] = 'crypt'
|
body['hashFunction'] = 'crypt'
|
||||||
@@ -7514,6 +7509,7 @@ def _run_oauth_flow(client_id, client_secret, scopes, access_type, login_hint=No
|
|||||||
'token_uri': 'https://oauth2.googleapis.com/token',
|
'token_uri': 'https://oauth2.googleapis.com/token',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_config(client_config, scopes)
|
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_config(client_config, scopes)
|
||||||
kwargs = {'access_type': access_type}
|
kwargs = {'access_type': access_type}
|
||||||
if login_hint:
|
if login_hint:
|
||||||
@@ -7724,7 +7720,7 @@ def _getLoginHintProjectId(createCmd):
|
|||||||
elif createCmd:
|
elif createCmd:
|
||||||
projectId = 'gam-project'
|
projectId = 'gam-project'
|
||||||
for _ in range(3):
|
for _ in range(3):
|
||||||
projectId += '-{0}'.format(''.join(random.choice(string.digits+string.ascii_lowercase) for _ in range(3)))
|
projectId += '-{0}'.format(''.join(random.choice(LOWERNUMERIC_CHARS) for _ in range(3)))
|
||||||
else:
|
else:
|
||||||
projectId = input('\nWhat is your API project ID? ').strip()
|
projectId = input('\nWhat is your API project ID? ').strip()
|
||||||
if not PROJECTID_PATTERN.match(projectId):
|
if not PROJECTID_PATTERN.match(projectId):
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import ssl
|
import ssl
|
||||||
|
import string
|
||||||
import sys
|
import sys
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
@@ -470,6 +471,12 @@ RT_CLOSE_PATTERN = re.compile(r'{/RT}')
|
|||||||
RT_STRIP_PATTERN = re.compile(r'(?s){RT}.*?{/RT}')
|
RT_STRIP_PATTERN = re.compile(r'(?s){RT}.*?{/RT}')
|
||||||
RT_TAG_REPLACE_PATTERN = re.compile(r'{(.*?)}')
|
RT_TAG_REPLACE_PATTERN = re.compile(r'{(.*?)}')
|
||||||
|
|
||||||
|
LOWERNUMERIC_CHARS = string.ascii_lowercase+string.digits
|
||||||
|
ALPHANUMERIC_CHARS = LOWERNUMERIC_CHARS+string.ascii_uppercase
|
||||||
|
URL_SAFE_CHARS = ALPHANUMERIC_CHARS+'-._~'
|
||||||
|
PASSWORD_SAFE_CHARS = ALPHANUMERIC_CHARS+string.punctuation+' '
|
||||||
|
FILENAME_SAFE_CHARS = ALPHANUMERIC_CHARS+'-_.() '
|
||||||
|
|
||||||
FILTER_ADD_LABEL_TO_ARGUMENT_MAP = {
|
FILTER_ADD_LABEL_TO_ARGUMENT_MAP = {
|
||||||
'IMPORTANT': 'important',
|
'IMPORTANT': 'important',
|
||||||
'STARRED': 'star',
|
'STARRED': 'star',
|
||||||
|
|||||||
Reference in New Issue
Block a user