Skip to content

Instantly share code, notes, and snippets.

@abadger
Created December 5, 2014 18:26
Show Gist options
  • Save abadger/1db069b6127cc65e914d to your computer and use it in GitHub Desktop.
Save abadger/1db069b6127cc65e914d to your computer and use it in GitHub Desktop.
diff -up q-2.5/q.py.bak q-2.5/q.py
--- q-2.5/q.py.bak 2014-12-01 19:37:24.000000000 -0800
+++ q-2.5/q.py 2014-12-05 10:23:52.556544396 -0800
@@ -66,7 +66,7 @@ else:
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.
@@ -177,6 +177,13 @@ class Q(object):
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.
@@ -184,11 +191,17 @@ class Q(object):
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):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment