コード例 #1
0
def getUtilityInfoDictionary(reg):
    """Return a PT-friendly info dictionary for a factory."""
    component = reg.component
    # Check whether we have an instance of some custom type or not
    # Unfortunately, a lot of utilities have a `__name__` attribute, so we
    # cannot simply check for its absence
    # TODO: Once we support passive display of instances, this insanity can go
    #       away.
    if not isinstance(component, (types.MethodType, types.FunctionType,
                                  six.class_types,
                                  InterfaceClass)):
        component = getattr(component, '__class__', component)

    path = getPythonPath(component)

    # provided interface id
    iface_id = '%s.%s' % (reg.provided.__module__, reg.provided.getName())

    # Determine the URL
    if isinstance(component, InterfaceClass):
        url = 'Interface/%s' % path
    else:
        url = None
        if isReferencable(path):
            url = 'Code/%s' % path.replace('.', '/')

    return {'name': six.text_type(reg.name) or _('<i>no name</i>'),
            'url_name': utilitymodule.encodeName(reg.name or '__noname__'),
            'iface_id': iface_id,
            'path': path,
            'url': url}
コード例 #2
0
def getAdapterInfoDictionary(reg):
    """Return a PT-friendly info dictionary for an adapter registration."""
    factory = getRealFactory(reg.factory)
    path = getPythonPath(factory)

    url = None
    if isReferencable(path):
        url = path.replace('.', '/')

    if isinstance(reg.info, six.string_types):
        doc = reg.info
        zcml = None
    else:
        doc = None
        zcml = getParserInfoInfoDictionary(reg.info)

    name = getattr(reg, 'name', u'')
    name = name.decode('utf-8') if isinstance(name, bytes) else name
    return {
        'provided': getInterfaceInfoDictionary(reg.provided),
        'required': [getSpecificationInfoDictionary(iface)
                     for iface in reg.required
                     if iface is not None],
        'name': name,
        'factory': path,
        'factory_url': url,
        'doc': doc,
        'zcml': zcml
    }
コード例 #3
0
ファイル: component.py プロジェクト: wpjunior/proled
def getAdapterInfoDictionary(reg):
    """Return a PT-friendly info dictionary for an adapter registration."""
    factory = getRealFactory(reg.value)
    path = getPythonPath(factory)

    url = None
    if isReferencable(path):
        url = path.replace('.', '/')

    if isinstance(reg.doc, (str, unicode)):
        doc = reg.doc
        zcml = None
    else:
        doc = None
        zcml = getParserInfoInfoDictionary(reg.doc)

    return {
        'provided': getInterfaceInfoDictionary(reg.provided),
        'required': [getInterfaceInfoDictionary(iface)
                     for iface in reg.required
                     if iface is not None],
        'name': getattr(reg, 'name', _('<subscription>')),
        'factory': path,
        'factory_url': url,
        'doc': doc,
        'zcml': zcml}
コード例 #4
0
    def test__qualname__descriptor_referencable(self):
        # When the __qualname__ is not a string but a descriptor object,
        # isReferencable does not raise an AttributeError
        # https://github.com/zopefoundation/zope.app.apidoc/issues/25

        from zope.app.apidoc import utilities

        # Set up an object that will return itself when looked up
        # as a module attribute via patching safe_import and when
        # asked for its __class__ so we can control the __qualname__
        # on all versions of Python.

        class O(object):
            "namespace object"

            def __getattribute__(self, name):
                if name in object.__getattribute__(self, '__dict__'):
                    return object.__getattribute__(self, '__dict__')[name]
                return self

        o = O()
        o.__qualname__ = object()

        def safe_import(path):
            return o

        old_safe_import = utilities.safe_import
        utilities.safe_import = safe_import
        try:
            self.assertTrue(utilities.isReferencable('a.module.object'))
        finally:
            utilities.safe_import = old_safe_import
コード例 #5
0
ファイル: browser.py プロジェクト: jean/zope.app.apidoc
 def getHandler(self):
     """Return information about the handler."""
     if self.context.handler is not None:
         path = getPythonPath(self.context.handler)
         return {
             'path': path,
             'url': isReferencable(path) and path.replace('.', '/') or None}
     return None
コード例 #6
0
ファイル: browser.py プロジェクト: jean/zope.app.apidoc
 def getSubdirectives(self):
     """Create a list of subdirectives."""
     dirs = []
     for ns, name, schema, handler, info in self.context.subdirs:
         details = self._getInterfaceDetails(schema)
         path = getPythonPath(handler)
         url = isReferencable(path) and path.replace('.', '/') or None
         dirs.append({
             'namespace': ns,
             'name': name,
             'schema': details,
             'handler': {'path': path, 'url': url},
             'info': info,
             })
     return dirs
コード例 #7
0
def getFactoryInfoDictionary(reg):
    """Return a PT-friendly info dictionary for a factory."""
    factory = reg.component
    callable = factory

    # Usually only zope.component.factory.Factory instances have this attribute
    if IFactory.providedBy(factory) and hasattr(factory, '_callable'):
        callable = factory._callable
    elif hasattr(callable, '__class__'):
        callable = callable.__class__

    path = getPythonPath(callable)

    return {'name': six.text_type(reg.name) or _('<i>no name</i>'),
            'title': getattr(factory, 'title', u''),
            'description': renderText(getattr(factory, 'description', u''),
                                      module=callable.__module__),
            'url': isReferencable(path) and path.replace('.', '/') or None}
コード例 #8
0
ファイル: zcml.py プロジェクト: wpjunior/proled
    def objectURL(self, value, field, rootURL):
        naked = removeSecurityProxy(self.context)
        bound = field.bind(naked.context)
        obj = bound.fromUnicode(value)
        if obj is None:
            return
        try:
            isInterface = IInterface.providedBy(obj)
        except AttributeError:
            # probably an object that does not like to play nice with the CA
            isInterface = False

        # The object mught be an instance; in this case get a link to the class
        if not hasattr(obj, '__name__'):
            obj = getattr(obj, '__class__')
        path = getPythonPath(obj)
        if isInterface:
            return rootURL+'/../Interface/%s/index.html' % path
        if isReferencable(path):
            return rootURL + '/%s/index.html' %(path.replace('.', '/'))
コード例 #9
0
def getTypeInfoDictionary(type):
    """Return a PT-friendly info dictionary for a type."""
    path = getPythonPath(type)
    return {'name': type.__name__,
            'module': type.__module__,
            'url': isReferencable(path) and path.replace('.', '/') or None}
コード例 #10
0
ファイル: class_.py プロジェクト: wpjunior/proled
def getInterfaceInfo(iface):
    if iface is None:
        return None
    path = getPythonPath(iface)
    return {'path': path,
            'url': isReferencable(path) and path or None}
コード例 #11
0
ファイル: class_.py プロジェクト: wpjunior/proled
def getTypeLink(type):
    if type is types.NoneType:
        return None
    path = getPythonPath(type)
    return isReferencable(path) and path.replace('.', '/') or None
コード例 #12
0
def getInterfaceInfo(iface):
    if iface is None:
        return None
    path = getPythonPath(iface)
    return {'path': path, 'url': isReferencable(path) and path or None}