merged conflicts
This commit is contained in:
+38
-42
@@ -11,12 +11,10 @@ Auth, Mail, PluginManager and various utilities
|
||||
"""
|
||||
|
||||
import base64
|
||||
try:
|
||||
import cPickle as pickle
|
||||
except:
|
||||
import pickle
|
||||
from functools import reduce
|
||||
from gluon._compat import pickle, thread, urllib2, Cookie, StringIO, configparser, MIMEBase, MIMEMultipart, \
|
||||
MIMEText, Encoders, Charset, long, urllib_quote, iteritems
|
||||
import datetime
|
||||
import thread
|
||||
import logging
|
||||
import sys
|
||||
import glob
|
||||
@@ -27,16 +25,13 @@ import fnmatch
|
||||
import traceback
|
||||
import smtplib
|
||||
import urllib
|
||||
import urllib2
|
||||
import Cookie
|
||||
import cStringIO
|
||||
import ConfigParser
|
||||
import email.utils
|
||||
import random
|
||||
import hmac
|
||||
import hashlib
|
||||
import json
|
||||
from email import MIMEBase, MIMEMultipart, MIMEText, Encoders, Header, message_from_string, Charset
|
||||
|
||||
from email import message_from_string
|
||||
|
||||
from gluon.contenttype import contenttype
|
||||
from gluon.storage import Storage, StorageList, Settings, Messages
|
||||
@@ -183,7 +178,7 @@ class Mail(object):
|
||||
in this way the can be referenced from the HTML as <img src="cid:attachment-0" /> etc.
|
||||
"""
|
||||
|
||||
class Attachment(MIMEBase.MIMEBase):
|
||||
class Attachment(MIMEBase):
|
||||
"""
|
||||
Email attachment
|
||||
|
||||
@@ -251,7 +246,7 @@ class Mail(object):
|
||||
content_type = contenttype(filename)
|
||||
self.my_filename = filename
|
||||
self.my_payload = payload
|
||||
MIMEBase.MIMEBase.__init__(self, *content_type.split('/', 1))
|
||||
MIMEBase.__init__(self, *content_type.split('/', 1))
|
||||
self.set_payload(payload)
|
||||
self['Content-Disposition'] = 'attachment; filename="%s"' % filename
|
||||
if content_id is not None:
|
||||
@@ -414,7 +409,7 @@ class Mail(object):
|
||||
|
||||
def encode_header(key):
|
||||
if [c for c in key if 32 > ord(c) or ord(c) > 127]:
|
||||
return Header.Header(key.encode('utf-8'), 'utf-8')
|
||||
return Header(key.encode('utf-8'), 'utf-8')
|
||||
else:
|
||||
return key
|
||||
|
||||
@@ -574,12 +569,12 @@ class Mail(object):
|
||||
# insert the origin payload
|
||||
payload.attach(payload_in)
|
||||
# insert the detached signature
|
||||
p = MIMEBase.MIMEBase("application", 'pgp-signature')
|
||||
p = MIMEBase("application", 'pgp-signature')
|
||||
p.set_payload(sig.read())
|
||||
payload.attach(p)
|
||||
# it's just a trick to handle the no encryption case
|
||||
payload_in = payload
|
||||
except errors.GPGMEError, ex:
|
||||
except errors.GPGMEError as ex:
|
||||
self.error = "GPG error: %s" % ex.getstring()
|
||||
return False
|
||||
############################################
|
||||
@@ -614,13 +609,13 @@ class Mail(object):
|
||||
boundary=None,
|
||||
_subparts=None,
|
||||
**dict(protocol="application/pgp-encrypted"))
|
||||
p = MIMEBase.MIMEBase("application", 'pgp-encrypted')
|
||||
p = MIMEBase("application", 'pgp-encrypted')
|
||||
p.set_payload("Version: 1\r\n")
|
||||
payload.attach(p)
|
||||
p = MIMEBase.MIMEBase("application", 'octet-stream')
|
||||
p = MIMEBase("application", 'octet-stream')
|
||||
p.set_payload(cipher.read())
|
||||
payload.attach(p)
|
||||
except errors.GPGMEError, ex:
|
||||
except errors.GPGMEError as ex:
|
||||
self.error = "GPG error: %s" % ex.getstring()
|
||||
return False
|
||||
#######################################################
|
||||
@@ -647,7 +642,7 @@ class Mail(object):
|
||||
# need m2crypto
|
||||
try:
|
||||
from M2Crypto import BIO, SMIME, X509
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.error = "Can't load M2Crypto module"
|
||||
return False
|
||||
msg_bio = BIO.MemoryBuffer(payload_in.as_string())
|
||||
@@ -672,7 +667,7 @@ class Mail(object):
|
||||
else X509.load_cert_string(x509_sign_chainfile)
|
||||
sk.push(chain)
|
||||
s.set_x509_stack(sk)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.error = "Something went wrong on certificate / private key loading: <%s>" % str(e)
|
||||
return False
|
||||
try:
|
||||
@@ -685,7 +680,7 @@ class Mail(object):
|
||||
p7 = s.sign(msg_bio, flags=flags)
|
||||
msg_bio = BIO.MemoryBuffer(payload_in.as_string(
|
||||
)) # Recreate coz sign() has consumed it.
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.error = "Something went wrong on signing: <%s> %s" % (
|
||||
str(e), str(flags))
|
||||
return False
|
||||
@@ -712,7 +707,7 @@ class Mail(object):
|
||||
else:
|
||||
tmp_bio.write(payload_in.as_string())
|
||||
p7 = s.encrypt(tmp_bio)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.error = "Something went wrong on encrypting: <%s>" % str(e)
|
||||
return False
|
||||
|
||||
@@ -749,7 +744,7 @@ class Mail(object):
|
||||
to.extend(bcc)
|
||||
payload['Subject'] = encoded_or_raw(subject.decode(encoding))
|
||||
payload['Date'] = email.utils.formatdate()
|
||||
for k, v in headers.iteritems():
|
||||
for k, v in iteritems(headers):
|
||||
payload[k] = encoded_or_raw(v.decode(encoding))
|
||||
result = {}
|
||||
try:
|
||||
@@ -804,7 +799,7 @@ class Mail(object):
|
||||
result = server.sendmail(
|
||||
sender, to, payload.as_string())
|
||||
server.quit()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.warn('Mail.send failure:%s' % e)
|
||||
self.result = result
|
||||
self.error = e
|
||||
@@ -1235,7 +1230,7 @@ class AuthJWT(object):
|
||||
self.header_prefix = header_prefix
|
||||
self.jwt_add_header = jwt_add_header or {}
|
||||
base_header = {'alg': self.algorithm, 'typ': 'JWT'}
|
||||
for k, v in self.jwt_add_header.iteritems():
|
||||
for k, v in iteritems(self.jwt_add_header):
|
||||
base_header[k] = v
|
||||
self.cached_b64h = self.jwt_b64e(json.dumps(base_header))
|
||||
digestmod_mapping = {
|
||||
@@ -1906,7 +1901,7 @@ class Auth(object):
|
||||
'Please ',
|
||||
A('login',
|
||||
_href=self.settings.login_url +
|
||||
('?_next=' + urllib.quote(current.request.env.http_web2py_component_location))
|
||||
('?_next=' + urllib_quote(current.request.env.http_web2py_component_location))
|
||||
if current.request.env.http_web2py_component_location else ''),
|
||||
' to view this content.',
|
||||
_class='not-authorized alert alert-block'))
|
||||
@@ -2030,7 +2025,7 @@ class Auth(object):
|
||||
if URL() == action:
|
||||
next = ''
|
||||
else:
|
||||
next = '?_next=' + urllib.quote(URL(args=request.args,
|
||||
next = '?_next=' + urllib_quote(URL(args=request.args,
|
||||
vars=request.get_vars))
|
||||
href = lambda function: \
|
||||
'%s/%s%s' % (action, function, next if referrer_actions is DEFAULT or function in referrer_actions else '')
|
||||
@@ -2046,7 +2041,7 @@ class Auth(object):
|
||||
if self.user_id: # User is logged in
|
||||
logout_next = self.settings.logout_next
|
||||
items.append({'name': T('Log Out'),
|
||||
'href': '%s/logout?_next=%s' % (action, urllib.quote(logout_next)),
|
||||
'href': '%s/logout?_next=%s' % (action, urllib_quote(logout_next)),
|
||||
'icon': 'icon-off'})
|
||||
if 'profile' not in self.settings.actions_disabled:
|
||||
items.append({'name': T('Profile'), 'href': href('profile'),
|
||||
@@ -2692,7 +2687,8 @@ class Auth(object):
|
||||
delattr(user, 'password')
|
||||
else:
|
||||
user = Row(user)
|
||||
for key, value in user.items():
|
||||
for key in list(user.keys()):
|
||||
value = user[key]
|
||||
if callable(value) or key == 'password':
|
||||
delattr(user, key)
|
||||
if self.settings.renew_session_onlogin:
|
||||
@@ -4284,7 +4280,7 @@ class Auth(object):
|
||||
next = self.here()
|
||||
current.session.flash = current.response.flash
|
||||
return call_or_redirect(self.settings.on_failed_authentication,
|
||||
self.settings.login_url + '?_next=' + urllib.quote(next))
|
||||
self.settings.login_url + '?_next=' + urllib_quote(next))
|
||||
|
||||
if callable(condition):
|
||||
flag = condition()
|
||||
@@ -5302,7 +5298,7 @@ regex_geocode = \
|
||||
|
||||
def geocode(address):
|
||||
try:
|
||||
a = urllib.quote(address)
|
||||
a = urllib_quote(address)
|
||||
txt = fetch('http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=%s' % a)
|
||||
item = regex_geocode.search(txt)
|
||||
(la, lo) = (float(item.group('la')), float(item.group('lo')))
|
||||
@@ -5322,10 +5318,10 @@ def reverse_geocode(lat, lng, lang=None):
|
||||
|
||||
|
||||
def universal_caller(f, *a, **b):
|
||||
c = f.func_code.co_argcount
|
||||
n = f.func_code.co_varnames[:c]
|
||||
c = f.__code__.co_argcount
|
||||
n = f.__code__.co_varnames[:c]
|
||||
|
||||
defaults = f.func_defaults or []
|
||||
defaults = f.__defaults__ or []
|
||||
pos_args = n[0:-len(defaults)]
|
||||
named_args = n[-len(defaults):]
|
||||
|
||||
@@ -5636,7 +5632,7 @@ class Service(object):
|
||||
import types
|
||||
r = universal_caller(self.run_procedures[args[0]],
|
||||
*args[1:], **dict(request.vars))
|
||||
s = cStringIO.StringIO()
|
||||
s = StringIO()
|
||||
if hasattr(r, 'export_to_csv_file'):
|
||||
r.export_to_csv_file(s)
|
||||
elif r and not isinstance(r, types.GeneratorType) and isinstance(r[0], (dict, Storage)):
|
||||
@@ -5747,7 +5743,7 @@ class Service(object):
|
||||
if hasattr(s, 'as_list'):
|
||||
s = s.as_list()
|
||||
return return_response(id, s)
|
||||
except Service.JsonRpcException, e:
|
||||
except Service.JsonRpcException as e:
|
||||
return return_error(id, e.code, e.info)
|
||||
except:
|
||||
etype, eval, etb = sys.exc_info()
|
||||
@@ -5828,7 +5824,7 @@ class Service(object):
|
||||
|
||||
try:
|
||||
must_respond = validate(data)
|
||||
except Service.JsonRpcException, e:
|
||||
except Service.JsonRpcException as e:
|
||||
return return_error(None, e.code, e.info)
|
||||
|
||||
id, method, params = data.get('id'), data['method'], data.get('params', '')
|
||||
@@ -5845,9 +5841,9 @@ class Service(object):
|
||||
return return_response(id, s)
|
||||
else:
|
||||
return ''
|
||||
except HTTP, e:
|
||||
except HTTP as e:
|
||||
raise e
|
||||
except Service.JsonRpcException, e:
|
||||
except Service.JsonRpcException as e:
|
||||
return return_error(id, e.code, e.info)
|
||||
except:
|
||||
etype, eval, etb = sys.exc_info()
|
||||
@@ -5909,7 +5905,7 @@ class Service(object):
|
||||
prefix='pys',
|
||||
documentation=documentation,
|
||||
ns=True)
|
||||
for method, (function, returns, args, doc) in procedures.iteritems():
|
||||
for method, (function, returns, args, doc) in iteritems(procedures):
|
||||
dispatcher.register_function(method, function, returns, args, doc)
|
||||
if request.env.request_method == 'POST':
|
||||
fault = {}
|
||||
@@ -7030,7 +7026,7 @@ class Config(object):
|
||||
section,
|
||||
default_values={}
|
||||
):
|
||||
self.config = ConfigParser.ConfigParser(default_values)
|
||||
self.config = configparser.ConfigParser(default_values)
|
||||
self.config.read(filename)
|
||||
if not self.config.has_section(section):
|
||||
self.config.add_section(section)
|
||||
@@ -7057,4 +7053,4 @@ class Config(object):
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
doctest.testmod()
|
||||
|
||||
Reference in New Issue
Block a user