updated user_agent_parser to 1.7.8, fix webclient
This commit is contained in:
@@ -23,7 +23,7 @@ try:
|
||||
if git.__version__ < '0.3.1':
|
||||
raise ImportError("Your version of git is %s. Upgrade to 0.3.1 or better." % git.__version__)
|
||||
have_git = True
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
have_git = False
|
||||
GIT_MISSING = 'Requires gitpython module, but not installed or incompatible version: %s' % e
|
||||
|
||||
@@ -123,6 +123,7 @@ def index():
|
||||
redirect(send)
|
||||
elif failed_login_count() >= allowed_number_of_attempts:
|
||||
time.sleep(2 ** allowed_number_of_attempts)
|
||||
print('4033')
|
||||
raise HTTP(403)
|
||||
elif request.vars.password:
|
||||
if verify_password(request.vars.password[:1024]):
|
||||
@@ -262,7 +263,7 @@ def site():
|
||||
new_repo = git.Repo.clone_from(form_update.vars.url, target)
|
||||
session.flash = T('new application "%s" imported',
|
||||
form_update.vars.name)
|
||||
except git.GitCommandError, err:
|
||||
except git.GitCommandError as err:
|
||||
session.flash = T('Invalid git repository specified.')
|
||||
redirect(URL(r=request))
|
||||
|
||||
@@ -272,7 +273,7 @@ def site():
|
||||
f = urllib.urlopen(form_update.vars.url)
|
||||
if f.code == 404:
|
||||
raise Exception("404 file not found")
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
session.flash = \
|
||||
DIV(T('Unable to download app because:'), PRE(repr(e)))
|
||||
redirect(URL(r=request))
|
||||
@@ -347,7 +348,7 @@ def pack():
|
||||
else:
|
||||
fname = 'web2py.app.%s.compiled.w2p' % app
|
||||
filename = app_pack_compiled(app, request, raise_ex=True)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
filename = None
|
||||
|
||||
if filename:
|
||||
@@ -421,7 +422,7 @@ def pack_custom():
|
||||
fname = 'web2py.app.%s.w2p' % app
|
||||
try:
|
||||
filename = app_pack(app, request, raise_ex=True, filenames=files)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
filename = None
|
||||
if filename:
|
||||
response.headers['Content-Type'] = 'application/w2p'
|
||||
@@ -732,7 +733,7 @@ def edit():
|
||||
try:
|
||||
code = request.vars.data.rstrip().replace('\r\n', '\n') + '\n'
|
||||
compile(code, path, "exec", _ast.PyCF_ONLY_AST)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
# offset calculation is only used for textarea (start/stop)
|
||||
start = sum([len(line) + 1 for l, line
|
||||
in enumerate(request.vars.data.split("\n"))
|
||||
@@ -757,11 +758,11 @@ def edit():
|
||||
# Lets try to reload the modules
|
||||
try:
|
||||
mopath = '.'.join(request.args[2:])[:-3]
|
||||
exec 'import applications.%s.modules.%s' % (
|
||||
request.args[0], mopath)
|
||||
exec('import applications.%s.modules.%s' % (
|
||||
request.args[0], mopath))
|
||||
reload(sys.modules['applications.%s.modules.%s'
|
||||
% (request.args[0], mopath)])
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
response.flash = DIV(
|
||||
T('failed to reload module because:'), PRE(repr(e)))
|
||||
|
||||
@@ -1468,7 +1469,7 @@ def create_file():
|
||||
redirect(URL('edit',
|
||||
args=[os.path.join(request.vars.location, filename)], vars=vars))
|
||||
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
if not isinstance(e, HTTP):
|
||||
session.flash = T('cannot create file')
|
||||
|
||||
@@ -1661,7 +1662,7 @@ def errors():
|
||||
pickel=error, causer=error_causer,
|
||||
last_line=last_line, hash=hash,
|
||||
ticket=fn.ticket_id)
|
||||
except AttributeError, e:
|
||||
except AttributeError as e:
|
||||
tk_db(tk_table.id == fn.id).delete()
|
||||
tk_db.commit()
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ if PY2:
|
||||
from string import maketrans
|
||||
from types import ClassType
|
||||
import cgi
|
||||
import cookielib
|
||||
reduce = reduce
|
||||
hashlib_md5 = hashlib.md5
|
||||
iterkeys = lambda d: d.iterkeys()
|
||||
@@ -94,6 +95,7 @@ else:
|
||||
from email.charset import Charset, add_charset, QP as charset_QP
|
||||
from urllib.request import FancyURLopener, urlopen
|
||||
from urllib.parse import quote as urllib_quote, unquote as urllib_unquote, urlencode
|
||||
from http import cookiejar as cookielib
|
||||
import html
|
||||
hashlib_md5 = lambda s: hashlib.md5(bytes(s, 'utf8'))
|
||||
iterkeys = lambda d: iter(d.keys())
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,11 +16,9 @@ mostly for testing purposes
|
||||
Some examples at the bottom.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from gluon._compat import urllib2, cookielib, iteritems, to_native, urlencode, to_bytes
|
||||
import re
|
||||
import time
|
||||
import urllib
|
||||
import urllib2
|
||||
import cookielib
|
||||
|
||||
|
||||
DEFAULT_HEADERS = {
|
||||
@@ -85,10 +83,10 @@ class WebClient(object):
|
||||
|
||||
# copy headers from dict to list of key,value
|
||||
headers_list = []
|
||||
for key, value in self.default_headers.iteritems():
|
||||
for key, value in iteritems(self.default_headers):
|
||||
if not key in headers:
|
||||
headers[key] = value
|
||||
for key, value in headers.iteritems():
|
||||
for key, value in iteritems(headers):
|
||||
if isinstance(value, (list, tuple)):
|
||||
for v in value:
|
||||
headers_list.append((key, v))
|
||||
@@ -96,7 +94,7 @@ class WebClient(object):
|
||||
headers_list.append((key, value))
|
||||
|
||||
# move cookies to headers
|
||||
for key, value in cookies.iteritems():
|
||||
for key, value in iteritems(cookies):
|
||||
headers_list.append(('Cookie', '%s=%s' % (key, value)))
|
||||
|
||||
# add headers to request
|
||||
@@ -120,24 +118,25 @@ class WebClient(object):
|
||||
data['_formkey'] = self.forms[data['_formname']]
|
||||
|
||||
# time the POST request
|
||||
data = urllib.urlencode(data, doseq=True)
|
||||
data = urlencode(data, doseq=True)
|
||||
else:
|
||||
self.method = 'GET' if method=='auto' else method
|
||||
data = None
|
||||
t0 = time.time()
|
||||
self.response = opener.open(self.url, data)
|
||||
self.response = opener.open(self.url, to_bytes(data))
|
||||
self.time = time.time() - t0
|
||||
except urllib2.HTTPError as error:
|
||||
except urllib2.HTTPError as er:
|
||||
error = er
|
||||
# catch HTTP errors
|
||||
self.time = time.time() - t0
|
||||
self.response = error
|
||||
self.response = er
|
||||
|
||||
if hasattr(self.response, 'getcode'):
|
||||
self.status = self.response.getcode()
|
||||
else:#python2.5
|
||||
self.status = None
|
||||
|
||||
self.text = self.response.read()
|
||||
self.text = to_native(self.response.read())
|
||||
self.headers = dict(self.response.headers)
|
||||
|
||||
# treat web2py tickets as special types of errors
|
||||
@@ -147,6 +146,9 @@ class WebClient(object):
|
||||
else:
|
||||
raise error
|
||||
|
||||
if 'Set-Cookie' in self.headers: #PY3
|
||||
self.headers['set-cookie'] = self.headers['Set-Cookie']
|
||||
|
||||
# parse headers into cookies
|
||||
self.cookies = {}
|
||||
if 'set-cookie' in self.headers:
|
||||
@@ -156,7 +158,7 @@ class WebClient(object):
|
||||
|
||||
# check is a new session id has been issued, symptom of broken session
|
||||
if self.session_regex is not None:
|
||||
for cookie, value in self.cookies.iteritems():
|
||||
for cookie, value in iteritems(self.cookies):
|
||||
match = self.session_regex.match(cookie)
|
||||
if match:
|
||||
name = match.group('name')
|
||||
@@ -166,7 +168,7 @@ class WebClient(object):
|
||||
|
||||
# find all forms and formkeys in page
|
||||
self.forms = {}
|
||||
for match in FORM_REGEX.finditer(self.text):
|
||||
for match in FORM_REGEX.finditer(to_native(self.text)):
|
||||
self.forms[match.group('formname')] = match.group('formkey')
|
||||
|
||||
# log this request
|
||||
|
||||
Reference in New Issue
Block a user