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