updated imports in tests

This commit is contained in:
ilvalle
2016-06-02 14:28:21 +02:00
parent 01bab81432
commit a1fd92b7f8
45 changed files with 182 additions and 169 deletions
+1
View File
@@ -48,6 +48,7 @@ applications/*/sessions/*
applications/*/errors/* applications/*/errors/*
applications/*/cache/* applications/*/cache/*
applications/*/uploads/* applications/*/uploads/*
applications/*/private/*
applications/*/*.py[oc] applications/*/*.py[oc]
applications/*/static/temp applications/*/static/temp
applications/*/progress.log applications/*/progress.log
+2 -2
View File
@@ -267,7 +267,7 @@ def select():
else: else:
rows = db(query, ignore_common_filters=True).select( rows = db(query, ignore_common_filters=True).select(
*fields, limitby=(start, stop)) *fields, limitby=(start, stop))
except Exception, e: except Exception as e:
import traceback import traceback
tb = traceback.format_exc() tb = traceback.format_exc()
(rows, nrows) = ([], 0) (rows, nrows) = ([], 0)
@@ -286,7 +286,7 @@ def select():
import_csv(db[request.vars.table], import_csv(db[request.vars.table],
request.vars.csvfile.file) request.vars.csvfile.file)
response.flash = T('data uploaded') response.flash = T('data uploaded')
except Exception, e: except Exception as e:
response.flash = DIV(T('unable to parse csv file'), PRE(str(e))) response.flash = DIV(T('unable to parse csv file'), PRE(str(e)))
# end handle upload csv # end handle upload csv
+17
View File
@@ -17,6 +17,13 @@ if PY2:
import thread import thread
import Cookie import Cookie
import urllib2 import urllib2
import Queue
import ConfigParser as configparser
from email.MIMEBase import MIMEBase
from email.Header import Header
from email import MIMEMultipart, MIMEText, Encoders, Charset
from urllib import FancyURLopener
from urllib import quote as urllib_quote, unquote as urllib_unquote
reduce = reduce reduce = reduce
hashlib_md5 = hashlib.md5 hashlib_md5 = hashlib.md5
iterkeys = lambda d: d.iterkeys() iterkeys = lambda d: d.iterkeys()
@@ -67,6 +74,16 @@ else:
from html.entities import entitydefs, name2codepoint from html.entities import entitydefs, name2codepoint
import builtins as builtin import builtins as builtin
import _thread as thread import _thread as thread
import configparser
import queue as Queue
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email import encoders as Encoders
from email.header import Header
from email.charset import Charset
from urllib.request import FancyURLopener
from urllib.parse import quote as urllib_quote, unquote as urllib_unquote
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())
itervalues = lambda d: iter(d.values()) itervalues = lambda d: iter(d.values())
+1 -1
View File
@@ -155,7 +155,7 @@ class CacheAbstract(object):
Auxiliary function called by `clear` to search and clear cache entries Auxiliary function called by `clear` to search and clear cache entries
""" """
r = re.compile(regex) r = re.compile(regex)
for key in storage.keys(): for key in list(storage.keys()):
if r.match(str(key)): if r.match(str(key)):
del storage[key] del storage[key]
return return
+3 -2
View File
@@ -42,6 +42,7 @@ revision3.com
viddler.com viddler.com
""" """
from __future__ import print_function from __future__ import print_function
from gluon._compat import FancyURLopener, urllib_quote
import re import re
import cgi import cgi
@@ -94,7 +95,7 @@ def video(url):
def googledoc_viewer(url): def googledoc_viewer(url):
return '<iframe src="https://docs.google.com/viewer?url=%s&embedded=true" style="max-width:100%%"></iframe>' % urllib.quote(url) return '<iframe src="https://docs.google.com/viewer?url=%s&embedded=true" style="max-width:100%%"></iframe>' % urllib_quote(url)
def web2py_component(url): def web2py_component(url):
@@ -136,7 +137,7 @@ EXTENSION_MAPS = {
} }
class VimeoURLOpener(urllib.FancyURLopener): class VimeoURLOpener(FancyURLopener):
"Vimeo blocks the urllib user agent for some reason" "Vimeo blocks the urllib user agent for some reason"
version = "Mozilla/4.0" version = "Mozilla/4.0"
urllib._urlopener = VimeoURLOpener() urllib._urlopener = VimeoURLOpener()
+2 -2
View File
@@ -7,7 +7,7 @@ from __future__ import print_function
import re import re
import urllib import urllib
from cgi import escape from cgi import escape
from string import maketrans from gluon._compat import maketrans, urllib_quote
try: try:
from ast import parse as ast_parse from ast import parse as ast_parse
@@ -1418,7 +1418,7 @@ def render(text,
return '[' + ','.join('<a href="#%s" class="%s">%s</a>' % return '[' + ','.join('<a href="#%s" class="%s">%s</a>' %
(id_prefix + d, b, d) for d in escape(code).split(',')) + ']' (id_prefix + d, b, d) for d in escape(code).split(',')) + ']'
elif b == 'latex': elif b == 'latex':
return LATEX % urllib.quote(code) return LATEX % urllib_quote(code)
elif b in html_colors: elif b in html_colors:
return '<span style="color: %s">%s</span>' \ return '<span style="color: %s">%s</span>' \
% (b, render(code, {}, {}, 'br', URL, environment, latex, % (b, render(code, {}, {}, 'br', URL, environment, latex,
+5 -5
View File
@@ -13,7 +13,7 @@ Contains the classes for the global used variables:
- Session - Session
""" """
from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2 from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2, iteritems
from gluon.storage import Storage, List from gluon.storage import Storage, List
from gluon.streamer import streamer, stream_file_or_304_or_206, DEFAULT_CHUNK_SIZE from gluon.streamer import streamer, stream_file_or_304_or_206, DEFAULT_CHUNK_SIZE
from gluon.contenttype import contenttype from gluon.contenttype import contenttype
@@ -198,7 +198,7 @@ class Request(Storage):
query_string = self.env.get('query_string', '') query_string = self.env.get('query_string', '')
dget = urlparse.parse_qs(query_string, keep_blank_values=1) # Ref: https://docs.python.org/2/library/cgi.html#cgi.parse_qs dget = urlparse.parse_qs(query_string, keep_blank_values=1) # Ref: https://docs.python.org/2/library/cgi.html#cgi.parse_qs
get_vars = self._get_vars = Storage(dget) get_vars = self._get_vars = Storage(dget)
for (key, value) in get_vars.iteritems(): for (key, value) in iteritems(get_vars):
if isinstance(value, list) and len(value) == 1: if isinstance(value, list) and len(value) == 1:
get_vars[key] = value[0] get_vars[key] = value[0]
@@ -272,7 +272,7 @@ class Request(Storage):
"""Merges get_vars and post_vars to vars """Merges get_vars and post_vars to vars
""" """
self._vars = copy.copy(self.get_vars) self._vars = copy.copy(self.get_vars)
for key, value in self.post_vars.iteritems(): for key, value in iteritems(self.post_vars):
if key not in self._vars: if key not in self._vars:
self._vars[key] = value self._vars[key] = value
else: else:
@@ -448,7 +448,7 @@ class Response(Storage):
def include_meta(self): def include_meta(self):
s = "\n" s = "\n"
for meta in (self.meta or {}).iteritems(): for meta in iteritems((self.meta or {})):
k, v = meta k, v = meta
if isinstance(v, dict): if isinstance(v, dict):
s += '<meta' + ''.join(' %s="%s"' % (xmlescape(key), xmlescape(v[key])) for key in v) +' />\n' s += '<meta' + ''.join(' %s="%s"' % (xmlescape(key), xmlescape(v[key])) for key in v) +' />\n'
@@ -680,7 +680,7 @@ class Response(Storage):
dbstats = [] dbstats = []
dbtables = {} dbtables = {}
infos = DAL.get_instances() infos = DAL.get_instances()
for k, v in infos.iteritems(): for k, v in iteritems(infos):
dbstats.append(TABLE(*[TR(PRE(row[0]), '%.2fms' % (row[1]*1000)) dbstats.append(TABLE(*[TR(PRE(row[0]), '%.2fms' % (row[1]*1000))
for row in v['dbstats']])) for row in v['dbstats']]))
dbtables[k] = dict(defined=v['dbtables']['defined'] or '[no defined tables]', dbtables[k] = dict(defined=v['dbtables']['defined'] or '[no defined tables]',
+18 -18
View File
@@ -20,7 +20,7 @@ import urllib
import base64 import base64
from gluon import sanitizer, decoder from gluon import sanitizer, decoder
import itertools import itertools
from gluon._compat import reduce, pickle, copyreg, HTMLParser, name2codepoint, iteritems, unichr, unicodeT from gluon._compat import reduce, pickle, copyreg, HTMLParser, name2codepoint, iteritems, unichr, unicodeT, urllib_quote
import marshal import marshal
from gluon.storage import Storage from gluon.storage import Storage
@@ -252,7 +252,7 @@ def URL(a=None,
'/a/c/f#%25%28id%29d' '/a/c/f#%25%28id%29d'
""" """
from rewrite import url_out # done here in case used not-in web2py from gluon.rewrite import url_out # done here in case used not-in web2py
if args in (None, []): if args in (None, []):
args = [] args = []
@@ -269,7 +269,7 @@ def URL(a=None,
(f, a, c) = (a, c, f) (f, a, c) = (a, c, f)
elif a and c and not f: elif a and c and not f:
(c, f, a) = (a, c, f) (c, f, a) = (a, c, f)
from globals import current from gluon.globals import current
if hasattr(current, 'request'): if hasattr(current, 'request'):
r = current.request r = current.request
@@ -304,7 +304,7 @@ def URL(a=None,
if controller == 'static': if controller == 'static':
extension = None extension = None
# add static version to url # add static version to url
from globals import current from gluon.globals import current
if hasattr(current, 'response'): if hasattr(current, 'response'):
response = current.response response = current.response
if response.static_version and response.static_version_urls: if response.static_version and response.static_version_urls:
@@ -322,9 +322,9 @@ def URL(a=None,
if args: if args:
if url_encode: if url_encode:
if encode_embedded_slash: if encode_embedded_slash:
other = '/' + '/'.join([urllib.quote(str(x), '') for x in args]) other = '/' + '/'.join([urllib_quote(str(x), '') for x in args])
else: else:
other = args and urllib.quote('/' + '/'.join([str(x) for x in args])) other = args and urllib_quote('/' + '/'.join([str(x) for x in args]))
else: else:
other = args and ('/' + '/'.join([str(x) for x in args])) other = args and ('/' + '/'.join([str(x) for x in args]))
else: else:
@@ -377,7 +377,7 @@ def URL(a=None,
other += '?%s' % '&'.join(['%s=%s' % var[:2] for var in list_vars]) other += '?%s' % '&'.join(['%s=%s' % var[:2] for var in list_vars])
if anchor: if anchor:
if url_encode: if url_encode:
other += '#' + urllib.quote(str(anchor)) other += '#' + urllib_quote(str(anchor))
else: else:
other += '#' + (str(anchor)) other += '#' + (str(anchor))
if extension: if extension:
@@ -451,7 +451,7 @@ def verifyURL(request, hmac_key=None, hash_vars=True, salt=None, user_signature=
# join all the args & vars into one long string # join all the args & vars into one long string
# always include all of the args # always include all of the args
other = args and urllib.quote('/' + '/'.join([str(x) for x in args])) or '' other = args and urllib_quote('/' + '/'.join([str(x) for x in args])) or ''
h_args = '/%s/%s/%s.%s%s' % (request.application, h_args = '/%s/%s/%s.%s%s' % (request.application,
request.controller, request.controller,
request.function, request.function,
@@ -723,7 +723,7 @@ class DIV(XmlComponent):
dictionary like updating of the tag attributes dictionary like updating of the tag attributes
""" """
for (key, value) in kargs.iteritems(): for (key, value) in iteritems(kargs):
self[key] = value self[key] = value
return self return self
@@ -924,7 +924,7 @@ class DIV(XmlComponent):
# get the attributes for this component # get the attributes for this component
# (they start with '_', others may have special meanings) # (they start with '_', others may have special meanings)
attr = [] attr = []
for key, value in self.attributes.iteritems(): for key, value in iteritems(self.attributes):
if key[:1] != '_': if key[:1] != '_':
continue continue
name = key[1:] name = key[1:]
@@ -934,7 +934,7 @@ class DIV(XmlComponent):
continue continue
attr.append((name, value)) attr.append((name, value))
data = self.attributes.get('data', {}) data = self.attributes.get('data', {})
for key, value in data.iteritems(): for key, value in iteritems(data):
name = 'data-' + key name = 'data-' + key
value = data[key] value = data[key]
attr.append((name, value)) attr.append((name, value))
@@ -1127,7 +1127,7 @@ class DIV(XmlComponent):
# value as provided # value as provided
tag = getattr(self, 'tag').replace('/', '') tag = getattr(self, 'tag').replace('/', '')
check = not (args and tag not in args) check = not (args and tag not in args)
for (key, value) in kargs.iteritems(): for (key, value) in iteritems(kargs):
if key not in ['first_only', 'replace', 'find_text']: if key not in ['first_only', 'replace', 'find_text']:
if isinstance(value, (str, int)): if isinstance(value, (str, int)):
if str(self[key]) != str(value): if str(self[key]) != str(value):
@@ -1211,7 +1211,7 @@ class DIV(XmlComponent):
tag = getattr(c, 'tag').replace("/", "") tag = getattr(c, 'tag').replace("/", "")
if args and tag not in args: if args and tag not in args:
check = False check = False
for (key, value) in kargs.iteritems(): for (key, value) in iteritems(kargs):
if c[key] != value: if c[key] != value:
check = False check = False
if check: if check:
@@ -2158,7 +2158,7 @@ class FORM(DIV):
c = [] c = []
attr = self.attributes.get('hidden', {}) attr = self.attributes.get('hidden', {})
if 'hidden' in self.attributes: if 'hidden' in self.attributes:
c = [INPUT(_type='hidden', _name=key, _value=value) for (key, value) in attr.iteritems()] c = [INPUT(_type='hidden', _name=key, _value=value) for (key, value) in iteritems(attr)]
if hasattr(self, 'formkey') and self.formkey: if hasattr(self, 'formkey') and self.formkey:
c.append(INPUT(_type='hidden', _name='_formkey', _value=self.formkey)) c.append(INPUT(_type='hidden', _name='_formkey', _value=self.formkey))
if hasattr(self, 'formname') and self.formname: if hasattr(self, 'formname') and self.formname:
@@ -2235,9 +2235,9 @@ class FORM(DIV):
onsuccess(self) onsuccess(self)
if next: if next:
if self.vars: if self.vars:
for key, value in self.vars.iteritems(): for key, value in iteritems(self.vars):
next = next.replace('[%s]' % key, next = next.replace('[%s]' % key,
urllib.quote(str(value))) urllib_quote(str(value)))
if not next.startswith('/'): if not next.startswith('/'):
next = URL(next) next = URL(next)
redirect(next) redirect(next)
@@ -2309,11 +2309,11 @@ class FORM(DIV):
inputs = [INPUT(_type='button', inputs = [INPUT(_type='button',
_value=name, _value=name,
_onclick=FORM.REDIRECT_JS % link) _onclick=FORM.REDIRECT_JS % link)
for name, link in buttons.iteritems()] for name, link in iteritems(buttons)]
inputs += [INPUT(_type='hidden', inputs += [INPUT(_type='hidden',
_name=name, _name=name,
_value=value) _value=value)
for name, value in hidden.iteritems()] for name, value in iteritems(hidden)]
form = FORM(INPUT(_type='submit', _value=text), *inputs) form = FORM(INPUT(_type='submit', _value=text), *inputs)
form.process() form.process()
return form return form
+6 -6
View File
@@ -18,7 +18,7 @@ import pkgutil
import logging import logging
from cgi import escape from cgi import escape
from threading import RLock from threading import RLock
from gluon._compat import copyreg, PY2, maketrans from gluon._compat import copyreg, PY2, maketrans, iterkeys, unicodeT, to_unicode
from gluon.portalocker import read_locked, LockedFile from gluon.portalocker import read_locked, LockedFile
from gluon.utf8 import Utf8 from gluon.utf8 import Utf8
@@ -334,7 +334,7 @@ def write_dict(filename, contents):
try: try:
fp = LockedFile(filename, 'w') fp = LockedFile(filename, 'w')
fp.write('# -*- coding: utf-8 -*-\n{\n') fp.write('# -*- coding: utf-8 -*-\n{\n')
for key in sorted(contents, sort_function): for key in sorted(contents, key=lambda x: to_unicode(x, 'utf-8').lower()):
fp.write('%s: %s,\n' % (repr(Utf8(key)), fp.write('%s: %s,\n' % (repr(Utf8(key)),
repr(Utf8(contents[key])))) repr(Utf8(contents[key]))))
fp.write('}\n') fp.write('}\n')
@@ -541,7 +541,7 @@ class translator(object):
def get_possible_languages(self): def get_possible_languages(self):
""" Gets list of all possible languages for current application """ """ Gets list of all possible languages for current application """
return list(set(self.current_languages + return list(set(self.current_languages +
[lang for lang in read_possible_languages(self.langpath).iterkeys() [lang for lang in iterkeys(read_possible_languages(self.langpath))
if lang != 'default'])) if lang != 'default']))
def set_current_languages(self, *languages): def set_current_languages(self, *languages):
@@ -658,7 +658,7 @@ class translator(object):
languages = [] languages = []
self.requested_languages = languages = tuple(languages) self.requested_languages = languages = tuple(languages)
if languages: if languages:
all_languages = set(lang for lang in pl_info.iterkeys() all_languages = set(lang for lang in iterkeys(pl_info)
if lang != 'default') \ if lang != 'default') \
| set(self.current_languages) | set(self.current_languages)
for lang in languages: for lang in languages:
@@ -800,9 +800,9 @@ class translator(object):
the ## notation is ignored in multiline strings and strings that the ## notation is ignored in multiline strings and strings that
start with ##. This is needed to allow markmin syntax to be translated start with ##. This is needed to allow markmin syntax to be translated
""" """
if isinstance(message, unicode): if isinstance(message, unicodeT):
message = message.encode('utf8') message = message.encode('utf8')
if isinstance(prefix, unicode): if isinstance(prefix, unicodeT):
prefix = prefix.encode('utf8') prefix = prefix.encode('utf8')
key = prefix + message key = prefix + message
mt = self.t.get(key, None) mt = self.t.get(key, None)
+2 -2
View File
@@ -10,7 +10,7 @@ Generates names for cache and session files
-------------------------------------------- --------------------------------------------
""" """
import os import os
from gluon._compat import builtin
def generate(filename, depth=2, base=512): def generate(filename, depth=2, base=512):
if os.path.sep in filename: if os.path.sep in filename:
@@ -62,4 +62,4 @@ def open(filename, mode="r", path=None):
fullfilename = os.path.join(path, generate(filename)) fullfilename = os.path.join(path, generate(filename))
if mode.startswith('w') and not os.path.exists(os.path.dirname(fullfilename)): if mode.startswith('w') and not os.path.exists(os.path.dirname(fullfilename)):
os.makedirs(os.path.dirname(fullfilename)) os.makedirs(os.path.dirname(fullfilename))
return file(fullfilename, mode) return builtin.open(fullfilename, mode)
+4 -3
View File
@@ -27,6 +27,7 @@ from gluon.storage import Storage, List
from gluon.http import HTTP from gluon.http import HTTP
from gluon.fileutils import abspath, read_file from gluon.fileutils import abspath, read_file
from gluon.settings import global_settings from gluon.settings import global_settings
from gluon._compat import urllib_unquote, urllib_quote
isdir = os.path.isdir isdir = os.path.isdir
isfile = os.path.isfile isfile = os.path.isfile
@@ -625,7 +626,7 @@ def regex_url_in(request, environ):
# serve if a static file # serve if a static file
# ################################################## # ##################################################
path = urllib.unquote(request.env.path_info) or '/' path = urllib_unquote(request.env.path_info) or '/'
path = path.replace('\\', '/') path = path.replace('\\', '/')
if path.endswith('/') and len(path) > 1: if path.endswith('/') and len(path) > 1:
path = path[:-1] path = path[:-1]
@@ -715,7 +716,7 @@ def filter_url(url, method='get', remote='0.0.0.0',
if isinstance(domain, str): if isinstance(domain, str):
domain = (domain, None) domain = (domain, None)
(path_info, query_string) = (uri[:k], uri[k + 1:]) (path_info, query_string) = (uri[:k], uri[k + 1:])
path_info = urllib.unquote(path_info) # simulate server path_info = urllib_unquote(path_info) # simulate server
e = { e = {
'REMOTE_ADDR': remote, 'REMOTE_ADDR': remote,
'REQUEST_METHOD': method, 'REQUEST_METHOD': method,
@@ -1100,7 +1101,7 @@ class MapUrlIn(object):
uri = '/%s%s%s%s' % ( uri = '/%s%s%s%s' % (
app, app,
uri, uri,
urllib.quote('/' + '/'.join( urllib_quote('/' + '/'.join(
str(x) for x in self.args)) if self.args else '', str(x) for x in self.args)) if self.args else '',
('?' + self.query) if self.query else '') ('?' + self.query) if self.query else '')
self.env['REQUEST_URI'] = uri self.env['REQUEST_URI'] = uri
+2 -2
View File
@@ -9,7 +9,7 @@ Background processes made simple
--------------------------------- ---------------------------------
""" """
from __future__ import print_function from __future__ import print_function
from gluon._compat import Queue
import os import os
import time import time
@@ -24,7 +24,7 @@ import logging
import optparse import optparse
import tempfile import tempfile
import types import types
import Queue
from json import loads, dumps from json import loads, dumps
from gluon import DAL, Field, IS_NOT_EMPTY, IS_IN_SET, IS_NOT_IN_DB from gluon import DAL, Field, IS_NOT_EMPTY, IS_IN_SET, IS_NOT_IN_DB
from gluon import IS_INT_IN_RANGE, IS_DATETIME, IS_IN_DB from gluon import IS_INT_IN_RANGE, IS_DATETIME, IS_IN_DB
+3 -3
View File
@@ -19,7 +19,7 @@ import urllib
import re import re
import os import os
from gluon._compat import StringIO, unichr from gluon._compat import StringIO, unichr, urllib_quote
from gluon.http import HTTP, redirect from gluon.http import HTTP, redirect
from gluon.html import XmlComponent, truncate_string from gluon.html import XmlComponent, truncate_string
from gluon.html import XML, SPAN, TAG, A, DIV, CAT, UL, LI, TEXTAREA, BR, IMG from gluon.html import XML, SPAN, TAG, A, DIV, CAT, UL, LI, TEXTAREA, BR, IMG
@@ -1329,10 +1329,10 @@ class SQLFORM(FORM):
db = linkto.split('/')[-1] db = linkto.split('/')[-1]
for rfld in table._referenced_by: for rfld in table._referenced_by:
if keyed: if keyed:
query = urllib.quote('%s.%s==%s' % ( query = urllib_quote('%s.%s==%s' % (
db, rfld, record[rfld.type[10:].split('.')[1]])) db, rfld, record[rfld.type[10:].split('.')[1]]))
else: else:
query = urllib.quote( query = urllib_quote(
'%s.%s==%s' % (db, rfld, record[self.id_field_name])) '%s.%s==%s' % (db, rfld, record[self.id_field_name]))
lname = olname = '%s.%s' % (rfld.tablename, rfld.name) lname = olname = '%s.%s' % (rfld.tablename, rfld.name)
if ofields and olname not in ofields: if ofields and olname not in ofields:
+1 -1
View File
@@ -307,7 +307,7 @@ class List(list):
if not value and otherwise: if not value and otherwise:
raise ValueError('Otherwise will raised.') raise ValueError('Otherwise will raised.')
except (ValueError, TypeError): except (ValueError, TypeError):
from http import HTTP, redirect from gluon.http import HTTP, redirect
if otherwise is None: if otherwise is None:
raise HTTP(404) raise HTTP(404)
elif isinstance(otherwise, str): elif isinstance(otherwise, str):
+5 -9
View File
@@ -18,10 +18,7 @@ import os
import cgi import cgi
import logging import logging
from re import compile, sub, escape, DOTALL from re import compile, sub, escape, DOTALL
try: from gluon._compat import StringIO
import cStringIO as StringIO
except:
from io import StringIO
try: try:
# have web2py # have web2py
@@ -279,13 +276,12 @@ class TemplateParser(object):
self.context = context self.context = context
# allow optional alternative delimiters # allow optional alternative delimiters
if delimiters != self.default_delimiters: if delimiters != self.default_delimiters:
escaped_delimiters = (escape(delimiters[0]), escaped_delimiters = (escape(delimiters[0]),
escape(delimiters[1])) escape(delimiters[1]))
self.r_tag = compile(r'(%s.*?%s)' % escaped_delimiters, DOTALL) self.r_tag = compile(r'(%s.*?%s)' % escaped_delimiters, DOTALL)
elif hasattr(context.get('response', None), 'delimiters'): elif hasattr(context.get('response', None), 'delimiters'):
if context['response'].delimiters != self.default_delimiters: if (context['response'].delimiters != self.default_delimiters) and (context['response'].delimiters != None):
delimiters = context['response'].delimiters delimiters = context['response'].delimiters
escaped_delimiters = ( escaped_delimiters = (
escape(delimiters[0]), escape(delimiters[0]),
@@ -807,7 +803,7 @@ def get_parsed(text):
class DummyResponse(): class DummyResponse():
def __init__(self): def __init__(self):
self.body = StringIO.StringIO() self.body = StringIO()
def write(self, data, escape=True): def write(self, data, escape=True):
if not escape: if not escape:
@@ -904,7 +900,7 @@ def render(content="hello world",
# save current response class # save current response class
if context and 'response' in context: if context and 'response' in context:
old_response_body = context['response'].body old_response_body = context['response'].body
context['response'].body = StringIO.StringIO() context['response'].body = StringIO()
else: else:
old_response_body = None old_response_body = None
context['response'] = Response() context['response'] = Response()
@@ -921,7 +917,7 @@ def render(content="hello world",
stream = open(filename, 'rb') stream = open(filename, 'rb')
close_stream = True close_stream = True
elif content: elif content:
stream = StringIO.StringIO(content) stream = StringIO(content)
# Execute the template. # Execute the template.
code = str(TemplateParser(stream.read( code = str(TemplateParser(stream.read(
+3 -3
View File
@@ -17,12 +17,12 @@ from .test_serializers import *
from .test_template import * from .test_template import *
from .test_validators import * from .test_validators import *
from .test_utils import * from .test_utils import *
from .test_contribs import *
from .test_web import *
from .test_dal import * from .test_dal import *
from .test_tools import * from .test_tools import *
from .test_appadmin import * from .test_appadmin import *
from .test_scheduler import * from .test_scheduler import *
if sys.version[:3] == '2.7': if sys.version[:3] == '2.7':
from test_old_doctests import * from .test_web import *
from .test_contribs import *
from .test_old_doctests import *
+8 -8
View File
@@ -10,15 +10,15 @@ import sys
import unittest import unittest
import json import json
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from compileapp import run_controller_in, run_view_in from gluon.compileapp import run_controller_in, run_view_in
from languages import translator from gluon.languages import translator
from gluon.storage import Storage, List from gluon.storage import Storage, List
import gluon.fileutils from gluon import fileutils
from gluon.dal import DAL, Field, Table from gluon.dal import DAL, Field, Table
from gluon.http import HTTP from gluon.http import HTTP
@@ -36,13 +36,13 @@ class TestAppAdmin(unittest.TestCase):
from gluon.globals import Request, Response, Session, current from gluon.globals import Request, Response, Session, current
from gluon.html import A, DIV, FORM, MENU, TABLE, TR, INPUT, URL, XML from gluon.html import A, DIV, FORM, MENU, TABLE, TR, INPUT, URL, XML
from gluon.validators import IS_NOT_EMPTY from gluon.validators import IS_NOT_EMPTY
from compileapp import LOAD from gluon.compileapp import LOAD
from gluon.http import HTTP, redirect from gluon.http import HTTP, redirect
from gluon.tools import Auth from gluon.tools import Auth
from gluon.sql import SQLDB from gluon.sql import SQLDB
from gluon.sqlhtml import SQLTABLE, SQLFORM from gluon.sqlhtml import SQLTABLE, SQLFORM
self.original_check_credentials = gluon.fileutils.check_credentials self.original_check_credentials = fileutils.check_credentials
gluon.fileutils.check_credentials = fake_check_credentials fileutils.check_credentials = fake_check_credentials
request = Request(env={}) request = Request(env={})
request.application = 'welcome' request.application = 'welcome'
request.controller = 'appadmin' request.controller = 'appadmin'
@@ -73,7 +73,7 @@ class TestAppAdmin(unittest.TestCase):
self.env = locals() self.env = locals()
def tearDown(self): def tearDown(self):
gluon.fileutils.check_credentials = self.original_check_credentials fileutils.check_credentials = self.original_check_credentials
def run_function(self): def run_function(self):
return run_controller_in(self.env['request'].controller, self.env['request'].function, self.env) return run_controller_in(self.env['request'].controller, self.env['request'].function, self.env)
+3 -3
View File
@@ -6,13 +6,13 @@
""" """
import os import os
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from storage import Storage from gluon.storage import Storage
from cache import CacheInRam, CacheOnDisk, Cache from gluon.cache import CacheInRam, CacheOnDisk, Cache
from gluon.dal import DAL, Field from gluon.dal import DAL, Field
oldcwd = None oldcwd = None
+2 -2
View File
@@ -4,11 +4,11 @@
""" Unit tests for utils.py """ """ Unit tests for utils.py """
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from compileapp import compile_application, remove_compiled_application from gluon.compileapp import compile_application, remove_compiled_application
from gluon.fileutils import w2p_pack, w2p_unpack from gluon.fileutils import w2p_pack, w2p_unpack
import os import os
+4 -4
View File
@@ -6,12 +6,12 @@
""" """
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from contenttype import contenttype from gluon.contenttype import contenttype
from gluon._compat import iteritems
class TestContentType(unittest.TestCase): class TestContentType(unittest.TestCase):
@@ -31,7 +31,7 @@ class TestContentType(unittest.TestCase):
'.w2p': 'application/w2p', '.w2p': 'application/w2p',
'.md': 'text/x-markdown; charset=utf-8' '.md': 'text/x-markdown; charset=utf-8'
} }
for k, v in mapping.iteritems(): for k, v in iteritems(mapping):
self.assertEqual(contenttype(k), v) self.assertEqual(contenttype(k), v)
# test without dot extension # test without dot extension
+3 -3
View File
@@ -5,13 +5,13 @@
import unittest import unittest
import os import os
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from gluon.storage import Storage from gluon.storage import Storage
import gluon.contrib.fpdf as fpdf from gluon.contrib import fpdf as fpdf
import gluon.contrib.pyfpdf as pyfpdf from gluon.contrib import pyfpdf as pyfpdf
from gluon.contrib.appconfig import AppConfig from gluon.contrib.appconfig import AppConfig
+1 -1
View File
@@ -7,7 +7,7 @@
import sys import sys
import os import os
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
+2 -2
View File
@@ -3,11 +3,11 @@
import unittest import unittest
import datetime import datetime
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from fileutils import parse_version from gluon.fileutils import parse_version
class TestFileUtils(unittest.TestCase): class TestFileUtils(unittest.TestCase):
+1 -1
View File
@@ -8,7 +8,7 @@
import re import re
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
+13 -10
View File
@@ -6,16 +6,17 @@
""" """
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from html import * from gluon.html import A, ASSIGNJS, B, BEAUTIFY, P, BODY, BR, BUTTON, CAT, CENTER, CODE, COL, COLGROUP, DIV, SPAN, URL, verifyURL
from html import verifyURL from gluon.html import truncate_string, EM, FIELDSET, FORM, H1, H2, H3, H4, H5, H6, HEAD, HR, HTML, I, IFRAME, IMG, INPUT, EMBED
from html import truncate_string from gluon.html import LABEL, LEGEND, LI, LINK, MARKMIN, MENU, META, OBJECT, OL, OPTGROUP, OPTION, PRE, SCRIPT, SELECT, STRONG
from storage import Storage from gluon.html import STYLE, TABLE, TR, TD, TAG, TBODY, THEAD, TEXTAREA, TFOOT, TH, TITLE, TT, UL, XHTML, XML
from html import XML_pickle, XML_unpickle from gluon.storage import Storage
from html import TAG_pickler, TAG_unpickler from gluon.html import XML_pickle, XML_unpickle
from gluon.html import TAG_pickler, TAG_unpickler
class TestBareHelpers(unittest.TestCase): class TestBareHelpers(unittest.TestCase):
@@ -41,7 +42,7 @@ class TestBareHelpers(unittest.TestCase):
self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/design.css') self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/design.css')
response = Storage() response = Storage()
response.static_version = '1.2.3' response.static_version = '1.2.3'
from globals import current from gluon.globals import current
current.response = response current.response = response
self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/design.css') self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/design.css')
response.static_version_urls = True response.static_version_urls = True
@@ -53,6 +54,8 @@ class TestBareHelpers(unittest.TestCase):
self.assertEqual(URL('a', 'c', 'f', args=['1', '2']), '/a/c/f/1/2') self.assertEqual(URL('a', 'c', 'f', args=['1', '2']), '/a/c/f/1/2')
self.assertEqual(URL('a', 'c', '/f'), '/a/c/f') self.assertEqual(URL('a', 'c', '/f'), '/a/c/f')
self.assertEqual(URL('a', 'c', 'f.json'), '/a/c/f.json') self.assertEqual(URL('a', 'c', 'f.json'), '/a/c/f.json')
from gluon.globals import current
current.request = None
self.assertRaises(SyntaxError, URL, *['a']) self.assertRaises(SyntaxError, URL, *['a'])
request = Storage() request = Storage()
@@ -61,7 +64,7 @@ class TestBareHelpers(unittest.TestCase):
request.function = 'f' request.function = 'f'
request.env = {} request.env = {}
from globals import current # Can't be moved with other import from gluon.globals import current # Can't be moved with other import
current.request = request current.request = request
must_return = '/a/c/f' must_return = '/a/c/f'
@@ -144,7 +147,7 @@ class TestBareHelpers(unittest.TestCase):
rtn = verifyURL(r) rtn = verifyURL(r)
self.assertEqual(rtn, False) self.assertEqual(rtn, False)
# emulate user signature # emulate user signature
from globals import current from gluon.globals import current
current.session = Storage(auth=Storage(hmac_key='key')) current.session = Storage(auth=Storage(hmac_key='key'))
r.get_vars['_signature'] = 'a32530f0d0caa80964bb92aad2bedf8a4486a31f' r.get_vars['_signature'] = 'a32530f0d0caa80964bb92aad2bedf8a4486a31f'
rtn = verifyURL(r, user_signature=True) rtn = verifyURL(r, user_signature=True)
+2 -2
View File
@@ -4,12 +4,12 @@
"""Unit tests for http.py """ """Unit tests for http.py """
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from http import HTTP, defined_status from gluon.http import HTTP, defined_status
class TestHTTP(unittest.TestCase): class TestHTTP(unittest.TestCase):
+4 -4
View File
@@ -5,13 +5,13 @@ Unit tests for IS_URL()
""" """
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from validators import IS_URL, IS_HTTP_URL, IS_GENERIC_URL from gluon.validators import IS_URL, IS_HTTP_URL, IS_GENERIC_URL
from validators import unicode_to_ascii_authority from gluon.validators import unicode_to_ascii_authority
class TestIsUrl(unittest.TestCase): class TestIsUrl(unittest.TestCase):
@@ -296,7 +296,7 @@ class TestIsGenericUrl(unittest.TestCase):
def testInvalidUrls(self): def testInvalidUrls(self):
urlsToCheckA = [] urlsToCheckA = []
for i in range(0, 32) + [127]: for i in list(range(0, 32)) + [127]:
# Control characters are disallowed in any part of a URL # Control characters are disallowed in any part of a URL
+2 -2
View File
@@ -10,12 +10,12 @@ import os
import shutil import shutil
import tempfile import tempfile
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from gluon import languages
import languages
MP_WORKING = 0 MP_WORKING = 0
try: try:
import multiprocessing import multiprocessing
+1 -1
View File
@@ -9,7 +9,7 @@ import sys
import os import os
import doctest import doctest
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
+1 -1
View File
@@ -8,7 +8,7 @@ import unittest
import os import os
import shutil import shutil
import uuid import uuid
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
+3
View File
@@ -1044,6 +1044,9 @@ class TestRouter(unittest.TestCase):
'http://domain.com/app2/static/filename-with_underscore'), 'http://domain.com/app2/static/filename-with_underscore'),
norm_root("%s/applications/app2/static/filename-with_underscore" % root)) norm_root("%s/applications/app2/static/filename-with_underscore" % root))
from gluon.globals import current
current.response.static_version = None
self.assertEqual(str(URL(a='init', c='default', f='a_b')), "/a_b") self.assertEqual(str(URL(a='init', c='default', f='a_b')), "/a_b")
self.assertEqual(str(URL(a='app1', c='default', f='a_b')), "/app1/a-b") self.assertEqual(str(URL(a='app1', c='default', f='a_b')), "/app1/a-b")
self.assertEqual(str(URL(a='app2', c='default', f='a_b')), "/app2/a_b") self.assertEqual(str(URL(a='app2', c='default', f='a_b')), "/app2/a_b")
+1 -1
View File
@@ -65,7 +65,7 @@ def setUpModule():
if not os.path.isdir('gluon'): if not os.path.isdir('gluon'):
os.chdir(os.path.realpath( os.chdir(os.path.realpath(
'../../')) # run from web2py base directory '../../')) # run from web2py base directory
import main # for initialization after chdir from gluon import main # for initialization after chdir
global logger global logger
logger = logging.getLogger('web2py.rewrite') logger = logging.getLogger('web2py.rewrite')
global_settings.applications_parent = tempfile.mkdtemp() global_settings.applications_parent = tempfile.mkdtemp()
+1 -1
View File
@@ -10,7 +10,7 @@ import glob
import datetime import datetime
import sys import sys
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
+3 -3
View File
@@ -6,14 +6,14 @@
""" """
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
import datetime import datetime
import decimal import decimal
fix_sys_path(__file__) fix_sys_path(__file__)
from serializers import * from gluon.serializers import *
from storage import Storage from gluon.storage import Storage
# careful with the import path 'cause of isinstance() checks # careful with the import path 'cause of isinstance() checks
from gluon.languages import translator from gluon.languages import translator
from gluon.html import SPAN from gluon.html import SPAN
+5 -5
View File
@@ -8,7 +8,7 @@ import os
import sys import sys
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
@@ -18,12 +18,12 @@ DEFAULT_URI = os.getenv('DB', 'sqlite:memory')
from gluon.dal import DAL, Field from gluon.dal import DAL, Field
from pydal.objects import Table from pydal.objects import Table
from tools import Auth, Mail from gluon.tools import Auth, Mail
from gluon.globals import Request, Response, Session from gluon.globals import Request, Response, Session
from storage import Storage from gluon.storage import Storage
from languages import translator from gluon.languages import translator
from gluon.http import HTTP from gluon.http import HTTP
from validators import * from gluon.validators import *
# TODO: Create these test... # TODO: Create these test...
+4 -4
View File
@@ -4,13 +4,13 @@
""" Unit tests for storage.py """ """ Unit tests for storage.py """
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from storage import Storage, StorageList, List from gluon.storage import Storage, StorageList, List
from http import HTTP from gluon.http import HTTP
import pickle from gluon._compat import pickle
class TestStorage(unittest.TestCase): class TestStorage(unittest.TestCase):
+3 -3
View File
@@ -5,12 +5,12 @@
""" """
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
import template from gluon import template
from template import render from gluon.template import render
class TestTemplate(unittest.TestCase): class TestTemplate(unittest.TestCase):
+4 -5
View File
@@ -10,7 +10,7 @@ import smtplib
import datetime import datetime
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
@@ -18,13 +18,12 @@ DEFAULT_URI = os.getenv('DB', 'sqlite:memory')
from gluon.dal import DAL, Field from gluon.dal import DAL, Field
from pydal.objects import Table from pydal.objects import Table
from tools import Auth, Mail, Recaptcha, Recaptcha2, prettydate from gluon.tools import Auth, Mail, Recaptcha, Recaptcha2, prettydate
from gluon.globals import Request, Response, Session from gluon.globals import Request, Response, Session
from storage import Storage from gluon.storage import Storage
from languages import translator from gluon.languages import translator
from gluon.http import HTTP from gluon.http import HTTP
python_version = sys.version[:3]
IS_IMAP = "imap" in DEFAULT_URI IS_IMAP = "imap" in DEFAULT_URI
+3 -6
View File
@@ -4,18 +4,15 @@
""" Unit tests for utils.py """ """ Unit tests for utils.py """
import unittest import unittest
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from utils import md5_hash from gluon.utils import md5_hash, compare, is_valid_ip_address, web2py_uuid
from utils import compare
from utils import is_valid_ip_address
from utils import web2py_uuid
import hashlib import hashlib
from hashlib import md5, sha1, sha224, sha256, sha384, sha512 from hashlib import md5, sha1, sha224, sha256, sha384, sha512
from utils import simple_hash, get_digest, secure_dumps, secure_loads from gluon.utils import simple_hash, get_digest, secure_dumps, secure_loads
class TestUtils(unittest.TestCase): class TestUtils(unittest.TestCase):
+1 -1
View File
@@ -7,7 +7,7 @@ import unittest
import datetime import datetime
import decimal import decimal
import re import re
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
+4 -4
View File
@@ -11,12 +11,12 @@ import subprocess
import time import time
import signal import signal
from fix_path import fix_sys_path from .fix_path import fix_sys_path
fix_sys_path(__file__) fix_sys_path(__file__)
from contrib.webclient import WebClient from gluon.contrib.webclient import WebClient
from urllib2 import HTTPError from gluon._compat import urllib2
webserverprocess = None webserverprocess = None
@@ -135,7 +135,7 @@ class TestWeb(LiveTest):
s = WebClient('http://127.0.0.1:8000/') s = WebClient('http://127.0.0.1:8000/')
try: try:
s.post('examples/soap_examples/call/soap', data=xml_request, method="POST") s.post('examples/soap_examples/call/soap', data=xml_request, method="POST")
except HTTPError as e: except urllib2.HTTPError as e:
assert(e.msg == 'INTERNAL SERVER ERROR') assert(e.msg == 'INTERNAL SERVER ERROR')
# check internal server error returned (issue 153) # check internal server error returned (issue 153)
assert(s.status == 500) assert(s.status == 500)
+19 -24
View File
@@ -12,12 +12,9 @@ Auth, Mail, PluginManager and various utilities
import base64 import base64
from functools import reduce from functools import reduce
try: from gluon._compat import pickle, thread, urllib2, Cookie, StringIO, configparser, MIMEBase, MIMEMultipart, \
import cPickle as pickle MIMEText, Encoders, Charset, long, urllib_quote
except:
import pickle
import datetime import datetime
import thread
import logging import logging
import sys import sys
import glob import glob
@@ -28,16 +25,13 @@ import fnmatch
import traceback import traceback
import smtplib import smtplib
import urllib import urllib
import urllib2
import Cookie
import cStringIO
import ConfigParser
import email.utils import email.utils
import random import random
import hmac import hmac
import hashlib import hashlib
import json 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.contenttype import contenttype
from gluon.storage import Storage, StorageList, Settings, Messages from gluon.storage import Storage, StorageList, Settings, Messages
@@ -184,7 +178,7 @@ class Mail(object):
in this way the can be referenced from the HTML as <img src="cid:attachment-0" /> etc. 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 Email attachment
@@ -252,7 +246,7 @@ class Mail(object):
content_type = contenttype(filename) content_type = contenttype(filename)
self.my_filename = filename self.my_filename = filename
self.my_payload = payload self.my_payload = payload
MIMEBase.MIMEBase.__init__(self, *content_type.split('/', 1)) MIMEBase.__init__(self, *content_type.split('/', 1))
self.set_payload(payload) self.set_payload(payload)
self['Content-Disposition'] = 'attachment; filename="%s"' % filename self['Content-Disposition'] = 'attachment; filename="%s"' % filename
if content_id is not None: if content_id is not None:
@@ -415,7 +409,7 @@ class Mail(object):
def encode_header(key): def encode_header(key):
if [c for c in key if 32 > ord(c) or ord(c) > 127]: 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: else:
return key return key
@@ -575,7 +569,7 @@ class Mail(object):
# insert the origin payload # insert the origin payload
payload.attach(payload_in) payload.attach(payload_in)
# insert the detached signature # insert the detached signature
p = MIMEBase.MIMEBase("application", 'pgp-signature') p = MIMEBase("application", 'pgp-signature')
p.set_payload(sig.read()) p.set_payload(sig.read())
payload.attach(p) payload.attach(p)
# it's just a trick to handle the no encryption case # it's just a trick to handle the no encryption case
@@ -615,10 +609,10 @@ class Mail(object):
boundary=None, boundary=None,
_subparts=None, _subparts=None,
**dict(protocol="application/pgp-encrypted")) **dict(protocol="application/pgp-encrypted"))
p = MIMEBase.MIMEBase("application", 'pgp-encrypted') p = MIMEBase("application", 'pgp-encrypted')
p.set_payload("Version: 1\r\n") p.set_payload("Version: 1\r\n")
payload.attach(p) payload.attach(p)
p = MIMEBase.MIMEBase("application", 'octet-stream') p = MIMEBase("application", 'octet-stream')
p.set_payload(cipher.read()) p.set_payload(cipher.read())
payload.attach(p) payload.attach(p)
except errors.GPGMEError as ex: except errors.GPGMEError as ex:
@@ -1881,7 +1875,7 @@ class Auth(object):
'Please ', 'Please ',
A('login', A('login',
_href=self.settings.login_url + _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 ''), if current.request.env.http_web2py_component_location else ''),
' to view this content.', ' to view this content.',
_class='not-authorized alert alert-block')) _class='not-authorized alert alert-block'))
@@ -2005,7 +1999,7 @@ class Auth(object):
if URL() == action: if URL() == action:
next = '' next = ''
else: else:
next = '?_next=' + urllib.quote(URL(args=request.args, next = '?_next=' + urllib_quote(URL(args=request.args,
vars=request.get_vars)) vars=request.get_vars))
href = lambda function: \ href = lambda function: \
'%s/%s%s' % (action, function, next if referrer_actions is DEFAULT or function in referrer_actions else '') '%s/%s%s' % (action, function, next if referrer_actions is DEFAULT or function in referrer_actions else '')
@@ -2021,7 +2015,7 @@ class Auth(object):
if self.user_id: # User is logged in if self.user_id: # User is logged in
logout_next = self.settings.logout_next logout_next = self.settings.logout_next
items.append({'name': T('Log Out'), 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'}) 'icon': 'icon-off'})
if 'profile' not in self.settings.actions_disabled: if 'profile' not in self.settings.actions_disabled:
items.append({'name': T('Profile'), 'href': href('profile'), items.append({'name': T('Profile'), 'href': href('profile'),
@@ -2667,7 +2661,8 @@ class Auth(object):
delattr(user, 'password') delattr(user, 'password')
else: else:
user = Row(user) user = Row(user)
for key, value in user.items(): for key in list(user.keys()):
value = user[key]
if callable(value) or key == 'password': if callable(value) or key == 'password':
delattr(user, key) delattr(user, key)
if self.settings.renew_session_onlogin: if self.settings.renew_session_onlogin:
@@ -4259,7 +4254,7 @@ class Auth(object):
next = self.here() next = self.here()
current.session.flash = current.response.flash current.session.flash = current.response.flash
return call_or_redirect(self.settings.on_failed_authentication, 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): if callable(condition):
flag = condition() flag = condition()
@@ -5277,7 +5272,7 @@ regex_geocode = \
def geocode(address): def geocode(address):
try: try:
a = urllib.quote(address) a = urllib_quote(address)
txt = fetch('http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=%s' % a) txt = fetch('http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=%s' % a)
item = regex_geocode.search(txt) item = regex_geocode.search(txt)
(la, lo) = (float(item.group('la')), float(item.group('lo'))) (la, lo) = (float(item.group('la')), float(item.group('lo')))
@@ -5611,7 +5606,7 @@ class Service(object):
import types import types
r = universal_caller(self.run_procedures[args[0]], r = universal_caller(self.run_procedures[args[0]],
*args[1:], **dict(request.vars)) *args[1:], **dict(request.vars))
s = cStringIO.StringIO() s = StringIO()
if hasattr(r, 'export_to_csv_file'): if hasattr(r, 'export_to_csv_file'):
r.export_to_csv_file(s) r.export_to_csv_file(s)
elif r and not isinstance(r, types.GeneratorType) and isinstance(r[0], (dict, Storage)): elif r and not isinstance(r, types.GeneratorType) and isinstance(r[0], (dict, Storage)):
@@ -6968,7 +6963,7 @@ class Config(object):
section, section,
default_values={} default_values={}
): ):
self.config = ConfigParser.ConfigParser(default_values) self.config = configparser.ConfigParser(default_values)
self.config.read(filename) self.config.read(filename)
if not self.config.has_section(section): if not self.config.has_section(section):
self.config.add_section(section) self.config.add_section(section)
+3 -3
View File
@@ -11,7 +11,7 @@ Utilities and class for UTF8 strings managing
---------------------------------------------- ----------------------------------------------
""" """
from __future__ import print_function from __future__ import print_function
from gluon._compat import builtin as __builtin__ from gluon._compat import builtin as __builtin__, unicodeT
__all__ = ['Utf8'] __all__ = ['Utf8']
@@ -62,7 +62,7 @@ def ord(char):
"""Returns unicode id for utf8 or unicode *char* character """Returns unicode id for utf8 or unicode *char* character
SUPPOSE that *char* is an utf-8 or unicode character only SUPPOSE that *char* is an utf-8 or unicode character only
""" """
if isinstance(char, unicode): if isinstance(char, unicodeT):
return __builtin__.ord(char) return __builtin__.ord(char)
return __builtin__.ord(unicode(char, 'utf-8')) return __builtin__.ord(unicode(char, 'utf-8'))
@@ -119,7 +119,7 @@ class Utf8(str):
You can see the benefit of this class in doctests() below You can see the benefit of this class in doctests() below
""" """
def __new__(cls, content='', codepage='utf-8'): def __new__(cls, content='', codepage='utf-8'):
if isinstance(content, unicode): if isinstance(content, unicodeT):
return str.__new__(cls, unicode.encode(content, 'utf-8')) return str.__new__(cls, unicode.encode(content, 'utf-8'))
elif codepage in ('utf-8', 'utf8') or isinstance(content, cls): elif codepage in ('utf-8', 'utf8') or isinstance(content, cls):
return str.__new__(cls, content) return str.__new__(cls, content)
+3 -3
View File
@@ -21,7 +21,7 @@ import urllib
import struct import struct
import decimal import decimal
import unicodedata import unicodedata
from gluon._compat import StringIO, long, unicodeT from gluon._compat import StringIO, long, unicodeT, to_unicode, urllib_unquote, unichr, to_bytes
from gluon.utils import simple_hash, web2py_uuid, DIGEST_ALG_BY_SIZE from gluon.utils import simple_hash, web2py_uuid, DIGEST_ALG_BY_SIZE
from pydal.objects import Field, FieldVirtual, FieldMethod from pydal.objects import Field, FieldVirtual, FieldMethod
from functools import reduce from functools import reduce
@@ -1508,7 +1508,7 @@ def unicode_to_ascii_url(url, prepend_scheme):
# Try appending a scheme to see if that fixes the problem # Try appending a scheme to see if that fixes the problem
scheme_to_prepend = prepend_scheme or 'http' scheme_to_prepend = prepend_scheme or 'http'
groups = url_split_regex.match( groups = url_split_regex.match(
unicode(scheme_to_prepend) + u'://' + url).groups() to_unicode(scheme_to_prepend) + u'://' + url).groups()
# if we still can't find the authority # if we still can't find the authority
if not groups[3]: if not groups[3]:
raise Exception('No authority component found, ' + raise Exception('No authority component found, ' +
@@ -1609,7 +1609,7 @@ class IS_GENERIC_URL(Validator):
scheme = url_split_regex.match(value).group(2) scheme = url_split_regex.match(value).group(2)
# Clean up the scheme before we check it # Clean up the scheme before we check it
if not scheme is None: if not scheme is None:
scheme = urllib.unquote(scheme).lower() scheme = urllib_unquote(scheme).lower()
# If the scheme really exists # If the scheme really exists
if scheme in self.allowed_schemes: if scheme in self.allowed_schemes:
# Then the URL is valid # Then the URL is valid
+3 -3
View File
@@ -55,9 +55,9 @@ def run_system_tests(options):
import subprocess import subprocess
major_version = sys.version_info[0] major_version = sys.version_info[0]
minor_version = sys.version_info[1] minor_version = sys.version_info[1]
call_args = [sys.executable, '-m', 'unittest', '-v', 'gluon.tests']
if major_version == 2: if major_version == 2:
if minor_version in (7,): if minor_version in (7,):
call_args = [sys.executable, '-m', 'unittest', '-v', 'gluon.tests']
if options.with_coverage: if options.with_coverage:
try: try:
import coverage import coverage
@@ -76,8 +76,8 @@ def run_system_tests(options):
sys.stderr.write("unknown python 2.x version\n") sys.stderr.write("unknown python 2.x version\n")
ret = 256 ret = 256
else: else:
sys.stderr.write("Only Python 2.x supported.\n") sys.stderr.write("Experimental Python 3.x.\n")
ret = 256 ret = subprocess.call(call_args)
sys.exit(ret and 1) sys.exit(ret and 1)