[Zope3-checkins] CVS: Zope3/src/zope/app - introspector.py:1.1.2.2
Fred L. Drake, Jr.
fred@zope.com
Tue, 24 Dec 2002 12:29:15 -0500
Update of /cvs-repository/Zope3/src/zope/app
In directory cvs.zope.org:/tmp/cvs-serv13562
Modified Files:
Tag: NameGeddon-branch
introspector.py
Log Message:
- fix up imports
- remove use of string module
- normalize whitespace
=== Zope3/src/zope/app/introspector.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/introspector.py:1.1.2.1 Mon Dec 23 14:30:56 2002
+++ Zope3/src/zope/app/introspector.py Tue Dec 24 12:29:14 2002
@@ -2,43 +2,45 @@
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
-#
+#
##############################################################################
-from zope.interface import Interface, IInterface
+
+from zope.interface import Interface
+from zope.interface.interfaces import IInterface
from zope.interface.implements import implements, getImplements
+
from zope.app.interfaces.introspector import IIntrospector
-from zope.proxy.introspection import removeAllProxies
+from zope.app.interfaces.services.service import INameResolver
from zope.component import getServiceManager, getAdapter, \
queryServiceManager, getServiceDefinitions
-from zope.app.interfaces.services.service import INameResolver
-import string
+from zope.proxy.introspection import removeAllProxies
class Introspector:
- """Introspecs an object"""
+ """Introspects an object"""
+
__implements__ = IIntrospector
-
def __init__(self, context):
self.context = context
self.request = None
self.currentclass = None
-
+
def isInterface(self):
"Checks if the context is class or interface"
try:
ck = self.context.namesAndDescriptions()
- return 1
+ return True
except:
- return 0
-
+ return False
+
def setRequest(self, request):
"""sets the request"""
self.request = request
@@ -46,9 +48,9 @@
path = self.request['PATH_INFO']
else:
path = ''
- name = path[string.rfind(path, '++module++')+len('++module++'):]
- name = string.split(name, '/')[0]
- if string.find(path, '++module++') != -1:
+ name = path[path.rfind('++module++') + len('++module++'):]
+ name = name.split('/')[0]
+ if path.find('++module++') != -1:
if (self.context == Interface and
name != 'Interface._Interface.Interface'):
servicemanager = getServiceManager(self.context)
@@ -59,16 +61,16 @@
self.currentclass = self.context
else:
self.currentclass = self.context.__class__
-
def _unpackTuple(self, tuple_obj):
res = []
for item in tuple_obj:
if type(item)==tuple:
res.extend(self._unpackTuple(item))
- else: res.append(item)
+ else:
+ res.append(item)
return tuple(res)
-
+
def getClass(self):
"""Returns the class name"""
return (self.currentclass).__name__
@@ -80,15 +82,15 @@
for base in bases:
base_names.append(base.__module__+'.'+base.__name__)
return base_names
-
+
def getModule(self):
"""Returns the module name of the class"""
return (self.currentclass).__module__
-
+
def getDocString(self):
"""Returns the description of the class"""
return removeAllProxies(self.currentclass).__doc__
-
+
def getInterfaces(self):
"""Returns interfaces implemented by this class"""
interfaces = removeAllProxies(self.currentclass).__implements__
@@ -103,12 +105,12 @@
try:
for intObj in self.getInterfaces():
names.append(intObj.__module__ + '.' + intObj.__name__)
- names.sort()
- return names
except:
return []
-
-
+ else:
+ names.sort()
+ return names
+
def getInterfaceDetails(self):
"""Returns the entire documentation in the interface"""
interface = self.context
@@ -127,12 +129,11 @@
desc.getDoc()))
else:
attributes.append((desc.getName(), desc.getDoc()))
-
+
for base in interface.getBases():
bases.append(base.__module__+'.'+base.__name__)
desc = str(interface.__doc__)
return [Iname, bases, desc, methods, attributes]
-
def getExtends(self):
"""Returns all the class extended up to the top most level"""
@@ -148,4 +149,3 @@
service.append(str(name))
print service
return service
-