use base64.urlsafe_b64 commands

This commit is contained in:
Jay Lee 2014-07-13 15:04:54 -04:00
parent 00a61dae70
commit 3dc755eafa

13
gam.py
View File

@ -1508,9 +1508,7 @@ def doPhoto(users):
except IOError, e:
print u' couldn\'t open %s: %s' % (filename, e.strerror)
continue
image_data = base64.b64encode(image_data)
image_data = image_data.replace(u'/', u'_')
image_data = image_data.replace(u'+', u'-')
image_data = base64.urlsafe_b64encode(image_data)
body = {u'photoData': image_data}
callGAPI(service=cd.users().photos(), function=u'update', soft_errors=True, userKey=user, body=body)
@ -1533,9 +1531,7 @@ def getPhoto(users):
continue
try:
photo_data = photo[u'photoData']
photo_data = photo_data.replace(u'_', u'/')
photo_data = photo_data.replace(u'-', u'+')
photo_data = base64.b64decode(photo_data)
photo_data = base64.urlsafe_b64decode(photo_data)
except KeyError:
print u' no photo for %s' % user
continue
@ -3425,7 +3421,7 @@ def doCreateUser():
body[u'password'] = gen_sha512_hash(body[u'password'])
body[u'hashFunction'] = u'crypt'
print u"Creating account for %s" % body[u'primaryEmail']
callGAPI(service=cd.users(), function='insert', body=body)
callGAPI(service=cd.users(), function='insert', body=body, fields=u'primaryEmail')
if do_admin:
print u' Changing admin status for %s to %s' % (body[u'primaryEmail'], admin_body[u'status'])
callGAPI(service=cd.users(), function=u'makeAdmin', userKey=body[u'primaryEmail'], body=admin_body)
@ -6387,8 +6383,7 @@ def send_email(msg_subj, msg_txt, msg_rcpt=None):
msg[u'From'] = sender_email
msg[u'To'] = msg_rcpt
msg_string = msg.as_string()
msg_b64 = base64.b64encode(msg_string)
msg_raw = msg_b64.replace(u'/', u'_').replace(u'+', u'-')
msg_raw = base64.urlsafe_b64encode(msg_string)
callGAPI(service=gmail.users().messages(), function=u'send', userId=sender_email, body={u'raw': msg_raw})
def doDownloadExportRequest():