eric6/Utilities/ClassBrowsers/pyclbr.py

changeset 7685
0b6e8c0d6403
parent 7676
0f67b4562d98
child 7690
a59680062837
diff -r 2fca14bea889 -r 0b6e8c0d6403 eric6/Utilities/ClassBrowsers/pyclbr.py
--- a/eric6/Utilities/ClassBrowsers/pyclbr.py	Wed Sep 02 17:58:19 2020 +0200
+++ b/eric6/Utilities/ClassBrowsers/pyclbr.py	Wed Sep 02 18:13:12 2020 +0200
@@ -343,16 +343,13 @@
     """
     global _modules
     
-    dictionary = {}
-    dict_counts = {}
-
     if module in _modules:
         # we've seen this module before...
         return _modules[module]
     if module in sys.builtin_module_names:
         # this is a built-in module
-        _modules[module] = dictionary
-        return dictionary
+        _modules[module] = {}
+        return {}
 
     # search the path for the module
     path = [] if path is None else path[:]
@@ -371,24 +368,45 @@
         f.close()
     if type not in SUPPORTED_TYPES:
         # not Python source, can't do anything with this module
-        _modules[module] = dictionary
-        return dictionary
+        _modules[module] = {}
+        return {}
+
+    try:
+        src = Utilities.readEncodedFile(file)[0]
+    except (UnicodeError, IOError):
+        # can't do anything with this module
+        _modules[module] = {}
+        return {}
+    
+    _modules[module] = scan(src, file, module)
+    return _modules[module]
+
 
-    _modules[module] = dictionary
+def scan(src, file, module):
+    """
+    Public method to scan the given source text.
+    
+    @param src source text to be scanned
+    @type str
+    @param file file name associated with the source text
+    @type str
+    @param module module name associated with the source text
+    @type str
+    @return dictionary containing the extracted data
+    @rtype dict
+    """
+    # convert eol markers the Python style
+    src = src.replace("\r\n", "\n").replace("\r", "\n")
+    
+    dictionary = {}
+    dict_counts = {}
+    
     classstack = []  # stack of (class, indent) pairs
     conditionalsstack = []  # stack of indents of conditional defines
     deltastack = []
     deltaindent = 0
     deltaindentcalculated = 0
-    try:
-        src = Utilities.readEncodedFile(file)[0]
-    except (UnicodeError, IOError):
-        # can't do anything with this module
-        _modules[module] = dictionary
-        return dictionary
-    # convert eol markers the Python style
-    src = src.replace("\r\n", "\n").replace("\r", "\n")
-
+    
     lineno, last_lineno_pos = 1, 0
     lastGlobalEntry = None
     cur_obj = None

eric ide

mercurial