Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1951

Show
Ignore:
Timestamp:
04/26/08 18:40:30
Author:
fumanchu
Message:

Fix for #805 (Remove import of inspect).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/__init__.py

    r1938 r1951  
    136136                    delattr(cls, name) 
    137137                 
    138                 # Get an inspect-style docstring if possible (usually so). 
    139                 val = dct[name] 
    140                 try: 
    141                     import inspect 
    142                     val = inspect.getdoc(property(doc=val)).strip() 
    143                 except: 
    144                     pass 
    145                  
    146                 # Indent the docstring. 
    147                 val = '\n'.join(['    ' + line.rstrip() 
    148                                  for line in val.split('\n')]) 
     138                # Make a uniformly-indented docstring from it. 
     139                val = '\n'.join(['    ' + line.strip() 
     140                                 for line in dct[name].split('\n')]) 
    149141                 
    150142                # Get the default value. 
  • trunk/cherrypy/_cptools.py

    r1811 r1951  
    2424 
    2525import cherrypy 
     26 
     27 
     28def _getargs(func): 
     29    """Return the names of all static arguments to the given function.""" 
     30    # Use this instead of importing inspect for less mem overhead. 
     31    import types 
     32    if isinstance(func, types.MethodType): 
     33        func = func.im_func 
     34    co = func.func_code 
     35    return co.co_varnames[:co.co_argcount] 
    2636 
    2737 
     
    4555        """Copy func parameter names to obj attributes.""" 
    4656        try: 
    47             import inspect 
    48             for arg in inspect.getargspec(self.callable)[0]: 
     57            for arg in _getargs(self.callable): 
    4958                setattr(self, arg, None) 
    50         except (ImportError, AttributeError): 
    51             pass 
    52         except TypeError: 
     59        except (TypeError, AttributeError): 
    5360            if hasattr(self.callable, "__call__"): 
    54                 for arg in inspect.getargspec(self.callable.__call__)[0]
     61                for arg in _getargs(self.callable.__call__)
    5562                    setattr(self, arg, None) 
    5663        # IronPython 1.0 raises NotImplementedError because 
     
    5966        except NotImplementedError: 
    6067            pass 
    61         # IronPython 1B1 may raise that error in some cases 
    62         # but if we trap it here it doesn't prevent CP from 
    63         # working 
     68        # IronPython 1B1 may raise IndexError in some cases, 
     69        # but if we trap it here it doesn't prevent CP from working. 
    6470        except IndexError: 
    6571            pass 

Hosted by WebFaction

Log in as guest/cpguest to create tickets