本文整理汇总了Python中tornado.log.app_log.warn函数的典型用法代码示例。如果您正苦于以下问题:Python warn函数的具体用法?Python warn怎么用?Python warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: reraise_client_error
def reraise_client_error(self, exc):
"""Remote fetch raised an error"""
try:
url = exc.response.request.url.split('?')[0]
body = exc.response.body.decode('utf8', 'replace').strip()
except AttributeError:
url = 'url'
body = ''
msg = self.client_error_message(exc, url, body)
slim_body = escape(body[:300])
app_log.warn("Fetching %s failed with %s. Body=%s", url, msg, slim_body)
if exc.code == 599:
if isinstance(exc, CurlError):
en = getattr(exc, 'errno', -1)
# can't connect to server should be 404
# possibly more here
if en in (pycurl.E_COULDNT_CONNECT, pycurl.E_COULDNT_RESOLVE_HOST):
raise web.HTTPError(404, msg)
# otherwise, raise 400 with informative message:
raise web.HTTPError(400, msg)
if exc.code >= 500:
# 5XX, server error, but not this server
raise web.HTTPError(502, msg)
else:
# client-side error, blame our client
if exc.code == 404:
raise web.HTTPError(404, "Remote %s" % msg)
else:
raise web.HTTPError(400, msg)
开发者ID:raphael-proust,项目名称:nbviewer,代码行数:32,代码来源:base.py
示例2: get
def get(self, path):
localfile_path = os.path.abspath(
self.settings.get('localfile_path', ''))
abspath = os.path.abspath(os.path.join(
localfile_path,
path
))
app_log.info("looking for file: '%s'" % abspath)
if not abspath.startswith(localfile_path):
app_log.warn("directory traversal attempt: '%s'" % localfile_path)
raise web.HTTPError(404)
if not os.path.exists(abspath):
raise web.HTTPError(404)
with io.open(abspath, encoding='utf-8') as f:
nbdata = f.read()
yield self.finish_notebook(nbdata, download_url=path,
msg="file from localfile: %s" % path,
public=False,
format=self.format,
request=self.request)
开发者ID:01-,项目名称:nbviewer,代码行数:27,代码来源:handlers.py
示例3: get_error_html
def get_error_html(self, status_code, **kwargs):
"""render custom error pages"""
exception = kwargs.get('exception')
message = ''
status_message = responses.get(status_code, 'Unknown')
if exception:
# get the custom message, if defined
try:
message = exception.log_message % exception.args
except Exception:
pass
# construct the custom reason, if defined
reason = getattr(exception, 'reason', '')
if reason:
status_message = reason
# build template namespace
ns = dict(
status_code=status_code,
status_message=status_message,
message=message,
exception=exception,
)
# render the template
try:
html = self.render_template('%d.html' % status_code, **ns)
except Exception as e:
app_log.warn("No template for %d", status_code)
html = self.render_template('error.html', **ns)
return html
开发者ID:mariusvniekerk,项目名称:nbviewer,代码行数:32,代码来源:handlers.py
示例4: wait_for_http_server
def wait_for_http_server(url, timeout=10):
"""Wait for an HTTP Server to respond at url
Any non-5XX response code will do, even 404.
"""
loop = ioloop.IOLoop.current()
tic = loop.time()
client = AsyncHTTPClient()
while loop.time() - tic < timeout:
try:
r = yield client.fetch(url, follow_redirects=False)
except HTTPError as e:
if e.code >= 500:
# failed to respond properly, wait and try again
if e.code != 599:
# we expect 599 for no connection,
# but 502 or other proxy error is conceivable
app_log.warn("Server at %s responded with error: %s", url, e.code)
yield gen.Task(loop.add_timeout, loop.time() + 0.25)
else:
app_log.debug("Server at %s responded with %s", url, e.code)
return
except (OSError, socket.error) as e:
if e.errno not in {errno.ECONNABORTED, errno.ECONNREFUSED, errno.ECONNRESET}:
app_log.warn("Failed to connect to %s (%s)", url, e)
yield gen.Task(loop.add_timeout, loop.time() + 0.25)
else:
return
raise TimeoutError("Server at {url} didn't respond in {timeout} seconds".format(
**locals()
))
开发者ID:Josue-Martinez-Moreno,项目名称:jupyterhub,代码行数:32,代码来源:utils.py
示例5: _log_rate_limit
def _log_rate_limit(self, future):
"""log GitHub rate limit headers
- error if 0 remaining
- warn if 10% or less remain
- debug otherwise
"""
try:
r = future.result()
except HTTPError as e:
r = e.response
limit_s = r.headers.get("X-RateLimit-Limit", "")
remaining_s = r.headers.get("X-RateLimit-Remaining", "")
if not remaining_s or not limit_s:
if r.code < 300:
app_log.warn("No rate limit headers. Did GitHub change? %s", json.dumps(r.headers, indent=1))
return
remaining = int(remaining_s)
limit = int(limit_s)
if remaining == 0:
jsondata = response_text(r)
data = json.loads(jsondata)
app_log.error("GitHub rate limit (%s) exceeded: %s", limit, data.get("message", "no message"))
return
if 10 * remaining > limit:
log = app_log.debug
else:
log = app_log.warn
log("%i/%i GitHub API requests remaining", remaining, limit)
开发者ID:f3r,项目名称:nbviewer,代码行数:31,代码来源:client.py
示例6: write_error
def write_error(self, status_code, **kwargs):
"""render custom error pages"""
exc_info = kwargs.get('exc_info')
message = ''
status_message = responses.get(status_code, 'Unknown')
if exc_info:
# get the custom message, if defined
exception = exc_info[1]
try:
message = exception.log_message % exception.args
except Exception:
pass
# construct the custom reason, if defined
reason = getattr(exception, 'reason', '')
if reason:
status_message = reason
# build template namespace
ns = dict(
status_code=status_code,
status_message=status_message,
message=message,
exception=exception,
)
# render the template
try:
html = self.render_template('%d.html' % status_code, **ns)
except Exception as e:
app_log.warn("No template for %d", status_code)
html = self.render_template('error.html', **ns)
self.set_header('Content-Type', 'text/html')
self.write(html)
开发者ID:Parsely,项目名称:nbviewer,代码行数:34,代码来源:handlers.py
示例7: reraise_client_error
def reraise_client_error(self, exc):
"""Remote fetch raised an error"""
try:
url = exc.response.request.url
except AttributeError:
url = 'url'
app_log.warn("Fetching %s failed with %s", url, exc)
if exc.code == 599:
str_exc = str(exc)
# strip the unhelpful 599 prefix
if str_exc.startswith('HTTP 599: '):
str_exc = str_exc[10:]
if isinstance(exc, CurlError):
en = getattr(exc, 'errno', -1)
# can't connect to server should be 404
# possibly more here
if en in (pycurl.E_COULDNT_CONNECT, pycurl.E_COULDNT_RESOLVE_HOST):
raise web.HTTPError(404, str_exc)
# otherwise, raise 400 with informative message:
raise web.HTTPError(400, str_exc)
if exc.code >= 500:
# 5XX, server error, but not this server
raise web.HTTPError(502, str(exc))
else:
if exc.code == 404:
raise web.HTTPError(404, "Remote %s" % exc)
else:
# client-side error, blame our client
raise web.HTTPError(400, str(exc))
开发者ID:franblas,项目名称:beaker-sharing-server,代码行数:29,代码来源:handlers.py
示例8: add_friend
def add_friend(self, friend):
if not self.check_friend(friend):
_conn.execute('''INSERT INTO tbl_friends (f_user_id, friend_id) VALUES (?, ?)''', (self.user_id, friend.user_id))
_conn.commit()
else:
app_log.warn("{!r} is already a friend of {!r}".format(friend.username, self.username))
raise FriendAlreadyAdded('{} has already been added as a friend of {}'.format(friend.username, self.username))
开发者ID:joshleeb,项目名称:PerfectGift,代码行数:7,代码来源:api.py
示例9: get
def get(self, path):
localfile_path = os.path.abspath(
self.settings.get('localfile_path', ''))
abspath = os.path.abspath(os.path.join(
localfile_path,
path
))
app_log.info("looking for file: '%s'" % abspath)
if not abspath.startswith(localfile_path):
app_log.warn("directory traversal attempt: '%s'" % localfile_path)
raise web.HTTPError(404)
if not os.path.exists(abspath):
raise web.HTTPError(404)
if not os.path.isfile(abspath):
base_url='/localfile'
contents=os.listdir(abspath)
dirs=[]
others=[]
ipynbs=[]
entries=[]
for c in contents:
e={}
e['name']=c
e['url']=os.path.join(base_url,path,c)
subpath=os.path.join(abspath,c)
if os.path.isdir(subpath):
e['class']='fa-folder-open'
dirs.append(e)
elif os.path.isfile(subpath):
if c.endswith('.ipynb'):
e['class']='fa-book'
ipynbs.append(e)
else:
e['url']='javascript:alert("not allowed type!");'
e['class']='fa-folder-close'
others.append(e)
entries.extend(dirs)
entries.extend(ipynbs)
entries.extend(others)
breadcrumbs=self.breadcrumbs(path,base_url)
html=self.render_template('treelist.html',
entries=entries,breadcrumbs=breadcrumbs,tree_type='localfile',
tree_label='localfiels')
yield self.cache_and_finish(html)
else:
with io.open(abspath, encoding='utf-8') as f:
nbdata = f.read()
provider_url=os.path.join(base_url,path)
yield self.finish_notebook(nbdata, download_url=path,
provider_url=provider_url,
msg="file from localfile: %s" % path,
public=False,
format=self.format,
request=self.request)
开发者ID:xxxspy,项目名称:nbviewer,代码行数:59,代码来源:handlers.py
示例10: find_uid
def find_uid(cls, uid):
cur = _conn.execute('''SELECT rowid AS user_id, fname, lname, username, email, image, dob FROM tbl_users WHERE rowid = ? LIMIT 1''', (uid,))
row = cur.fetchone()
if not row:
app_log.warn("user with the uid {} could not be found".format(uid))
raise UserNotFound('Uid {} does not exist'.format(uid))
return cls(**row)
开发者ID:joshleeb,项目名称:PerfectGift,代码行数:9,代码来源:api.py
示例11: find
def find(cls, product_id):
cur = _conn.execute('''SELECT p.rowid AS product_id, p.name, p.image, p.link, p.description, p.price, i.checked FROM tbl_products AS p LEFT JOIN tbl_list_item AS i ON p.rowid = i.product_id WHERE p.rowid = ? LIMIT 1''', (product_id,))
row = cur.fetchone()
if not row:
app_log.warn("product {} could not be found".format(product_id))
raise ProductNotFound('{} does not exist'.format(product_id))
return cls(*row)
开发者ID:joshleeb,项目名称:PerfectGift,代码行数:9,代码来源:api.py
示例12: on_finish
def on_finish(self):
if self._pkg_fd is not None:
self._pkg_fd.close()
# md5_digest content not found
if self._need_md5:
app_log.warn('md5_digest disposition not found')
self._pkg_md5 = self._pkg_diggest.hexdigest()
self.write_md5()
开发者ID:hurie,项目名称:Tornado-PyPi-Proxy,代码行数:9,代码来源:handler.py
示例13: create_notebook_server
def create_notebook_server(self, base_path,
image="jupyter/demo",
ipython_executable="ipython3",
mem_limit="512m",
cpu_shares="1",
container_ip="127.0.0.1",
container_port=8888):
'''
Creates a notebook_server running off of `base_path`.
returns the container_id, ip, port in a Future
'''
templates = ['/srv/ga',
'/srv/ipython/IPython/html',
'/srv/ipython/IPython/html/templates']
tornado_settings = {'template_path': templates}
ipython_args = [
"notebook", "--no-browser",
"--port {}".format(container_port),
"--ip=0.0.0.0",
"--NotebookApp.base_url=/{}".format(base_path),
"--NotebookApp.tornado_settings=\"{}\"".format(tornado_settings)
]
ipython_command = ipython_executable + " " + " ".join(ipython_args)
command = [
"/bin/sh",
"-c",
ipython_command
]
resp = yield self.docker_client.create_container(image=image,
command=command,
mem_limit=mem_limit,
cpu_shares=cpu_shares)
docker_warnings = resp['Warnings']
if docker_warnings is not None:
app_log.warn(docker_warnings)
container_id = resp['Id']
app_log.info("Created container {}".format(container_id))
yield self.docker_client.start(container_id,
port_bindings={container_port: (container_ip,)})
container_network = yield self.docker_client.port(container_id,
container_port)
host_port = container_network[0]['HostPort']
host_ip = container_network[0]['HostIp']
raise gen.Return((container_id, host_ip, int(host_port)))
开发者ID:gitter-badger,项目名称:tmpnb,代码行数:57,代码来源:dockworker.py
示例14: create_notebook_server
def create_notebook_server(self, base_path, container_name, container_config):
'''Creates a notebook_server running off of `base_path`.
Returns the (container_id, ip, port) tuple in a Future.'''
port = container_config.container_port
app_log.debug(container_config)
# Assumes that the container_config.command is of a format like:
#
# ipython3 notebook --no-browser --port {port} --ip=0.0.0.0
# --NotebookApp.base_path=/{base_path}
# --NotebookApp.tornado_settings=\"{ \"template_path\": [ \"/srv/ga\",
# \"/srv/ipython/IPython/html\",
# \"/srv/ipython/IPython/html/templates\" ] }\""
#
# Important piece here is the parametrized base_path to let the
# underlying process know where the proxy is routing it.
rendered_command = container_config.command.format(base_path=base_path, port=port)
command = [
"/bin/sh",
"-c",
rendered_command
]
resp = yield self._with_retries(self.docker_client.create_container,
image=container_config.image,
command=command,
mem_limit=container_config.mem_limit,
cpu_shares=container_config.cpu_shares,
name=container_name)
docker_warnings = resp['Warnings']
if docker_warnings is not None:
app_log.warn(docker_warnings)
container_id = resp['Id']
app_log.info("Created container {}".format(container_id))
port_bindings = {
container_config.container_port: (container_config.container_ip,)
}
yield self._with_retries(self.docker_client.start,
container_id,
port_bindings=port_bindings)
container_network = yield self._with_retries(self.docker_client.port,
container_id,
container_config.container_port)
host_port = container_network[0]['HostPort']
host_ip = container_network[0]['HostIp']
raise gen.Return((container_id, host_ip, int(host_port)))
开发者ID:vishnuvr,项目名称:tmpnb,代码行数:56,代码来源:dockworker.py
示例15: cleanout
def cleanout(self):
'''Completely cleanout containers that are part of this pool.'''
app_log.info("Performing initial pool cleanup")
containers = yield self.spawner.list_notebook_servers(self.container_name_pattern, all=True)
for container in containers:
try:
app_log.debug("Clearing old container [%s] from pool", container['Id'])
yield self.spawner.shutdown_notebook_server(container['Id'])
except Exception as e:
app_log.warn(e)
开发者ID:vincentdavis,项目名称:tmpnb,代码行数:11,代码来源:spawnpool.py
示例16: get_current_user
def get_current_user(self):
"""Check admin API token, if any"""
if not self.admin_token:
return 'authorized'
client_token = self.request.headers.get('Authorization')
if client_token != 'token %s' % self.admin_token:
app_log.warn('Rejecting admin request with token %s', client_token)
return
else:
return 'authorized'
开发者ID:bshlgrs,项目名称:tmpnb,代码行数:11,代码来源:orchestrate.py
示例17: prepare
def prepare(self):
'''
Responds with a 401 error if the configured admin auth token is not
present in the request headers.
'''
if self.admin_token:
client_token = self.request.headers.get('Authorization')
if client_token != 'token %s' % self.admin_token:
app_log.warn('Rejecting admin request with token %s', client_token)
return self.send_error(401)
return super(AdminHandler, self).prepare()
开发者ID:vincentdavis,项目名称:tmpnb,代码行数:11,代码来源:orchestrate.py
示例18: user_for_cookie
def user_for_cookie(self, encrypted_cookie, use_cache=True):
"""Ask the Hub to identify the user for a given cookie.
Args:
encrypted_cookie (str): the cookie value (not decrypted, the Hub will do that)
use_cache (bool): Specify use_cache=False to skip cached cookie values (default: True)
Returns:
user_model (dict): The user model, if a user is identified, None if authentication fails.
The 'name' field contains the user's name.
"""
if use_cache:
cached = self.cookie_cache.get(encrypted_cookie)
if cached is not None:
return cached
try:
r = requests.get(
url_path_join(
self.api_url, "authorizations/cookie", self.cookie_name, quote(encrypted_cookie, safe="")
),
headers={"Authorization": "token %s" % self.api_token},
)
except requests.ConnectionError:
msg = "Failed to connect to Hub API at %r." % self.api_url
msg += " Is the Hub accessible at this URL (from host: %s)?" % socket.gethostname()
if "127.0.0.1" in self.api_url:
msg += (
" Make sure to set c.JupyterHub.hub_ip to an IP accessible to"
+ " single-user servers if the servers are not on the same host as the Hub."
)
raise HTTPError(500, msg)
if r.status_code == 404:
data = None
elif r.status_code == 403:
app_log.error(
"I don't have permission to verify cookies, my auth token may have expired: [%i] %s",
r.status_code,
r.reason,
)
raise HTTPError(500, "Permission failure checking authorization, I may need a new token")
elif r.status_code >= 500:
app_log.error("Upstream failure verifying auth token: [%i] %s", r.status_code, r.reason)
raise HTTPError(502, "Failed to check authorization (upstream problem)")
elif r.status_code >= 400:
app_log.warn("Failed to check authorization: [%i] %s", r.status_code, r.reason)
raise HTTPError(500, "Failed to check authorization")
else:
data = r.json()
self.cookie_cache[encrypted_cookie] = data
return data
开发者ID:jhamrick,项目名称:jupyterhub,代码行数:52,代码来源:auth.py
示例19: name_matches
def name_matches(container):
try:
names = container['Names']
if names is None:
app_log.warn("Docker API returned null Names, ignoring")
return False
except Exception:
app_log.warn("Invalid container: %r", container)
return False
for name in names:
if pool_regex.search(name):
return True
return False
开发者ID:apurva3000,项目名称:tmpnb,代码行数:13,代码来源:dockworker.py
示例20: get
def get(self, path):
"""Get a directory listing, rendered notebook, or raw file
at the given path based on the type and URL query parameters.
If the path points to an accessible directory, render its contents.
If the path points to an accessible notebook file, render it.
If the path points to an accessible file and the URL contains a
'download' query parameter, respond with the file as a download.
Parameters
==========
path: str
Local filesystem path
"""
abspath = os.path.abspath(os.path.join(
self.localfile_path,
path
))
if not abspath.startswith(self.localfile_path):
app_log.warn("directory traversal attempt: '%s'" %
self.localfile_path)
raise web.HTTPError(404)
if not os.path.exists(abspath):
raise web.HTTPError(404)
if os.path.isdir(abspath):
html = self.show_dir(abspath, path)
raise gen.Return(self.cache_and_finish(html))
is_download = self.get_query_arguments('download')
if is_download:
self.download(abspath)
return
try:
with io.open(abspath, encoding='utf-8') as f:
nbdata = f.read()
except IOError as ex:
if ex.errno == errno.EACCES:
# py2/3: can't read the file, so don't give away it exists
raise web.HTTPError(404)
raise ex
yield self.finish_notebook(nbdata,
download_url='?download',
msg="file from localfile: %s" % path,
public=False,
format=self.format,
request=self.request)
开发者ID:SylvainCorlay,项目名称:nbviewer,代码行数:51,代码来源:handlers.py
注:本文中的tornado.log.app_log.warn函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论