Robert Brewer committed 0867293

Fix for #805 (Remove import of inspect).

Comments (0)

Files changed (2)


                 if hasattr(cls, name):
                     delattr(cls, name)
-                # Get an inspect-style docstring if possible (usually so).
-                val = dct[name]
-                try:
-                    import inspect
-                    val = inspect.getdoc(property(doc=val)).strip()
-                except:
-                    pass
-                # Indent the docstring.
-                val = '\n'.join(['    ' + line.rstrip()
-                                 for line in val.split('\n')])
+                # Make a uniformly-indented docstring from it.
+                val = '\n'.join(['    ' + line.strip()
+                                 for line in dct[name].split('\n')])
                 # Get the default value.
                 attrname = name[:-5]


 import cherrypy
+def _getargs(func):
+    """Return the names of all static arguments to the given function."""
+    # Use this instead of importing inspect for less mem overhead.
+    import types
+    if isinstance(func, types.MethodType):
+        func = func.im_func
+    co = func.func_code
+    return co.co_varnames[:co.co_argcount]
 class Tool(object):
     """A registered function for use with CherryPy request-processing hooks.
     def _setargs(self):
         """Copy func parameter names to obj attributes."""
-            import inspect
-            for arg in inspect.getargspec(self.callable)[0]:
+            for arg in _getargs(self.callable):
                 setattr(self, arg, None)
-        except (ImportError, AttributeError):
-            pass
-        except TypeError:
+        except (TypeError, AttributeError):
             if hasattr(self.callable, "__call__"):
-                for arg in inspect.getargspec(self.callable.__call__)[0]:
+                for arg in _getargs(self.callable.__call__):
                     setattr(self, arg, None)
         # IronPython 1.0 raises NotImplementedError because
         # inspect.getargspec tries to access Python bytecode
         # in co_code attribute.
         except NotImplementedError:
-        # IronPython 1B1 may raise that error in some cases
-        # but if we trap it here it doesn't prevent CP from
-        # working
+        # IronPython 1B1 may raise IndexError in some cases,
+        # but if we trap it here it doesn't prevent CP from working.
         except IndexError:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.