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