fixed bug in parse command with requests which don't have __dict__ attribute

This commit is contained in:
Pablo Hoffman 2009-10-02 09:20:22 -03:00
parent bb4871b7a7
commit 0f1bb87198
1 changed files with 6 additions and 12 deletions

View File

@ -5,7 +5,6 @@ import sys
import pprint as pypprint
from scrapy.item import BaseItem
from scrapy.http import Request, Response
nocolour = False
@ -20,30 +19,25 @@ def colorize(text):
except ImportError:
return text
def pformat_dictobj(obj):
def _pformat_dictobj(obj):
clsname = obj.__class__.__name__
return "%s(%s)\n" % (clsname, colorize(pypprint.pformat(obj.__dict__)))
def pprint_dictobj(obj):
print pformat_dictobj(obj)
def pformat(obj, *args, **kwargs):
"""
Wrapper which autodetects the object type and uses the proper formatting
function
"""
if isinstance(obj, (list, tuple)):
return "".join([pformat(i, *args, **kwargs) for i in obj])
elif isinstance(obj, (BaseItem, Request, Response)):
return pformat_dictobj(obj)
if isinstance(obj, BaseItem):
return _pformat_dictobj(obj)
elif hasattr(obj, '__iter__'):
return "".join(map(pformat, obj))
else:
return colorize(pypprint.pformat(obj))
return colorize(pypprint.pformat(repr(obj)))
def pprint(obj, *args, **kwargs):
"""
Wrapper which autodetects the object type and uses the proper printing
function
"""
print pformat(obj, *args, **kwargs)