def getMenuLink(self, node): """Return the HTML link of the node that is displayed in the menu.""" obj = node.context if zapi.isinstance(obj, Utility): iface = zapi.getParent(obj) return "./" + zapi.name(iface) + "/" + zapi.name(obj) + "/index.html" if zapi.isinstance(obj, UtilityInterface): return "../Interface/" + zapi.name(obj) + "/index.html" return None
def testCorrectFactories(self): path = os.path.join(test_directory, 'testfiles') request = TestRequest() resource = DirectoryResourceFactory(path, checker, 'files')(request) image = resource['test.gif'] self.assert_(zapi.isinstance(image, FileResource)) template = resource['test.pt'] self.assert_(zapi.isinstance(template, PageTemplateResource)) file = resource['test.txt'] self.assert_(zapi.isinstance(file, FileResource)) file = resource['png'] self.assert_(zapi.isinstance(file, FileResource))
def attributes(self): context = removeSecurityProxy(self.context) attrs = [{'name': (ns and context.prefixes[ns]+':' or '') + name, 'value': value, 'url': None, 'values': []} for (ns, name), value in context.attrs.items()] names = context.schema.names(True) rootURL = zapi.absoluteURL(findDocModule(self), self.request) for attr in attrs: name = (attr['name'] in names) and attr['name'] or attr['name']+'_' field = context.schema.get(name) if zapi.isinstance(field, (GlobalObject, GlobalInterface)): attr['url'] = self.objectURL(attr['value'], field, rootURL) elif zapi.isinstance(field, Tokens): field = field.value_type values = attr['value'].strip().split() if len(values) == 1: attr['value'] = values[0] attr['url'] = self.objectURL(values[0], field, rootURL) else: for value in values: if zapi.isinstance(field, (GlobalObject, GlobalInterface)): url = self.objectURL(value, field, rootURL) else: break attr['values'].append({'value': value, 'url': url}) # Make sure that the attributes are in the same order they are defined # in the schema. fieldNames = getFieldNamesInOrder(context.schema) fieldNames = [name.endswith('_') and name[:-1] or name for name in fieldNames] attrs.sort(lambda x, y: _compareAttrs(x, y, fieldNames)) if not IRootDirective.providedBy(context): return attrs xmlns = [] for uri, prefix in context.prefixes.items(): name = prefix and ':'+prefix or '' xmlns.append({'name': 'xmlns'+name, 'value': uri, 'url': None, 'values': []}) xmlns.sort(lambda x, y: cmp(x['name'], y['name'])) return xmlns + attrs
def getMenuLink(self, node): """Return the HTML link of the node that is displayed in the menu.""" obj = node.context if zapi.isinstance(obj, Directive): ns = zapi.getParent(obj) return './'+zapi.name(ns) + '/' + zapi.name(obj) + '/index.html' return None
def getMenuTitle(self, node): """Return the title of the node that is displayed in the menu.""" obj = node.context if zapi.isinstance(obj, UtilityInterface): return zapi.name(obj).split(".")[-1] if obj.name == NONAME: return "no name" return obj.name
def getMenuTitle(self, node): """Return the title of the node that is displayed in the menu.""" if zapi.isinstance(node.context, TypeInterface): iface = node.context.interface else: iface = node.context # Interfaces have no security declarations, so we have to unwrap. return removeSecurityProxy(iface).getName()
def items(self): """See zope.app.container.interfaces.IReadContainer""" sm = zapi.getGlobalSiteManager() items = [(encodeName(reg.name or NONAME), Utility(self, reg)) for reg in sm.registrations() if zapi.isinstance(reg, UtilityRegistration) and \ self.interface == reg.provided] items.sort() return items
def getMenuTitle(self, node): """Return the title of the node that is displayed in the menu.""" obj = node.context if zapi.isinstance(obj, Namespace): name = obj.getShortName() if name == 'ALL': return 'All Namespaces' return name return zapi.name(obj)
def get(self, key, default=None): """See zope.app.container.interfaces.IReadContainer""" sm = zapi.getGlobalSiteManager() key = decodeName(key) if key == NONAME: key = '' utils = [Utility(self, reg) for reg in sm.registrations() if zapi.isinstance(reg, UtilityRegistration) and \ reg.name == key and reg.provided == self.interface] return utils and utils[0] or default
def getToolInstances(self, tool): """Find every registered utility for a given tool configuration.""" regManager = self.getSiteManagementFolder(tool).registrationManager return [ {'name': reg.name, 'url': zapi.absoluteURL(reg.component, self.request), 'rename': tool is self.activeTool and reg.name in self.renameList, 'active': reg.status == u'Active' } for reg in regManager.values() if (zapi.isinstance(reg, site.UtilityRegistration) and reg.provided.isOrExtends(tool.interface))]
def getFileInfo(self): """Get the file where the directive was declared.""" # ZCML directive `info` objects do not have security declarations, so # everything is forbidden by default. We need to remove the security # proxies in order to get to the data. info = removeSecurityProxy(self.context.info) if zapi.isinstance(info, ParserInfo): return {'file': relativizePath(info.file), 'line': info.line, 'column': info.column, 'eline': info.eline, 'ecolumn': info.ecolumn} return None
def testFactory(self): f = configfile(''' <permission id="zope.Foo" title="Zope Foo Permission" /> <content class="zope.app.component.tests.exampleclass.ExampleClass"> <factory id="test.Example" title="Example content" description="Example description" /> </content>''') xmlconfig(f) obj = createObject('test.Example') self.failUnless(zapi.isinstance(obj, exampleclass.ExampleClass))
def testURL3Level(self): request = TestRequest() request._vh_root = support.site ob.__parent__ = support.site ob.__name__ = 'ob' path = os.path.join(test_directory, 'testfiles') files = DirectoryResourceFactory(path, checker, 'test_files')(request) files.__parent__ = ob file = files['test.gif'] self.assertEquals(file(), 'http://127.0.0.1/@@/test_files/test.gif') subdir = files['subdir'] self.assert_(zapi.isinstance(subdir, DirectoryResource)) file = subdir['test.gif'] self.assertEquals(file(), 'http://127.0.0.1/@@/test_files/subdir/test.gif')
def getEntries(self, columns=True): """Return info objects for all modules and classes in this module.""" entries = [{'name': name, # only for interfaces; should be done differently somewhen 'path': getPythonPath(removeAllProxies(obj)), 'url': zapi.absoluteURL(obj, self.request), 'ismodule': zapi.isinstance(obj, Module), 'isinterface': zapi.isinstance( removeAllProxies(obj), InterfaceClass), 'isclass': zapi.isinstance(obj, Class), 'isfunction': zapi.isinstance(obj, Function), 'istextfile': zapi.isinstance(obj, TextFile), 'iszcmlfile': zapi.isinstance(obj, ZCMLFile)} for name, obj in self.context.items()] entries.sort(lambda x, y: cmp(x['name'], y['name'])) if columns: entries = columnize(entries) return entries
def findAPIDocumentationRoot(obj, request): if zapi.isinstance(obj, APIDocumentation): return zapi.absoluteURL(obj, request) return findAPIDocumentationRoot(zapi.getParent(obj), request)
def _evalId(id): if zapi.isinstance(id, Global): id = id.__name__ if id == 'CheckerPublic': id = 'zope.Public' return id