Exemple #1
0
    def getMethods(self):
        """Get all methods of this class."""
        methods = []
        # remove the security proxy, so that `attr` is not proxied. We could
        # unproxy `attr` for each turn, but that would be less efficient.
        #
        # `getPermissionIds()` also expects the class's security checker not
        # to be proxied.
        klass = removeSecurityProxy(self.apidoc)
        for name, attr, iface in klass.getMethodDescriptors():
            entry = {
                'name': name,
                'signature': "(...)",
                'doc': attr.__doc__ or '',
                'attr': attr,
                'interface': iface
            }
            entry.update(getPermissionIds(name, klass.getSecurityChecker()))
            methods.append(entry)

        for name, attr, iface in klass.getMethods():
            entry = {
                'name': name,
                'signature': getFunctionSignature(attr),
                'doc': attr.__doc__ or '',
                'attr': attr,
                'interface': iface
            }
            entry.update(getPermissionIds(name, klass.getSecurityChecker()))
            methods.append(entry)
        return methods
Exemple #2
0
    def getMethods(self):
        """Get all methods of this class."""
        methods = []
        # remove the security proxy, so that `attr` is not proxied. We could
        # unproxy `attr` for each turn, but that would be less efficient.
        #
        # `getPermissionIds()` also expects the class's security checker not
        # to be proxied.
        klass = removeSecurityProxy(self.context)
        for name, attr, iface in klass.getMethodDescriptors():
            entry = {'name': name,
                     'signature': "(...)",
                     'doc': renderText(attr.__doc__ or '',
                                       inspect.getmodule(attr)),
                     'interface': getInterfaceInfo(iface)}
            entry.update(getPermissionIds(name, klass.getSecurityChecker()))
            methods.append(entry)

        for name, attr, iface in klass.getMethods():
            entry = {'name': name,
                     'signature': getFunctionSignature(attr),
                     'doc': renderText(attr.__doc__ or '',
                                       inspect.getmodule(attr)),
                     'interface': getInterfaceInfo(iface)}
            entry.update(getPermissionIds(name, klass.getSecurityChecker()))
            methods.append(entry)
        return methods
Exemple #3
0
    def getMethods(self):
        """Get all methods of an object.

        Get a list of dicts, describing the methods of an object. The
        dicts support keys ``name`` (name of method), ``signature``,
        ``doc`` (method's docstring or ``None``) and ``interface``
        (the interface, where the method was defined or ``None``).
        """
        klass = removeSecurityProxy(self.__klass)
        obj = removeSecurityProxy(self.obj)
        for name in dir(obj):
            value = getattr(obj, name, None)
            if value is None:
                continue
            if not (inspect.ismethod(value)
                    and not inspect.ismethoddescriptor(value)):
                continue
            if inspect.ismethod(value):
                signature = utilities.getFunctionSignature(value)
            else:
                signature = '(...)'

            entry = {
                'name': name,
                'signature': signature,
                'doc': getattr(value, '__doc__', None),
                'interface': utilities.getInterfaceForAttribute(name,
                                                                klass=klass),
                'value_linkable': self.isLinkable(value),
            }
            entry.update(
                utilities.getPermissionIds(name,
                                           getCheckerForInstancesOf(klass)))
            yield entry
Exemple #4
0
    def getAttributes(self):
        """Get all attributes of an object.

        See objectinfo.txt to learn more.
        """
        klass = removeSecurityProxy(self.__klass)
        obj = removeSecurityProxy(self.obj)
        for name in dir(obj):
            value = getattr(obj, name, None)
            if value is None:
                continue
            if inspect.ismethod(value) or inspect.ismethoddescriptor(value):
                continue
            entry = {
                'name': name,
                'value': ` value `,
                'value_linkable': self.isLinkable(value),
                'type': type(value),
                # type_link is a very browser oriented data
                # element. Move it to a view?
                'type_link': self.getTypeLink(type(value)),
                'interface': utilities.getInterfaceForAttribute(name,
                                                                klass=klass)
            }
            entry.update(
                utilities.getPermissionIds(name,
                                           getCheckerForInstancesOf(klass)))
            yield entry
Exemple #5
0
def getViewInfoDictionary(reg):
    """Build up an information dictionary for a view registration."""
    # get configuration info
    if isinstance(reg.doc, (str, unicode)):
        doc = reg.doc
        zcml = None
    else:
        doc = None
        zcml = getParserInfoInfoDictionary(reg.doc)

    # get layer
    layer = None
    if ILayer.providedBy(reg.required[-1]):
        layer = getInterfaceInfoDictionary(reg.required[-1])


    info = {'name' : reg.name or '<i>no name</i>',
            'type' : getPythonPath(getPresentationType(reg.required[-1])),
            'factory' : getViewFactoryData(reg.value),
            'required': [getInterfaceInfoDictionary(iface)
                         for iface in reg.required],
            'provided' : getInterfaceInfoDictionary(reg.provided),
            'layer': layer,
            'doc': doc,
            'zcml': zcml
            }

    # Educated guess of the attribute name
    info.update(getPermissionIds('publishTraverse', klass=reg.value))

    return info
Exemple #6
0
 def getAttributes(self):
     """Get the attributes of this class."""
     attrs = []
     # See remark in getMethods()
     klass = removeSecurityProxy(self.apidoc)
     for name, attr, iface in klass.getAttributes():
         entry = {'name': name,
                  'value': `attr`,
                  'type': type(attr).__name__,
                  'interface': iface
             }
         entry.update(getPermissionIds(name,klass.getSecurityChecker()))
         attrs.append(entry)
     return attrs
Exemple #7
0
 def getAttributes(self):
     """Get all attributes of this class."""
     attrs = []
     # remove the security proxy, so that `attr` is not proxied. We could
     # unproxy `attr` for each turn, but that would be less efficient.
     #
     # `getPermissionIds()` also expects the class's security checker not
     # to be proxied.
     klass = removeSecurityProxy(self.context)
     for name, attr, iface in klass.getAttributes():
         entry = {'name': name,
                  'value': `attr`,
                  'type': type(attr).__name__,
                  'type_link': getTypeLink(type(attr)),
                  'interface': getInterfaceInfo(iface)}
         entry.update(getPermissionIds(name, klass.getSecurityChecker()))
         attrs.append(entry)
     return attrs
def getViewInfoDictionary(reg):
    """Build up an information dictionary for a view registration."""
    # get configuration info
    if isinstance(reg.info, six.string_types):
        doc = reg.info
        zcml = None
    else:
        doc = None
        zcml = getParserInfoInfoDictionary(reg.info)

    info = {'name' : six.text_type(reg.name) or _('<i>no name</i>'),
            'type' : getPythonPath(getPresentationType(reg.required[-1])),
            'factory' : getViewFactoryData(reg.factory),
            'required': [getInterfaceInfoDictionary(iface)
                         for iface in reg.required],
            'provided' : getInterfaceInfoDictionary(reg.provided),
            'doc': doc,
            'zcml': zcml
            }

    # Educated guess of the attribute name
    info.update(getPermissionIds('publishTraverse', klass=reg.factory))

    return info