本文整理汇总了Python中aspen.log_dammit函数的典型用法代码示例。如果您正苦于以下问题:Python log_dammit函数的具体用法?Python log_dammit怎么用?Python log_dammit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log_dammit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:BigBlueHat,项目名称:aspen-python,代码行数:32,代码来源:server.py
示例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}
开发者ID:amitkot,项目名称:aspen-python,代码行数:7,代码来源:website.py
示例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
开发者ID:nejstastnejsistene,项目名称:aspen-python,代码行数:25,代码来源:server.py
示例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
开发者ID:allisonmobley,项目名称:aspen,代码行数:25,代码来源:website.py
示例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)
开发者ID:barmoshe,项目名称:www.gittip.com,代码行数:33,代码来源:__init__.py
示例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
开发者ID:cyberjacob,项目名称:www.gittip.com,代码行数:26,代码来源:email.py
示例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}
开发者ID:joeyespo,项目名称:aspen-python,代码行数:7,代码来源:website.py
示例8: f
def f():
while True:
try:
func()
except Exception, e:
self.website.tell_sentry(e, {})
log_dammit(traceback.format_exc().strip())
sleep(period)
开发者ID:cyberjacob,项目名称:www.gittip.com,代码行数:8,代码来源:cron.py
示例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)
开发者ID:mushketyk,项目名称:www.gittip.com,代码行数:58,代码来源:__init__.py
示例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)
开发者ID:Alive-AttemptTheLifeGangHouse,项目名称:www.gittip.com,代码行数:58,代码来源:csrf.py
示例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
开发者ID:joonas,项目名称:aspen,代码行数:9,代码来源:website.py
示例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)
开发者ID:maryannbanks,项目名称:www.gittip.com,代码行数:11,代码来源:configure-aspen.py
示例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)
开发者ID:hashar,项目名称:www.gittip.com,代码行数:12,代码来源:wireup.py
示例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)
开发者ID:BigBlueHat,项目名称:aspen-python,代码行数:12,代码来源:server.py
示例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)
开发者ID:Solution4Future,项目名称:www.gittip.com,代码行数:13,代码来源:configure-aspen.py
示例16: 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)
except:
if tell_sentry:
tell_sentry(None)
else:
tb = traceback.format_exc().strip()
log_dammit(tb)
time.sleep(UPDATE_HOMEPAGE_EVERY)
开发者ID:joeyespo,项目名称:www.gittip.com,代码行数:14,代码来源:configure-aspen.py
示例17: bind_server_to_port
def bind_server_to_port(website):
"""
"""
if hasattr(socket, 'AF_UNIX'):
if website.network_sockfam == socket.AF_UNIX:
if os.path.exists(website.network_address):
aspen.log("Removing stale socket.")
os.remove(website.network_address)
if website.network_port is not None:
welcome = "port %d" % website.network_port
else:
welcome = website.network_address
aspen.log("Starting %s engine." % website.network_engine.name)
website.network_engine.bind()
aspen.log_dammit("Greetings, program! Welcome to %s." % welcome)
开发者ID:BigBlueHat,项目名称:aspen-python,代码行数:15,代码来源:server.py
示例18: main
def main(argv=None):
"""http://aspen.io/cli/
"""
try:
_main(argv)
except KeyboardInterrupt:
raise SystemExit(75) # 75 == INT
except SystemExit:
pass
except:
import aspen, traceback
aspen.log_dammit("Oh no! Server crashed!")
aspen.log_dammit(traceback.format_exc())
raise SystemExit(1) # 1 == Other
开发者ID:jarpineh,项目名称:aspen,代码行数:15,代码来源:server.py
示例19: main
def main(argv=None):
"""http://aspen.io/cli/
"""
try:
_main(argv)
except SystemExit:
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
开发者ID:allisonmobley,项目名称:aspen,代码行数:17,代码来源:server.py
示例20: f
def f():
if period <= 0:
return
sleep = time.sleep
if exclusive:
cursor = conn.cursor()
try_lock = lambda: cursor.one("SELECT pg_try_advisory_lock(0)")
has_lock = False
while 1:
try:
if exclusive and not has_lock:
has_lock = try_lock()
if not exclusive or has_lock:
func()
except Exception, e:
tell_sentry(e)
log_dammit(traceback.format_exc().strip())
sleep(period)
开发者ID:colindean,项目名称:www.gittip.com,代码行数:18,代码来源:configure-aspen.py
注:本文中的aspen.log_dammit函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论