summaryrefslogtreecommitdiff
path: root/paste/docsupport/metadata_real.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-06-01 05:22:31 +0000
committerianb <devnull@localhost>2005-06-01 05:22:31 +0000
commitc19b04eb58c241f198935131f9c83569912d6cb9 (patch)
treed2e9d7d8e68dd1a6bd38f942a9ba4c3ab7f23185 /paste/docsupport/metadata_real.py
parent7c04782f49b4523f252e860a28829e3be7804f1d (diff)
downloadpaste-c19b04eb58c241f198935131f9c83569912d6cb9.tar.gz
Removed import overhead when not extracting; made sure that class instance methods and module functions don't blur together
Diffstat (limited to 'paste/docsupport/metadata_real.py')
-rw-r--r--paste/docsupport/metadata_real.py120
1 files changed, 120 insertions, 0 deletions
diff --git a/paste/docsupport/metadata_real.py b/paste/docsupport/metadata_real.py
new file mode 100644
index 0000000..b636013
--- /dev/null
+++ b/paste/docsupport/metadata_real.py
@@ -0,0 +1,120 @@
+# @@: There are too many imports here; this shouldn't have much
+# overhead except during extraction, but everything in this
+# module has to be imported regardless.
+import sys
+import copy
+import types
+import inspect
+import new
+from itertools import count
+from paste.util import import_string
+from paste.util.classinit import ClassInitMeta
+from paste.util.classinstance import classinstancemethod
+
+doc_count = count()
+
+class DocItem(object):
+
+ __metaclass__ = ClassInitMeta
+
+ def __classinit__(cls, new_attrs):
+ cls.__creationorder__ = doc_count.next()
+
+ def __init__(self):
+ self.__creationorder__ = doc_count.next()
+ stack = inspect.stack()
+ try:
+ while 1:
+ name = stack[0][0].f_globals['__name__']
+ if name != __name__:
+ break
+ stack.pop(0)
+ self.call_module_name = name
+ finally:
+ # Break reference to frames
+ stack = None
+
+ def get_object(self, name):
+ if '.' in name:
+ return import_string.eval_import(name)
+ else:
+ return getattr(sys.modules[self.call_module_name], name)
+
+ def writeto(self, context):
+ raise NotImplementedError
+
+ def writeobj(self, name, context):
+ """
+ Write the named object to the context
+ """
+ if name is None:
+ return
+ obj = self.get_object(name)
+ context.push_name(name)
+ context.extract(obj)
+ context.pop_name(name)
+
+
+class WSGIKey(DocItem):
+
+ def __init__(self, name, doc=None, interface=None):
+ self.name = name
+ self.doc = doc
+ self.interface = interface
+ super(WSGIKey, self).__init__()
+
+ def writeto(self, context):
+ context.writekey(self.name, type='WSGI Environment Key')
+ context.writedoc(self.doc)
+ self.writeobj(self.interface, context)
+ context.endkey()
+
+class NoDefault: pass
+
+class Config(DocItem):
+
+ def __init__(self, doc, name=None, default=NoDefault):
+ self.doc = doc
+ self.name = name
+ self.default = default
+
+ def writeto(self, context):
+ name = self.name
+ if not self.name:
+ name = context.last_name
+ if name.startswith('_config_'):
+ name = name[len('_config_'):]
+ name = "``%s``" % name
+ if self.default is not NoDefault:
+ name += ' (default: ``%r``)' % self.default
+ context.writekey(name, type='Paste Configuration',
+ monospace=False)
+ context.writedoc(self.doc)
+ context.endkey()
+
+class Attribute(DocItem):
+
+ def __init__(self, doc, name=None, interface=None):
+ self.doc = doc
+ self.name = name
+ self.interface = interface
+ super(Attribute, self).__init__()
+
+ def writeto(self, context):
+ name = self.name or context.last_name
+ context.writekey(self.name, type='Attribute')
+ context.writedoc(self.doc)
+ if self.interface:
+ context.write(self.interface)
+ context.endkey()
+
+def install():
+ """
+ Puts this module in place of the normal paste.docsupport.metadata
+ module, which is all stubby because this functional module takes
+ longer to import.
+ """
+ from paste.docsupport import metadata
+ for name, value in globals().items():
+ setattr(metadata, name, value)
+