from tornado.iostream import IOStream
from tornado.template import DictLoader
from tornado.testing import LogTrapTestCase, AsyncHTTPTestCase
-from tornado.util import b, bytes_type
-from tornado.web import RequestHandler, _O, authenticated, Application, asynchronous, url, HTTPError, StaticFileHandler, _create_signature
+from tornado.util import b, bytes_type, ObjectDict
+from tornado.web import RequestHandler, authenticated, Application, asynchronous, url, HTTPError, StaticFileHandler, _create_signature
import binascii
import logging
def __init__(self):
# don't call super.__init__
self._cookies = {}
- self.application = _O(settings=dict(cookie_secret='0123456789'))
+ self.application = ObjectDict(settings=dict(cookie_secret='0123456789'))
def get_cookie(self, name):
return self._cookies.get(name)
"""Miscellaneous utility functions."""
+class ObjectDict(dict):
+ """Makes a dictionary behave like an object."""
+ def __getattr__(self, name):
+ try:
+ return self[name]
+ except KeyError:
+ raise AttributeError(name)
+
+ def __setattr__(self, name, value):
+ self[name] = value
+
+
def import_object(name):
"""Imports an object by name.
from tornado import stack_context
from tornado import template
from tornado.escape import utf8, _unicode
-from tornado.util import b, bytes_type, import_object
+from tornado.util import b, bytes_type, import_object, ObjectDict
try:
from io import BytesIO # python 3
self._finished = False
self._auto_finish = True
self._transforms = None # will be set in _execute
- self.ui = _O((n, self._ui_method(m)) for n, m in
+ self.ui = ObjectDict((n, self._ui_method(m)) for n, m in
application.ui_methods.iteritems())
# UIModules are available as both `modules` and `_modules` in the
# template namespace. Historically only `modules` was available
# but could be clobbered by user additions to the namespace.
# The template {% module %} directive looks in `_modules` to avoid
# possible conflicts.
- self.ui["_modules"] = _O((n, self._ui_module(n, m)) for n, m in
+ self.ui["_modules"] = ObjectDict((n, self._ui_module(n, m)) for n, m in
application.ui_modules.iteritems())
self.ui["modules"] = self.ui["_modules"]
self.clear()
hash = hmac.new(utf8(secret), digestmod=hashlib.sha1)
for part in parts: hash.update(utf8(part))
return utf8(hash.hexdigest())
-
-
-class _O(dict):
- """Makes a dictionary behave like an object."""
- def __getattr__(self, name):
- try:
- return self[name]
- except KeyError:
- raise AttributeError(name)
-
- def __setattr__(self, name, value):
- self[name] = value