Python tornado.web.py() Examples
The following are 2
code examples of tornado.web.py().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tornado.web
, or try the search function
.
Example #1
Source File: checkplotserver_standalone.py From astrobase with MIT License | 6 votes |
def _time_independent_equals(a, b): ''' This compares two values in constant time. Taken from tornado: https://github.com/tornadoweb/tornado/blob/ d4eb8eb4eb5cc9a6677e9116ef84ded8efba8859/tornado/web.py#L3060 ''' if len(a) != len(b): return False result = 0 if isinstance(a[0], int): # python3 byte strings for x, y in zip(a, b): result |= x ^ y else: # python2 for x, y in zip(a, b): result |= ord(x) ^ ord(y) return result == 0
Example #2
Source File: api.py From jupyter-server-proxy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get(self, name): if name not in self.icons: raise web.HTTPError(404) path = self.icons[name] # Guess mimetype appropriately # Stolen from https://github.com/tornadoweb/tornado/blob/b399a9d19c45951e4561e6e580d7e8cf396ef9ff/tornado/web.py#L2881 mime_type, encoding = mimetypes.guess_type(path) if encoding == "gzip": content_type = "application/gzip" # As of 2015-07-21 there is no bzip2 encoding defined at # http://www.iana.org/assignments/media-types/media-types.xhtml # So for that (and any other encoding), use octet-stream. elif encoding is not None: content_type = "application/octet-stream" elif mime_type is not None: content_type = mime_type # if mime_type not detected, use application/octet-stream else: content_type = "application/octet-stream" with open(self.icons[name]) as f: self.write(f.read()) self.set_header('Content-Type', content_type)