예제 #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
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
 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
 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}