pmuller / procfs

Python API for Linux /proc
Other
75 stars 25 forks source link

proc.net.tcp erroring #5

Closed perryjrandall closed 10 years ago

perryjrandall commented 10 years ago

Hey I was recently using this to check /proc//net/tcp in a nice pythonic manner and found that when iterating over the entries it would consistently error out... not quite sure of the root cause, not too much time on my hands to troubleshoot but i did make a slight change which prevents it from throwing an error, instead returns None...


diff --git a/procfs/core.py b/procfs/core.py
index a486ca7..a13930d 100644
--- a/procfs/core.py
+++ b/procfs/core.py
@@ -54,9 +54,11 @@ class BaseFile(object):
             data = self._read()
             if isinstance(data, dict) and attr in data:
                 return data[attr]
-            if hasattr(data, attr):
-                return getattr(data, attr)
-            raise AttributeError(attr)
+            if isinstance(attr, basestring):
+                if hasattr(data, attr):
+                    return getattr(data, attr)
+                raise AttributeError(attr)
+            return None
         raise AttributeError(attr)
     __getitem__ = __getattr__

FedericoCeratto commented 10 years ago

Same here.

pmuller commented 10 years ago

released on pypi as 0.4.0. Thanks !