本文整理汇总了Python中aspen.log_dammit函数的典型用法代码示例。如果您正苦于以下问题:Python log_dammit函数的具体用法?Python log_dammit怎么用?Python log_dammit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log_dammit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_conflict_over_port
def handle_conflict_over_port(exception, website):
"""Be friendly about port conflicts.
The traceback one gets from a port conflict or permission error is not that
friendly. Here's a helper to let the user know (in color?!) that a port
conflict or a permission error is probably the problem. But in case it
isn't (website.start fires the start hook, and maybe the user tries to
connect to a network service in there?), don't fully swallow the exception.
Also, be explicit about the port number. What if they have logging turned
off? Then they won't see the port number in the "Greetings, program!" line.
They definitely won't see it if using an engine like eventlet that binds to
the port early.
"""
if exception.__class__ is not socket.error:
return
if website.network_port is not None:
msg = "Is something already running on port %s? Because ..."
if not aspen.WINDOWS:
if website.network_port < 1024:
if os.geteuid() > 0:
msg = ("Do you have permission to bind to port %s?"
" Because ...")
msg %= website.network_port
if not aspen.WINDOWS:
# Assume we can use ANSI color escapes if not on Windows.
# XXX Maybe a bad assumption if this is going into a log
# file? See also: colorama
msg = '\033[01;33m%s\033[00m' % msg
aspen.log_dammit(msg)
raise
示例2: log_traceback_for_5xx
def log_traceback_for_5xx(response, traceback=None):
if response.code >= 500:
if traceback:
aspen.log_dammit(traceback)
else:
aspen.log_dammit(response.body)
return {'traceback': None}
示例3: main
def main(argv=None):
"""http://aspen.io/cli/
"""
try:
_main(argv)
except (SystemExit, KeyboardInterrupt):
# Under some (most?) network engines, a SIGINT will be trapped by the
# SIGINT signal handler above. However, gevent does "something" with
# signals and our signal handler never fires. However, we *do* get a
# KeyboardInterrupt here in that case. *shrug*
#
# See: https://github.com/gittip/aspen-python/issues/196
pass
except:
import aspen, aspen.execution, time, traceback
aspen.log_dammit("Oh no! Aspen crashed!")
aspen.log_dammit(traceback.format_exc())
try:
while 1:
aspen.execution.check_all()
time.sleep(1)
except KeyboardInterrupt:
raise SystemExit
示例4: handle_error_nicely
def handle_error_nicely(self, request):
"""Try to provide some nice error handling.
"""
try: # nice error messages
tb_1 = traceback.format_exc()
response = sys.exc_info()[1]
if not isinstance(response, Response):
aspen.log_dammit(tb_1)
response = Response(500, tb_1)
elif 200 <= response.code < 300:
return response
response.request = request
self.hooks.outbound_early.run(response)
fs = self.ours_or_theirs(str(response.code) + '.html')
if fs is None:
fs = self.ours_or_theirs('error.html')
if fs is None:
raise
request.fs = fs
request.original_resource = request.resource
request.resource = resources.get(request)
response = request.resource.respond(request, response)
return response
except Response, response: # no nice error simplate available
raise
示例5: update_homepage_queries_once
def update_homepage_queries_once(db):
with db.get_cursor() as cursor:
log_dammit("updating homepage queries")
start = time.time()
cursor.execute("DELETE FROM homepage_top_givers")
cursor.execute("""
INSERT INTO homepage_top_givers (username, anonymous, amount, avatar_url, statement, number)
SELECT username, anonymous_giving, giving, avatar_url, statement, number
FROM participants
WHERE is_suspicious IS NOT true
AND last_bill_result = ''
ORDER BY giving DESC
LIMIT 100;
""".strip())
cursor.execute("DELETE FROM homepage_top_receivers")
cursor.execute("""
INSERT INTO homepage_top_receivers (username, anonymous, amount, avatar_url, statement, number)
SELECT username, anonymous_receiving, receiving, avatar_url, statement, number
FROM participants
WHERE is_suspicious IS NOT true
AND claimed_time IS NOT NULL
ORDER BY receiving DESC
LIMIT 100;
""".strip())
end = time.time()
elapsed = end - start
log_dammit("updated homepage queries in %.2f seconds" % elapsed)
示例6: __init__
def __init__(self, env, db, tell_sentry, root):
if self._have_ses(env):
log_dammit("AWS SES is configured! We'll send mail through SES.")
self._mailer = boto3.client( service_name='ses'
, region_name=env.aws_ses_default_region
, aws_access_key_id=env.aws_ses_access_key_id
, aws_secret_access_key=env.aws_ses_secret_access_key
)
else:
log_dammit("AWS SES is not configured! Mail will be dumped to the console here.")
self._mailer = ConsoleMailer()
self.db = db
self.tell_sentry = tell_sentry
self.sleep_for = env.email_queue_sleep_for
self.allow_up_to = env.email_queue_allow_up_to
self.log_every = env.email_queue_log_metrics_every
templates = {}
templates_dir = os.path.join(root, 'emails')
assert os.path.isdir(templates_dir)
i = len(templates_dir) + 1
for spt in find_files(templates_dir, '*.spt'):
base_name = spt[i:-4]
templates[base_name] = compile_email_spt(spt)
self._email_templates = templates
示例7: log_traceback_for_exception
def log_traceback_for_exception(website, exception):
tb = traceback.format_exc()
aspen.log_dammit(tb)
response = Response(500)
if website.show_tracebacks:
response.body = tb
return {'response': response, 'exception': None}
示例8: f
def f():
while True:
try:
func()
except Exception, e:
self.website.tell_sentry(e, {})
log_dammit(traceback.format_exc().strip())
sleep(period)
示例9: update_homepage_queries_once
def update_homepage_queries_once(db):
with db.get_cursor() as cursor:
log_dammit("updating homepage queries")
start = time.time()
cursor.execute("DELETE FROM homepage_top_givers")
cursor.execute("""
INSERT INTO homepage_top_givers (username, anonymous, amount, avatar_url, statement, number)
SELECT tipper, anonymous_giving, sum(amount) AS amount, avatar_url, statement, number
FROM ( SELECT DISTINCT ON (tipper, tippee)
amount
, tipper
FROM tips
JOIN participants p ON p.username = tipper
JOIN participants p2 ON p2.username = tippee
JOIN elsewhere ON elsewhere.participant = tippee
WHERE p.last_bill_result = ''
AND p.is_suspicious IS NOT true
AND p2.claimed_time IS NOT NULL
AND elsewhere.is_locked = false
ORDER BY tipper, tippee, mtime DESC
) AS foo
JOIN participants p ON p.username = tipper
WHERE is_suspicious IS NOT true
GROUP BY tipper, anonymous_giving, avatar_url, statement, number
ORDER BY amount DESC
LIMIT 100;
""".strip())
cursor.execute("DELETE FROM homepage_top_receivers")
cursor.execute("""
INSERT INTO homepage_top_receivers (username, anonymous, amount, avatar_url, statement, number)
SELECT tippee, anonymous_receiving, sum(amount) AS amount, avatar_url, statement, number
FROM ( SELECT DISTINCT ON (tipper, tippee)
amount
, tippee
FROM tips
JOIN participants p ON p.username = tipper
JOIN elsewhere ON elsewhere.participant = tippee
WHERE last_bill_result = ''
AND elsewhere.is_locked = false
AND is_suspicious IS NOT true
AND claimed_time IS NOT null
ORDER BY tipper, tippee, mtime DESC
) AS foo
JOIN participants p ON p.username = tippee
WHERE is_suspicious IS NOT true
GROUP BY tippee, anonymous_receiving, avatar_url, statement, number
ORDER BY amount DESC
LIMIT 100;
""".strip())
end = time.time()
elapsed = end - start
log_dammit("updated homepage queries in %.2f seconds" % elapsed)
示例10: inbound
def inbound(request):
"""Given a Request object, reject it if it's a forgery.
"""
if request.line.uri.startswith('/assets/'): return
try:
csrf_token = request.headers.cookie.get('csrf_token')
csrf_token = '' if csrf_token is None else csrf_token.value
csrf_token = _sanitize_token(csrf_token)
except KeyError:
csrf_token = _get_new_csrf_key()
request.context['csrf_token'] = csrf_token
# Assume that anything not defined as 'safe' by RC2616 needs protection
if request.line.method not in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):
if _is_secure(request):
# Suppose user visits http://example.com/
# An active network attacker (man-in-the-middle, MITM) sends a
# POST form that targets https://example.com/detonate-bomb/ and
# submits it via JavaScript.
#
# The attacker will need to provide a CSRF cookie and token, but
# that's no problem for a MITM and the session-independent
# nonce we're using. So the MITM can circumvent the CSRF
# protection. This is true for any HTTP connection, but anyone
# using HTTPS expects better! For this reason, for
# https://example.com/ we need additional protection that treats
# http://example.com/ as completely untrusted. Under HTTPS,
# Barth et al. found that the Referer header is missing for
# same-domain requests in only about 0.2% of cases or less, so
# we can use strict Referer checking.
referer = request.headers.get('Referer')
if referer is None:
raise Response(403, REASON_NO_REFERER)
good_referer = 'https://%s/' % _get_host(request)
if not same_origin(referer, good_referer):
reason = REASON_BAD_REFERER % (referer, good_referer)
log_dammit(reason)
raise Response(403, reason)
if csrf_token is None:
raise Response(403, REASON_NO_CSRF_COOKIE)
# Check non-cookie token for match.
request_csrf_token = ""
if request.line.method == "POST":
request_csrf_token = request.body.get('csrf_token', '')
if request_csrf_token == "":
# Fall back to X-CSRF-TOKEN, to make things easier for AJAX,
# and possible for PUT/DELETE.
request_csrf_token = request.headers.get('X-CSRF-TOKEN', '')
if not constant_time_compare(request_csrf_token, csrf_token):
raise Response(403, REASON_BAD_TOKEN)
示例11: handle_error_at_all
def handle_error_at_all(self, tb_1):
tb_2 = traceback.format_exc().strip()
tbs = '\n\n'.join([tb_2, "... while handling ...", tb_1])
aspen.log_dammit(tbs)
if self.show_tracebacks:
response = Response(500, tbs)
else:
response = Response(500)
return response
示例12: f
def f():
if period <= 0:
return
sleep = time.sleep
while 1:
try:
func()
except Exception, e:
tell_sentry(e)
log_dammit(traceback.format_exc().strip())
sleep(period)
示例13: tell_sentry
def tell_sentry(request):
cls, response = sys.exc_info()[:2]
if cls is aspen.Response:
if response.code < 500:
return
kw = {'extra': { "filepath": request.fs
, "request": str(request).splitlines()
}}
exc = sentry.captureException(**kw)
ident = sentry.get_ident(exc)
aspen.log_dammit("Exception reference: " + ident)
示例14: stop
def stop(website):
"""Stop the server.
"""
if website is None:
return
aspen.log_dammit("Shutting down Aspen website.")
website.network_engine.stop()
if hasattr(socket, 'AF_UNIX'):
if website.network_sockfam == socket.AF_UNIX:
if os.path.exists(website.network_address):
os.remove(website.network_address)
示例15: update_homepage_queries
def update_homepage_queries():
from gittip import utils
while 1:
try:
utils.update_global_stats(website)
utils.update_homepage_queries_once(website.db)
website.db.self_check()
except:
exception = sys.exc_info()[0]
tell_sentry(exception)
tb = traceback.format_exc().strip()
log_dammit(tb)
time.sleep(UPDATE_HOMEPAGE_EVERY)