]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Move web._O to util.ObjectDict
authorAlek Storm <alek.storm@gmail.com>
Sat, 10 Sep 2011 23:25:10 +0000 (23:25 +0000)
committerAlek Storm <alek.storm@gmail.com>
Sat, 10 Sep 2011 23:25:10 +0000 (23:25 +0000)
tornado/httputil.py
tornado/test/web_test.py
tornado/util.py
tornado/web.py

index 3b78dc64029533d85915c6ff2f873c7bfe6b0362..f27148c9ff4992504f9ff1e119b223e6ef70587e 100644 (file)
@@ -20,7 +20,7 @@ import logging
 import urllib
 import re
 
-from tornado.util import b
+from tornado.util import b, ObjectDict
 
 class HTTPHeaders(dict):
     """A dictionary that maintains Http-Header-Case for all keys.
index ca473d89924d2bb68d91e1243d5774a4a6fc11e9..6898ffc03e77ba5a880408ecf01b1a38fab4d567 100644 (file)
@@ -2,8 +2,8 @@ from tornado.escape import json_decode, utf8, to_unicode, recursive_unicode, nat
 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
@@ -17,7 +17,7 @@ class CookieTestRequestHandler(RequestHandler):
     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)
index 4ac59908f5781d45889764441fcb524c67c37d15..6752401affb46f4983e1e7f8dfad0eda09ba0a34 100644 (file)
@@ -1,5 +1,17 @@
 """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.
 
index 59445209b6f52fc3db17809afa297eeee713b19d..e87f330545042f05a98ccd43037aa234290e2819 100644 (file)
@@ -82,7 +82,7 @@ from tornado import locale
 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
@@ -105,14 +105,14 @@ class RequestHandler(object):
         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()
@@ -1911,15 +1911,3 @@ def _create_signature(secret, *parts):
     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