minor few fix
This commit is contained in:
+10
-4
@@ -22,9 +22,10 @@ if PY2:
|
||||
from email.MIMEBase import MIMEBase
|
||||
from email.Header import Header
|
||||
from email import MIMEMultipart, MIMEText, Encoders, Charset
|
||||
from urllib import FancyURLopener, urlencode
|
||||
from urllib import FancyURLopener, urlencode, urlopen
|
||||
from urllib import quote as urllib_quote, unquote as urllib_unquote
|
||||
from string import maketrans
|
||||
from types import ClassType
|
||||
import cgi
|
||||
reduce = reduce
|
||||
hashlib_md5 = hashlib.md5
|
||||
@@ -64,8 +65,9 @@ if PY2:
|
||||
return obj
|
||||
return obj.encode(charset, errors)
|
||||
|
||||
def _local_html_escape(data, quote):
|
||||
return cgi.escape(data, quote).replace("'", "'")
|
||||
def _local_html_escape(data, quote=False):
|
||||
s = cgi.escape(data, quote)
|
||||
return s.replace("'", "'") if quote else s
|
||||
|
||||
else:
|
||||
import pickle
|
||||
@@ -87,7 +89,7 @@ else:
|
||||
from email import encoders as Encoders
|
||||
from email.header import Header
|
||||
from email.charset import Charset
|
||||
from urllib.request import FancyURLopener
|
||||
from urllib.request import FancyURLopener, urlopen
|
||||
from urllib.parse import quote as urllib_quote, unquote as urllib_unquote, urlencode
|
||||
import html
|
||||
hashlib_md5 = lambda s: hashlib.md5(bytes(s, 'utf8'))
|
||||
@@ -103,6 +105,7 @@ else:
|
||||
unichr = chr
|
||||
unicodeT = str
|
||||
maketrans = str.maketrans
|
||||
ClassType = type
|
||||
|
||||
implements_iterator = _identity
|
||||
implements_bool = _identity
|
||||
@@ -129,6 +132,9 @@ else:
|
||||
characters, both double quote (") and single quote (') characters are also
|
||||
translated.
|
||||
"""
|
||||
if isinstance(s, str):
|
||||
return html.escape(s, quote=quote)
|
||||
|
||||
s = s.replace(b"&", b"&") # Must be done first!
|
||||
s = s.replace(b"<", b"<")
|
||||
s = s.replace(b">", b">")
|
||||
|
||||
@@ -477,7 +477,7 @@ def ldap_auth(server='ldap',
|
||||
ldap_groups_of_the_user = get_user_groups_from_ldap(username, password)
|
||||
|
||||
# search for allowed group names
|
||||
if not isinstance(allowed_groups, type(list())):
|
||||
if not isinstance(allowed_groups, list):
|
||||
allowed_groups = [allowed_groups]
|
||||
for group in allowed_groups:
|
||||
if ldap_groups_of_the_user.count(group) > 0:
|
||||
|
||||
@@ -29,17 +29,12 @@
|
||||
An interactive, stateful AJAX shell that runs Python code on the server.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from gluon._compat import ClassType, pickle, StringIO
|
||||
import logging
|
||||
import new
|
||||
try:
|
||||
import cPickle as pickle
|
||||
except:
|
||||
import pickle
|
||||
import sys
|
||||
import traceback
|
||||
import types
|
||||
import StringIO
|
||||
import threading
|
||||
locker = threading.RLock()
|
||||
|
||||
@@ -53,6 +48,7 @@ _HISTORY_KIND = '_Shell_History'
|
||||
UNPICKLABLE_TYPES = [
|
||||
types.ModuleType,
|
||||
type,
|
||||
ClassType
|
||||
types.FunctionType,
|
||||
]
|
||||
|
||||
@@ -204,7 +200,7 @@ def run(history, statement, env={}):
|
||||
# globals, run the statement, and re-pickle the history globals, all
|
||||
# inside it.
|
||||
old_main = sys.modules.get('__main__')
|
||||
output = StringIO.StringIO()
|
||||
output = StringIO()
|
||||
try:
|
||||
sys.modules['__main__'] = statement_module
|
||||
statement_module.__name__ = '__main__'
|
||||
@@ -212,7 +208,7 @@ def run(history, statement, env={}):
|
||||
|
||||
# re-evaluate the unpicklables
|
||||
for code in history.unpicklables:
|
||||
exec code in statement_module.__dict__
|
||||
exec(code, statement_module.__dict__)
|
||||
|
||||
# re-initialize the globals
|
||||
for name, val in history.globals_dict().items():
|
||||
@@ -232,7 +228,7 @@ def run(history, statement, env={}):
|
||||
try:
|
||||
sys.stderr = sys.stdout = output
|
||||
locker.acquire()
|
||||
exec compiled in statement_module.__dict__
|
||||
exec(compiled, statement_module.__dict__)
|
||||
finally:
|
||||
locker.release()
|
||||
sys.stdout, sys.stderr = old_stdout, old_stderr
|
||||
|
||||
@@ -48,6 +48,7 @@ PAST = 'Sat, 1-Jan-1971 00:00:00'
|
||||
FUTURE = 'Tue, 1-Dec-2999 23:59:59'
|
||||
|
||||
try:
|
||||
#FIXME PY3
|
||||
from gluon.contrib.minify import minify
|
||||
have_minify = True
|
||||
except ImportError:
|
||||
|
||||
+6
-7
@@ -7,9 +7,8 @@
|
||||
| License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from gluon._compat import xrange
|
||||
from gluon._compat import xrange, _local_html_escape
|
||||
import re
|
||||
import cgi
|
||||
|
||||
__all__ = ['highlight']
|
||||
|
||||
@@ -63,7 +62,7 @@ class Highlighter(object):
|
||||
Callback for C specific highlighting.
|
||||
"""
|
||||
|
||||
value = cgi.escape(match.group())
|
||||
value = _local_html_escape(match.group(), quote=False)
|
||||
self.change_style(token, style)
|
||||
self.output.append(value)
|
||||
|
||||
@@ -77,7 +76,7 @@ class Highlighter(object):
|
||||
Callback for python specific highlighting.
|
||||
"""
|
||||
|
||||
value = cgi.escape(match.group())
|
||||
value = _local_html_escape(match.group(), quote=False)
|
||||
if token == 'MULTILINESTRING':
|
||||
self.change_style(token, style)
|
||||
self.output.append(value)
|
||||
@@ -114,7 +113,7 @@ class Highlighter(object):
|
||||
Callback for HTML specific highlighting.
|
||||
"""
|
||||
|
||||
value = cgi.escape(match.group())
|
||||
value = _local_html_escape(match.group(), quote=False)
|
||||
self.change_style(token, style)
|
||||
self.output.append(value)
|
||||
if token == 'GOTOPYTHON':
|
||||
@@ -292,13 +291,13 @@ def highlight(
|
||||
'WEB2PY']:
|
||||
code = Highlighter(language, link, styles).highlight(code)
|
||||
else:
|
||||
code = cgi.escape(code)
|
||||
code = _local_html_escape(code, quote=False)
|
||||
lines = code.split('\n')
|
||||
|
||||
if counter is None:
|
||||
linenumbers = [''] * len(lines)
|
||||
elif isinstance(counter, str):
|
||||
linenumbers = [cgi.escape(counter)] * len(lines)
|
||||
linenumbers = [_local_html_escape(counter, quote=False)] * len(lines)
|
||||
else:
|
||||
linenumbers = [str(i + counter) + '.' for i in
|
||||
xrange(len(lines))]
|
||||
|
||||
+2
-1
@@ -2210,7 +2210,8 @@ class FORM(DIV):
|
||||
next = where to redirect in case of success
|
||||
any other kwargs will be passed for form.accepts(...)
|
||||
"""
|
||||
from gluon import current, redirect
|
||||
from gluon.globals import current
|
||||
from gluon.http import redirect
|
||||
kwargs['request_vars'] = kwargs.get(
|
||||
'request_vars', current.request.post_vars)
|
||||
kwargs['session'] = kwargs.get('session', current.session)
|
||||
|
||||
+2
-2
@@ -163,7 +163,7 @@ def redirect(location='', how=303, client_side=False, headers=None):
|
||||
"""
|
||||
headers = headers or {}
|
||||
if location:
|
||||
from gluon import current
|
||||
from gluon.globals import current
|
||||
loc = location.replace('\r', '%0D').replace('\n', '%0A')
|
||||
if client_side and current.request.ajax:
|
||||
headers['web2py-redirect-location'] = loc
|
||||
@@ -174,7 +174,7 @@ def redirect(location='', how=303, client_side=False, headers=None):
|
||||
'You are being redirected <a href="%s">here</a>' % loc,
|
||||
**headers)
|
||||
else:
|
||||
from gluon import current
|
||||
from gluon.globals import current
|
||||
if client_side and current.request.ajax:
|
||||
headers['web2py-component-command'] = 'window.location.reload(true)'
|
||||
raise HTTP(200, **headers)
|
||||
|
||||
+2
-2
@@ -541,7 +541,7 @@ class translator(object):
|
||||
def get_possible_languages(self):
|
||||
""" Gets list of all possible languages for current application """
|
||||
return list(set(self.current_languages +
|
||||
[lang for lang in iterkeys(read_possible_languages(self.langpath))
|
||||
[lang for lang in read_possible_languages(self.langpath)
|
||||
if lang != 'default']))
|
||||
|
||||
def set_current_languages(self, *languages):
|
||||
@@ -658,7 +658,7 @@ class translator(object):
|
||||
languages = []
|
||||
self.requested_languages = languages = tuple(languages)
|
||||
if languages:
|
||||
all_languages = set(lang for lang in iterkeys(pl_info)
|
||||
all_languages = set(lang for lang in pl_info
|
||||
if lang != 'default') \
|
||||
| set(self.current_languages)
|
||||
for lang in languages:
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ Restricted environment to execute application's code
|
||||
"""
|
||||
|
||||
import sys
|
||||
from gluon._compat import pickle
|
||||
from gluon._compat import pickle, ClassType
|
||||
import traceback
|
||||
import types
|
||||
import os
|
||||
@@ -249,7 +249,7 @@ def snapshot(info=None, context=5, code=None, environment=None):
|
||||
# if no exception info given, get current:
|
||||
etype, evalue, etb = info or sys.exc_info()
|
||||
|
||||
if isinstance(etype, type):
|
||||
if isinstance(etype, ClassType):
|
||||
etype = etype.__name__
|
||||
|
||||
# create a snapshot dict with some basic information
|
||||
|
||||
+7
-7
@@ -30,7 +30,7 @@ from gluon.globals import Request, Response, Session
|
||||
from gluon.storage import Storage, List
|
||||
from gluon.admin import w2p_unpack
|
||||
from pydal.base import BaseAdapter
|
||||
from gluon._compat import iteritems
|
||||
from gluon._compat import iteritems, ClassType
|
||||
|
||||
logger = logging.getLogger("web2py")
|
||||
|
||||
@@ -87,7 +87,7 @@ def exec_environment(
|
||||
if pyfile:
|
||||
pycfile = pyfile + 'c'
|
||||
if os.path.isfile(pycfile):
|
||||
exec (read_pyc(pycfile)) in env
|
||||
exec (read_pyc(pycfile), env)
|
||||
else:
|
||||
execfile(pyfile, env)
|
||||
return Storage(env)
|
||||
@@ -244,14 +244,14 @@ def run(
|
||||
"controllers_%s_%s.pyc" % (c, f))
|
||||
if ((cronjob and os.path.isfile(pycfile))
|
||||
or not os.path.isfile(pyfile)):
|
||||
exec (read_pyc(pycfile)) in _env
|
||||
exec(read_pyc(pycfile), _env)
|
||||
elif os.path.isfile(pyfile):
|
||||
execfile(pyfile, _env)
|
||||
else:
|
||||
die(errmsg)
|
||||
|
||||
if f:
|
||||
exec ('print %s()' % f, _env)
|
||||
exec('print %s()' % f, _env)
|
||||
return
|
||||
|
||||
_env.update(exec_pythonrc())
|
||||
@@ -260,7 +260,7 @@ def run(
|
||||
ccode = None
|
||||
if startfile.endswith('.pyc'):
|
||||
ccode = read_pyc(startfile)
|
||||
exec (ccode) in _env
|
||||
exec(ccode, _env)
|
||||
else:
|
||||
execfile(startfile, _env)
|
||||
|
||||
@@ -398,7 +398,7 @@ def test(testpath, import_models=True, verbose=False):
|
||||
def doctest_object(name, obj):
|
||||
"""doctest obj and enclosed methods and classes."""
|
||||
|
||||
if type(obj) in (types.FunctionType, type, types.MethodType,
|
||||
if type(obj) in (types.FunctionType, type, ClassType, types.MethodType,
|
||||
types.UnboundMethodType):
|
||||
|
||||
# Reload environment before each test.
|
||||
@@ -409,7 +409,7 @@ def test(testpath, import_models=True, verbose=False):
|
||||
obj, globs=globs,
|
||||
name='%s: %s' % (os.path.basename(testfile),
|
||||
name), verbose=verbose)
|
||||
if type(obj) in (type):
|
||||
if type(obj) in (type, ClassType):
|
||||
for attr_name in dir(obj):
|
||||
|
||||
# Execute . operator so decorators are executed.
|
||||
|
||||
+3
-3
@@ -11,14 +11,14 @@ Utilities and class for UTF8 strings managing
|
||||
----------------------------------------------
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from gluon._compat import builtin as __builtin__, unicodeT, iteritems
|
||||
from gluon._compat import builtin as __builtin__, unicodeT, iteritems, to_unicode
|
||||
|
||||
__all__ = ['Utf8']
|
||||
|
||||
repr_escape_tab = {}
|
||||
#FIXME PY3
|
||||
#for i in range(1, 32):
|
||||
# repr_escape_tab[i] = ur'\x%02x' % i
|
||||
for i in range(1, 32):
|
||||
repr_escape_tab[i] = to_unicode("\\"+"x%02x" % i)
|
||||
repr_escape_tab[7] = u'\\a'
|
||||
repr_escape_tab[8] = u'\\b'
|
||||
repr_escape_tab[9] = u'\\t'
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ __all__ = [
|
||||
]
|
||||
|
||||
try:
|
||||
from globals import current
|
||||
from gluon.globals import current
|
||||
have_current = True
|
||||
except ImportError:
|
||||
have_current = False
|
||||
|
||||
+4
-4
@@ -355,7 +355,7 @@ class web2pyDialog(object):
|
||||
except:
|
||||
sys.stderr.write('Sorry, -K only supported for python 2.6-2.7\n')
|
||||
return
|
||||
code = "from gluon import current;current._scheduler.loop()"
|
||||
code = "from gluon.globals import current;current._scheduler.loop()"
|
||||
print('starting scheduler from widget for "%s"...' % app)
|
||||
args = (app, True, True, None, False, code)
|
||||
logging.getLogger().setLevel(self.options.debuglevel)
|
||||
@@ -1034,9 +1034,9 @@ def check_existent_app(options, appname):
|
||||
|
||||
def get_code_for_scheduler(app, options):
|
||||
if len(app) == 1 or app[1] is None:
|
||||
code = "from gluon import current;current._scheduler.loop()"
|
||||
code = "from gluon.globals import current;current._scheduler.loop()"
|
||||
else:
|
||||
code = "from gluon import current;current._scheduler.group_names = ['%s'];"
|
||||
code = "from gluon.globals import current;current._scheduler.group_names = ['%s'];"
|
||||
code += "current._scheduler.loop()"
|
||||
code = code % ("','".join(app[1:]))
|
||||
app_ = app[0]
|
||||
@@ -1056,7 +1056,7 @@ def start_schedulers(options):
|
||||
apps = [(app.strip(), None) for app in options.scheduler.split(',')]
|
||||
if options.scheduler_groups:
|
||||
apps = options.scheduler_groups
|
||||
code = "from gluon import current;current._scheduler.loop()"
|
||||
code = "from gluon.globals import current;current._scheduler.loop()"
|
||||
logging.getLogger().setLevel(options.debuglevel)
|
||||
if options.folder:
|
||||
os.chdir(options.folder)
|
||||
|
||||
Reference in New Issue
Block a user