Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions q.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
class Q(object):
__doc__ = __doc__ # from the module's __doc__ above

import ast, code, inspect, os, pydoc, sys, random, re, time
import ast, code, inspect, os, pydoc, sys, random, re, time, pprint

# The debugging log will go to this file; temporary files will also have
# this path as a prefix, followed by a random number.
Expand Down Expand Up @@ -177,18 +177,31 @@ def unindent(self, lines):
indent = min(len(self.re.match(r'^ *', line).group()) for line in lines)
return [line[indent:].rstrip() for line in lines]

def save_large_value(self, value):
if isinstance(value, self.TEXT_TYPES):
value = value.encode('utf-8')
path = self.OUTPUT_PATH + '%08d.txt' % self.random.randrange(1e8)
self.FileWriter(path).write('w', value)
return path

def safe_repr(self, value):
# TODO: Use colour to distinguish '...' elision from actual '...' chars.
# TODO: Show a nicer repr for SRE.Match objects.
# TODO: Show a nicer repr for big multiline strings.
result = self.TEXT_REPR.repr(value)
if isinstance(value, self.BASESTRING_TYPES) and len(value) > 80:
# If the string is big, save it to a file for later examination.
if isinstance(value, self.TEXT_TYPES):
value = value.encode('utf-8')
path = self.OUTPUT_PATH + '%08d.txt' % self.random.randrange(1e8)
self.FileWriter(path).write('w', value)
path = self.save_large_value(value)
result += ' (file://' + path + ')'
else:
# Use pretty print if no specific choices were found
pp = self.pprint.PrettyPrinter(indent=1)
formatted = pp.pformat(value)
if len(formatted) > 80:
path = self.save_large_value(formatted)
result += ' (file://' + path + ')'
else:
result = formatted
return result

def get_call_exprs(self, line):
Expand Down