本文整理汇总了Python中werkzeug._internal._log函数的典型用法代码示例。如果您正苦于以下问题:Python _log函数的具体用法?Python _log怎么用?Python _log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: restart_with_reloader
def restart_with_reloader():
"""Spawn a new Python interpreter with the same arguments as this one,
but running the reloader thread.
"""
while 1:
_log('info', ' * Restarting with reloader')
requires_shell = False
if sys.executable:
args = [sys.executable] + sys.argv
else:
args, requires_shell = detect_executable()
new_environ = os.environ.copy()
new_environ['WERKZEUG_RUN_MAIN'] = 'true'
# a weird bug on windows. sometimes unicode strings end up in the
# environment and subprocess.call does not like this, encode them
# to latin1 and continue.
if os.name == 'nt' and PY2:
for key, value in iteritems(new_environ):
if isinstance(value, text_type):
new_environ[key] = value.encode('iso-8859-1')
exit_code = subprocess.call(args, env=new_environ, shell=requires_shell)
if exit_code != 3:
return exit_code
示例2: thumbs
def thumbs():
# not good (type of values) but something like this
infile = request.args.get('file', None)
width = request.args.get('width', 120)
height = request.args.get('height', 90)
quality = request.args.get('quality', 100)
crop = request.args.get('crop', False)
origfile = os.path.join(basedir, app.static_folder + infile)
if not os.path.isfile(origfile):
infile = '/img/nopic.jpg'
origfile = os.path.join(basedir, app.static_folder + infile)
filehash = sha1(infile.encode('utf-8')).hexdigest()
#cached_file = os.path.basename(infile).rsplit('.',1)[0] + \
# '_' + width + 'x' + height + '.' + \
# os.path.basename(infile).rsplit('.',1)[1]
cached_file = filehash + \
'_' + width + 'x' + height + '.' + \
os.path.basename(infile).rsplit('.', 1)[1]
newpath = os.path.join(basedir, app.static_folder + '/img/cache/' + cached_file)
if os.path.isfile(newpath):
_log('info', newpath)
return send_file(newpath)
resize(Image.open(origfile), (int(width), int(height)), crop, newpath, quality)
return send_file(newpath, add_etags=False)
示例3: restart_with_reloader
def restart_with_reloader():
"""Spawn a new Python interpreter with the same arguments as this one,
but running the reloader thread.
"""
while 1:
_log('info', ' * Restarting with reloader')
#args = [sys.executable] + sys.argv
args = ['moin.py','server','standalone']
new_environ = os.environ.copy()
new_environ['WERKZEUG_RUN_MAIN'] = 'true'
# a weird bug on windows. sometimes unicode strings end up in the
# environment and subprocess.call does not like this, encode them
# to latin1 and continue.
if os.name == 'nt':
for key, value in new_environ.iteritems():
if isinstance(value, unicode):
new_environ[key] = value.encode('iso-8859-1')
shell = True
else:
shell = False
exit_code = subprocess.call(args, env=new_environ, shell=shell)
if exit_code != 3:
return exit_code
示例4: werk_log
def werk_log(self, type, message, *args):
try:
msg = '%s - - [%s] %s' % (
self.address_string(),
self.log_date_time_string(),
message % args,
)
http_code = str(args[1])
except:
return _orig_log(type, message, *args)
# Utilize terminal colors, if available
if http_code[0] == '2':
# Put 2XX first, since it should be the common case
msg = _style.HTTP_SUCCESS(msg)
elif http_code[0] == '1':
msg = _style.HTTP_INFO(msg)
elif http_code == '304':
msg = _style.HTTP_NOT_MODIFIED(msg)
elif http_code[0] == '3':
msg = _style.HTTP_REDIRECT(msg)
elif http_code == '404':
msg = _style.HTTP_NOT_FOUND(msg)
elif http_code[0] == '4':
msg = _style.HTTP_BAD_REQUEST(msg)
else:
# Any 5XX, or any other response
msg = _style.HTTP_SERVER_ERROR(msg)
_log(type, msg)
示例5: restart_with_reloader
def restart_with_reloader(self):
"""Spawn a new Python interpreter with the same arguments as this one,
but running the reloader thread.
"""
while 1:
_log('info', ' * Restarting with %s' % self.name)
args = _get_args_for_reloading()
# a weird bug on windows. sometimes unicode strings end up in the
# environment and subprocess.call does not like this, encode them
# to latin1 and continue.
if os.name == 'nt' and PY2:
new_environ = {}
for key, value in iteritems(os.environ):
if isinstance(key, text_type):
key = key.encode('iso-8859-1')
if isinstance(value, text_type):
value = value.encode('iso-8859-1')
new_environ[key] = value
else:
new_environ = os.environ.copy()
new_environ['WERKZEUG_RUN_MAIN'] = 'true'
exit_code = subprocess.call(args, env=new_environ,
close_fds=False)
if exit_code != 3:
return exit_code
示例6: run
def run(self):
watches = {}
observer = self.observer_class()
observer.start()
to_delete = set(watches)
paths = _find_observable_paths(self.extra_files)
for path in paths:
if path not in watches:
try:
watches[path] = observer.schedule(
self.event_handler, path, recursive=True)
except OSError as e:
message = str(e)
if message != "Path is not a directory":
# Log the exception
_log('error', message)
# Clear this path from list of watches We don't want
# the same error message showing again in the next
# iteration.
watches[path] = None
to_delete.discard(path)
for path in to_delete:
watch = watches.pop(path, None)
if watch is not None:
observer.unschedule(watch)
self.observable_paths = paths
yield from self.should_reload.wait()
sys.exit(3)
示例7: pauseSession
def pauseSession():
u = User.query.get(session['userID'])
_log("info", u.__str__())
s = u.getRunningSession()
s.startPause()
return "gepauzeerd"
示例8: log_request
def log_request(self, code='-', size='-'):
_log('info', '%s -- [%s] %s %s',
self.address_string(),
self.requestline,
code,
size
)
示例9: run_simple
def run_simple(hostname, port, application, use_reloader=False,
use_debugger=False, use_evalex=True, extra_files=None,
reloader_interval=1, passthrough_errors=False,
ssl_context=None):
if use_debugger:
from werkzeug.debug import DebuggedApplication
application = DebuggedApplication(application, use_evalex)
def serve_forever():
make_server(hostname, port, application,
passthrough_errors=passthrough_errors,
ssl_context=ssl_context).serve_forever()
if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
display_hostname = hostname != '*' and hostname or 'localhost'
if ':' in display_hostname:
display_hostname = '[%s]' % display_hostname
_log('info', ' * Running on %s://%s:%d/', ssl_context is None
and 'http' or 'https', display_hostname, port)
if use_reloader:
open_test_socket(hostname, port)
run_with_reloader(serve_forever, extra_files, reloader_interval)
else:
serve_forever()
示例10: _reloader_stat_loop
def _reloader_stat_loop(extra_files=None, interval=1):
"""When this function is run from the main thread, it will force other
threads to exit when any modules currently loaded change.
Copyright notice. This function is based on the autoreload.py from
the CherryPy trac which originated from WSGIKit which is now dead.
:param extra_files: a list of additional files it should watch.
"""
from itertools import chain
mtimes = {}
while 1:
for filename in chain(_iter_module_files(), extra_files or ()):
try:
mtime = os.stat(filename).st_mtime
except OSError:
continue
old_time = mtimes.get(filename)
if old_time is None:
mtimes[filename] = mtime
continue
elif mtime > old_time:
_log("info", " * Detected change in %r, reloading" % filename)
sys.exit(3)
time.sleep(interval)
示例11: reloader_loop
def reloader_loop(extra_files = None, interval = 1):
def iter_module_files():
for module in sys.modules.values():
filename = getattr(module, '__file__', None)
if filename:
old = None
while not os.path.isfile(filename):
old = filename
filename = os.path.dirname(filename)
if filename == old:
break
else:
if filename[-4:] in ('.pyc', '.pyo'):
filename = filename[:-1]
yield filename
mtimes = {}
while 1:
for filename in chain(iter_module_files(), extra_files or ()):
try:
mtime = os.stat(filename).st_mtime
except OSError:
continue
old_time = mtimes.get(filename)
if old_time is None:
mtimes[filename] = mtime
continue
elif mtime > old_time:
_log('info', ' * Detected change in %r, reloading' % filename)
sys.exit(3)
time.sleep(interval)
示例12: run_simple
def run_simple(hostname, port, application, use_reloader=False,
use_debugger=False, use_evalex=True, extra_files=None,
reloader_interval=1, passthrough_errors=False, processes=None,
threaded=False, ssl_context=None):
if use_debugger:
from werkzeug.debug import DebuggedApplication
application = DebuggedApplication(application, use_evalex)
processes = max(processes, 1)
def serve_forever():
make_server(hostname, port, application, processes=processes,
threaded=threaded, passthrough_errors=passthrough_errors,
ssl_context=ssl_context).serve_forever()
def serve_error_app(tb_str, monitored_files):
from clastic import flaw
err_app = flaw.create_app(tb_str, monitored_files)
err_server = make_server(hostname, port, err_app)
thread.start_new_thread(err_server.serve_forever, ())
return err_server
if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
display_hostname = hostname != '*' and hostname or 'localhost'
if ':' in display_hostname:
display_hostname = '[%s]' % display_hostname
_log('info', ' * Running on %s://%s:%d/', ssl_context is None
and 'http' or 'https', display_hostname, port)
if use_reloader:
open_test_socket(hostname, port)
run_with_reloader(serve_forever, extra_files, reloader_interval,
error_func=serve_error_app)
else:
serve_forever()
示例13: log_pin_request
def log_pin_request(self):
"""Log the pin if needed."""
if self.pin_logging and self.pin is not None:
_log('info', ' * To enable the debugger you need to '
'enter the security pin:')
_log('info', ' * Debugger pin code: %s' % self.pin)
return Response('')
示例14: restart_with_reloader
def restart_with_reloader():
"""Spawn a new Python interpreter with the same arguments as this one,
but running the reloader thread.
"""
while 1:
_log('info', ' * Restarting with reloader')
#fix lastest python version entry_point script file incompatible bug
if sys.argv[0].endswith('.pyw') or sys.argv[0].endswith('.py'):
args = [sys.executable] + sys.argv
else:
args = sys.argv
new_environ = os.environ.copy()
new_environ['WERKZEUG_RUN_MAIN'] = 'true'
# a weird bug on windows. sometimes unicode strings end up in the
# environment and subprocess.call does not like this, encode them
# to latin1 and continue.
if os.name == 'nt' and PY2:
for key, value in iteritems(new_environ):
if isinstance(value, text_type):
new_environ[key] = value.encode('iso-8859-1')
exit_code = subprocess.call(args, env=new_environ)
if exit_code != 3:
return exit_code
示例15: run_simple
def run_simple(
hostname,
port,
application,
use_reloader=False,
use_debugger=False,
use_evalex=True,
extra_files=None,
reloader_interval=1,
reloader_type="auto",
threaded=False,
processes=1,
request_handler=None,
static_files=None,
passthrough_errors=False,
ssl_context=None,
):
if use_debugger:
from werkzeug.debug import DebuggedApplication
application = DebuggedApplication(application, use_evalex)
if static_files:
from werkzeug.wsgi import SharedDataMiddleware
application = SharedDataMiddleware(application, static_files)
def inner():
# Override here
make_server(
hostname, port, application, threaded, processes, request_handler, passthrough_errors, ssl_context
).serve_forever()
if os.environ.get("WERKZEUG_RUN_MAIN") != "true":
display_hostname = hostname != "*" and hostname or "localhost"
if ":" in display_hostname:
display_hostname = "[%s]" % display_hostname
quit_msg = "(Press CTRL+C to quit)"
_log(
"info",
" * Running on %s://%s:%d/ %s",
ssl_context is None and "http" or "https",
display_hostname,
port,
quit_msg,
)
if use_reloader:
# Create and destroy a socket so that any exceptions are raised before
# we spawn a separate Python interpreter and lose this ability.
address_family = select_ip_version(hostname, port)
test_socket = socket.socket(address_family, socket.SOCK_STREAM)
test_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
test_socket.bind((hostname, port))
test_socket.close()
from werkzeug._reloader import run_with_reloader
run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
else:
inner()