Last active
July 18, 2016 00:05
-
-
Save ficapy/039dad3f7a85c7f220230eb3ff192962 to your computer and use it in GitHub Desktop.
打印模块的异常结构
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import inspect | |
from collections import defaultdict | |
def _tree(): return defaultdict(_tree) | |
tree = _tree() | |
def getitem(tree,seq): | |
tree = tree | |
for i in seq: | |
tree = tree.__getitem__(i) | |
def classtree(cls): | |
ret = [] | |
def inner(cls): | |
if cls is object: | |
return | |
ret.append(cls.__name__) | |
inner(cls.__base__) | |
inner(cls) | |
getitem(tree,reversed(ret)) | |
def pretty(d, indent=0): | |
for key, value in d.items(): | |
print('\t' * indent + str(key)) | |
if isinstance(value, dict): | |
pretty(value, indent + 1) | |
else: | |
print('\t' * (indent + 1) + str(value)) | |
def main(requests): | |
for i in dir(requests): | |
if inspect.isclass(getattr(requests, i)): | |
ret = issubclass(getattr(requests, i), BaseException) | |
if ret: | |
classtree(getattr(requests, i)) | |
pretty(dict(tree)) | |
if __name__ == '__main__': | |
main(requests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BaseException | |
Exception | |
OSError | |
RequestException | |
ConnectionError | |
ConnectTimeout | |
Timeout | |
ReadTimeout | |
HTTPError | |
TooManyRedirects | |
URLRequired | |
Warning | |
HTTPWarning | |
DependencyWarning | |
RequestsWarning | |
FileModeWarning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment