better options and regexp, thanks Paolo
This commit is contained in:
1 parent
563de284f7
commit
2f35117282
4 files changed
+44
-41
No files matched your search
+12
-8
@@ -56,8 +56,6 @@ except ImportError:
|
|||||||
have_minify = False
|
have_minify = False
|
||||||
|
|
||||||
|
|
||||||
regex_session_id = re.compile('^([\w\-]+/)?[\w\-\.]+$')
|
|
||||||
|
|
||||||
__all__ = ['Request', 'Response', 'Session']
|
__all__ = ['Request', 'Response', 'Session']
|
||||||
|
|
||||||
current = threading.local() # thread-local storage for request-scope globals
|
current = threading.local() # thread-local storage for request-scope globals
|
||||||
@@ -357,9 +355,11 @@ class Request(Storage):
|
|||||||
"""
|
"""
|
||||||
cmd_opts = global_settings.cmd_options
|
cmd_opts = global_settings.cmd_options
|
||||||
# checking if this is called within the scheduler or within the shell
|
# checking if this is called within the scheduler or within the shell
|
||||||
# in addition to checking if it's not a cronjob
|
# in addition to checking if it's a cronjob
|
||||||
if ((cmd_opts and (cmd_opts.shell or cmd_opts.scheduler))
|
# FIXME: cmd_opts.scheduler does not imply that
|
||||||
or global_settings.cronjob or self.is_https):
|
# we are running in the scheduler
|
||||||
|
if (self.is_https or cmd_opts and (
|
||||||
|
cmd_opts.shell or cmd_opts.scheduler or cmd_opts.cronjob)):
|
||||||
current.session.secure()
|
current.session.secure()
|
||||||
else:
|
else:
|
||||||
current.session.forget()
|
current.session.forget()
|
||||||
@@ -602,6 +602,7 @@ class Response(Storage):
|
|||||||
# for attachment settings and backward compatibility
|
# for attachment settings and backward compatibility
|
||||||
keys = [item.lower() for item in headers]
|
keys = [item.lower() for item in headers]
|
||||||
if attachment:
|
if attachment:
|
||||||
|
# FIXME: should be done like in next download method
|
||||||
if filename is None:
|
if filename is None:
|
||||||
attname = ""
|
attname = ""
|
||||||
else:
|
else:
|
||||||
@@ -654,6 +655,7 @@ class Response(Storage):
|
|||||||
|
|
||||||
Downloads from http://..../download/filename
|
Downloads from http://..../download/filename
|
||||||
"""
|
"""
|
||||||
|
from pydal.helpers.regex import REGEX_UPLOAD_PATTERN
|
||||||
from pydal.exceptions import NotAuthorizedException, NotFoundException
|
from pydal.exceptions import NotAuthorizedException, NotFoundException
|
||||||
|
|
||||||
current.session.forget(current.response)
|
current.session.forget(current.response)
|
||||||
@@ -661,10 +663,10 @@ class Response(Storage):
|
|||||||
if not request.args:
|
if not request.args:
|
||||||
raise HTTP(404)
|
raise HTTP(404)
|
||||||
name = request.args[-1]
|
name = request.args[-1]
|
||||||
items = re.compile('(?P<table>.*?)\.(?P<field>.*?)\..*').match(name)
|
items = re.match(REGEX_UPLOAD_PATTERN, name)
|
||||||
if not items:
|
if not items:
|
||||||
raise HTTP(404)
|
raise HTTP(404)
|
||||||
(t, f) = (items.group('table'), items.group('field'))
|
t = items.group('table'); f = items.group('field')
|
||||||
try:
|
try:
|
||||||
field = db[t][f]
|
field = db[t][f]
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
@@ -801,6 +803,8 @@ class Session(Storage):
|
|||||||
- session_filename
|
- session_filename
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
REGEX_SESSION_FILE = r'^(?:[\w-]+/)?[\w.-]+$'
|
||||||
|
|
||||||
def connect(self,
|
def connect(self,
|
||||||
request=None,
|
request=None,
|
||||||
response=None,
|
response=None,
|
||||||
@@ -891,7 +895,7 @@ class Session(Storage):
|
|||||||
response.session_file = None
|
response.session_file = None
|
||||||
# check if the session_id points to a valid sesion filename
|
# check if the session_id points to a valid sesion filename
|
||||||
if response.session_id:
|
if response.session_id:
|
||||||
if not regex_session_id.match(response.session_id):
|
if not re.match(self.REGEX_SESSION_FILE, response.session_id):
|
||||||
response.session_id = None
|
response.session_id = None
|
||||||
else:
|
else:
|
||||||
response.session_filename = \
|
response.session_filename = \
|
||||||
|
|||||||
+13
-9
@@ -31,7 +31,6 @@ _cron_subprocs = []
|
|||||||
def absolute_path_link(path):
|
def absolute_path_link(path):
|
||||||
"""
|
"""
|
||||||
Returns an absolute path for the destination of a symlink
|
Returns an absolute path for the destination of a symlink
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if os.path.islink(path):
|
if os.path.islink(path):
|
||||||
link = os.readlink(path)
|
link = os.readlink(path)
|
||||||
@@ -73,16 +72,17 @@ class extcron(threading.Thread):
|
|||||||
|
|
||||||
class hardcron(threading.Thread):
|
class hardcron(threading.Thread):
|
||||||
|
|
||||||
def __init__(self, applications_parent):
|
def __init__(self, applications_parent, apps=None):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.setDaemon(True)
|
self.setDaemon(True)
|
||||||
self.path = applications_parent
|
self.path = applications_parent
|
||||||
crondance(self.path, 'hard', startup=True)
|
self.apps = apps
|
||||||
|
crondance(self.path, 'hard', startup=True, apps=self.apps)
|
||||||
|
|
||||||
def launch(self):
|
def launch(self):
|
||||||
if not _cron_stopping:
|
if not _cron_stopping:
|
||||||
logger.debug('hard cron invocation')
|
logger.debug('hard cron invocation')
|
||||||
crondance(self.path, 'hard', startup=False)
|
crondance(self.path, 'hard', startup=False, apps=self.apps)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
s = sched.scheduler(time.time, time.sleep)
|
s = sched.scheduler(time.time, time.sleep)
|
||||||
@@ -95,15 +95,16 @@ class hardcron(threading.Thread):
|
|||||||
|
|
||||||
class softcron(threading.Thread):
|
class softcron(threading.Thread):
|
||||||
|
|
||||||
def __init__(self, applications_parent):
|
def __init__(self, applications_parent, apps=None):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.path = applications_parent
|
self.path = applications_parent
|
||||||
# crondance(self.path, 'soft', startup=True)
|
self.apps = apps
|
||||||
|
# crondance(self.path, 'soft', startup=True, apps=self.apps)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if not _cron_stopping:
|
if not _cron_stopping:
|
||||||
logger.debug('soft cron invocation')
|
logger.debug('soft cron invocation')
|
||||||
crondance(self.path, 'soft', startup=False)
|
crondance(self.path, 'soft', startup=False, apps=self.apps)
|
||||||
|
|
||||||
|
|
||||||
class Token(object):
|
class Token(object):
|
||||||
@@ -270,7 +271,10 @@ class cronlauncher(threading.Thread):
|
|||||||
|
|
||||||
|
|
||||||
def crondance(applications_parent, ctype='soft', startup=False, apps=None):
|
def crondance(applications_parent, ctype='soft', startup=False, apps=None):
|
||||||
# TODO: docstring
|
"""
|
||||||
|
Does the periodic job of cron service: read the crontab(s) and launch
|
||||||
|
the various commands.
|
||||||
|
"""
|
||||||
apppath = os.path.join(applications_parent, 'applications')
|
apppath = os.path.join(applications_parent, 'applications')
|
||||||
token = Token(applications_parent)
|
token = Token(applications_parent)
|
||||||
cronmaster = token.acquire(startup=startup)
|
cronmaster = token.acquire(startup=startup)
|
||||||
@@ -299,7 +303,7 @@ def crondance(applications_parent, ctype='soft', startup=False, apps=None):
|
|||||||
base_commands.append(w2p_path)
|
base_commands.append(w2p_path)
|
||||||
if applications_parent != global_settings.gluon_parent:
|
if applications_parent != global_settings.gluon_parent:
|
||||||
base_commands.extend(('-f', applications_parent))
|
base_commands.extend(('-f', applications_parent))
|
||||||
base_commands.extend(('-J',
|
base_commands.extend(('--cronjob', '--no-banner', '--nogui', '--plain',
|
||||||
# FIXME: this should not be needed since we are
|
# FIXME: this should not be needed since we are
|
||||||
# not launching the web server
|
# not launching the web server
|
||||||
'-a', '"<recycle>"'))
|
'-a', '"<recycle>"'))
|
||||||
|
|||||||
+1
-1
Submodule gluon/packages/dal updated: f3401dd8c0...f1cf5aab12.
+18
-23
@@ -216,6 +216,14 @@ class web2pyDialog(object):
|
|||||||
self.bannerarea.after(1000, self.update_canvas)
|
self.bannerarea.after(1000, self.update_canvas)
|
||||||
|
|
||||||
# IP
|
# IP
|
||||||
|
# retrieves the list of server IP addresses
|
||||||
|
try:
|
||||||
|
if_ips = list(set( # no duplicates
|
||||||
|
[addrinfo[4][0] for addrinfo in getipaddrinfo(socket.getfqdn())
|
||||||
|
if not is_loopback_ip_address(addrinfo=addrinfo)]))
|
||||||
|
except socket.gaierror:
|
||||||
|
if_ips = []
|
||||||
|
|
||||||
tkinter.Label(self.root,
|
tkinter.Label(self.root,
|
||||||
text='Server IP:', bg=bg_color,
|
text='Server IP:', bg=bg_color,
|
||||||
justify=tkinter.RIGHT).grid(row=4,
|
justify=tkinter.RIGHT).grid(row=4,
|
||||||
@@ -226,7 +234,7 @@ class web2pyDialog(object):
|
|||||||
row = 4
|
row = 4
|
||||||
ips = [('127.0.0.1', 'Local (IPv4)')] + \
|
ips = [('127.0.0.1', 'Local (IPv4)')] + \
|
||||||
([('::1', 'Local (IPv6)')] if socket.has_ipv6 else []) + \
|
([('::1', 'Local (IPv6)')] if socket.has_ipv6 else []) + \
|
||||||
[(ip, 'Public') for ip in options.ips] + \
|
[(ip, 'Public') for ip in if_ips] + \
|
||||||
[('0.0.0.0', 'Public')]
|
[('0.0.0.0', 'Public')]
|
||||||
for ip, legend in ips:
|
for ip, legend in ips:
|
||||||
self.ips[ip] = tkinter.Radiobutton(
|
self.ips[ip] = tkinter.Radiobutton(
|
||||||
@@ -704,7 +712,7 @@ web2py will attempt to run a GUI to ask for it when starting the web server
|
|||||||
metavar='APPNAME', help=\
|
metavar='APPNAME', help=\
|
||||||
'run web2py in interactive shell or IPython (if installed) with ' \
|
'run web2py in interactive shell or IPython (if installed) with ' \
|
||||||
'specified appname (if app does not exist it will be created). ' \
|
'specified appname (if app does not exist it will be created). ' \
|
||||||
'APPNAME like a/c/f?x=y (c,f and vars x,y optional)')
|
'APPNAME like a/c/f?x=y (c, f and vars optional)')
|
||||||
|
|
||||||
parser.add_option('-B', '--bpython',
|
parser.add_option('-B', '--bpython',
|
||||||
default=False,
|
default=False,
|
||||||
@@ -752,7 +760,7 @@ web2py will attempt to run a GUI to ask for it when starting the web server
|
|||||||
default=None,
|
default=None,
|
||||||
metavar='TEST_PATH', help=\
|
metavar='TEST_PATH', help=\
|
||||||
'run doctests in web2py environment; ' \
|
'run doctests in web2py environment; ' \
|
||||||
'TEST_PATH like a/c/f (c,f optional)')
|
'TEST_PATH like a/c/f (c, f optional)')
|
||||||
|
|
||||||
parser.add_option('-C', '--cron', dest='extcron',
|
parser.add_option('-C', '--cron', dest='extcron',
|
||||||
default=False,
|
default=False,
|
||||||
@@ -777,7 +785,9 @@ web2py will attempt to run a GUI to ask for it when starting the web server
|
|||||||
parser.add_option('-J', '--cronjob',
|
parser.add_option('-J', '--cronjob',
|
||||||
default=False,
|
default=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='identify cron-initiated command')
|
# NOTE: help suppressed because this option is
|
||||||
|
# intended for internal use only
|
||||||
|
help=optparse.SUPPRESS_HELP)
|
||||||
|
|
||||||
parser.add_option('-L', '--config',
|
parser.add_option('-L', '--config',
|
||||||
default='',
|
default='',
|
||||||
@@ -840,6 +850,10 @@ web2py will attempt to run a GUI to ask for it when starting the web server
|
|||||||
# TODO: warn or error if args (should be no unparsed arguments)
|
# TODO: warn or error if args (should be no unparsed arguments)
|
||||||
options.args = other_args
|
options.args = other_args
|
||||||
|
|
||||||
|
if options.taskbar and os.name != 'nt':
|
||||||
|
# TODO: warn and disable taskbar instead of exit
|
||||||
|
die('taskbar not supported on this platform')
|
||||||
|
|
||||||
if options.config.endswith('.py'):
|
if options.config.endswith('.py'):
|
||||||
options.config = options.config[:-3]
|
options.config = options.config[:-3]
|
||||||
if options.config:
|
if options.config:
|
||||||
@@ -853,20 +867,6 @@ web2py will attempt to run a GUI to ask for it when starting the web server
|
|||||||
if hasattr(options, key):
|
if hasattr(options, key):
|
||||||
setattr(options, key, getattr(options2, key))
|
setattr(options, key, getattr(options2, key))
|
||||||
|
|
||||||
# store in options.ips the list of server IP addresses
|
|
||||||
try:
|
|
||||||
options.ips = list(set( # no duplicates
|
|
||||||
[addrinfo[4][0] for addrinfo in getipaddrinfo(socket.getfqdn())
|
|
||||||
if not is_loopback_ip_address(addrinfo=addrinfo)]))
|
|
||||||
except socket.gaierror:
|
|
||||||
options.ips = []
|
|
||||||
|
|
||||||
if options.cronjob:
|
|
||||||
global_settings.cronjob = True # tell the world
|
|
||||||
options.plain = True # cronjobs use a plain shell
|
|
||||||
options.nobanner = True
|
|
||||||
options.nogui = True
|
|
||||||
|
|
||||||
# transform options.interfaces, in the form
|
# transform options.interfaces, in the form
|
||||||
# "ip1:port1:key1:cert1:ca_cert1;[ip2]:port2;ip3:port3:key3:cert3"
|
# "ip1:port1:key1:cert1:ca_cert1;[ip2]:port2;ip3:port3:key3:cert3"
|
||||||
# (no spaces; optional key:cert:ca_cert indicate SSL), into
|
# (no spaces; optional key:cert:ca_cert indicate SSL), into
|
||||||
@@ -1074,11 +1074,6 @@ def start(cron=True):
|
|||||||
# if no password provided and have Tk library start GUI (when not
|
# if no password provided and have Tk library start GUI (when not
|
||||||
# explicitly disabled), we also need a GUI to put in taskbar (system tray)
|
# explicitly disabled), we also need a GUI to put in taskbar (system tray)
|
||||||
# when requested
|
# when requested
|
||||||
|
|
||||||
# FIXME: this check should be done first
|
|
||||||
if options.taskbar and os.name != 'nt':
|
|
||||||
die('taskbar not supported on this platform')
|
|
||||||
|
|
||||||
root = None
|
root = None
|
||||||
|
|
||||||
if (not options.nogui and options.password == '<ask>') or options.taskbar:
|
if (not options.nogui and options.password == '<ask>') or options.taskbar:
|
||||||
|
|||||||
Reference in new issue
Block a user