~ubuntu-branches/ubuntu/trusty/spyder/trusty-proposed

« back to all changes in this revision

Viewing changes to spyderlib/utils/dochelpers.py

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Aubry
  • Date: 2010-06-28 23:43:02 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100628234302-3xnz0gcu0w83282r
Tags: 1.1.1-1
* New upstream release
* New maintainer address (Closes: #586833)
* Build with python 2.6 (Closes: #586824)

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
def getsource(obj):
55
55
    """Wrapper around inspect.getsource"""
56
56
    try:
57
 
        src = encoding.to_unicode( inspect.getsource(obj) )
58
 
    except TypeError:
59
 
        if hasattr(obj, '__class__'):
60
 
            src = encoding.to_unicode( inspect.getsource(obj.__class__) )
61
 
        else:
62
 
            # Bindings like VTK or ITK require this case
63
 
            src = getdoc(obj)
64
 
    return src
 
57
        try:
 
58
            src = encoding.to_unicode( inspect.getsource(obj) )
 
59
        except TypeError:
 
60
            if hasattr(obj, '__class__'):
 
61
                src = encoding.to_unicode( inspect.getsource(obj.__class__) )
 
62
            else:
 
63
                # Bindings like VTK or ITK require this case
 
64
                src = getdoc(obj)
 
65
        return src
 
66
    except (TypeError, IOError):
 
67
        return
65
68
 
66
69
def getargfromdoc(obj):
67
70
    """Get arguments from object doc"""
119
122
 
120
123
 
121
124
def isdefined(obj, force_import=False, namespace=None):
122
 
    """Return True if object is defined"""
 
125
    """Return True if object is defined in namespace
 
126
    If namespace is None --> namespace = locals()"""
123
127
    if namespace is None:
124
128
        namespace = locals()
125
129
    attr_list = obj.split('.')
127
131
    if len(base) == 0:
128
132
        return False
129
133
    import __builtin__
130
 
    if base not in locals() and base not in globals() \
131
 
       and base not in __builtin__.__dict__ and base not in namespace:
 
134
    if base not in __builtin__.__dict__ and base not in namespace:
132
135
        if force_import:
133
136
            try:
134
137
                module = __import__(base, globals(), namespace)
135
 
                globals()[base] = module
 
138
                if base not in globals():
 
139
                    globals()[base] = module
136
140
                namespace[base] = module
137
141
            except ImportError:
138
142
                return False