Permalink
Browse files

Switch to textwrap.dedent().

  • Loading branch information...
1 parent 3a18a5a commit dcd8a393b5767fdb6eb076cd43984c407de1d43e @kgaughan committed Oct 20, 2012
Showing with 5 additions and 29 deletions.
  1. +5 −21 dbkit.py
  2. +0 −8 tests/test_dbkit.py
View
@@ -8,12 +8,14 @@
"""
from __future__ import with_statement
+
import collections
import contextlib
import datetime
import functools
import pprint
import sys
+import textwrap
import threading
@@ -26,10 +28,9 @@
'execute_proc', 'query_proc_row',
'query_proc_value', 'query_proc_column',
'DictFactory', 'TupleFactory',
- 'unindent_statement', 'make_file_object_logger',
- 'null_logger', 'stderr_logger')
+ 'make_file_object_logger', 'null_logger', 'stderr_logger')
-__version__ = '0.2.0'
+__version__ = '0.2.1'
__author__ = 'Keith Gaughan'
__email__ = 'k@stereochro.me'
@@ -844,23 +845,6 @@ def _safe_close(obj):
pass
-def unindent_statement(stmt):
- """
- Strips leading whitespace from a query based on the indentation
- of the first non-empty line.
-
- This is for use in logging functions for cleaning up query formatting.
- """
- lines = stmt.split("\n")
- prefix = 0
- for line in lines:
- stripped = line.lstrip()
- if stripped != '':
- prefix = len(line) - len(stripped)
- break
- return "\n".join(line[prefix:] for line in lines)
-
-
def null_logger(_stmt, _args):
"""A logger that discards everything sent to it."""
pass
@@ -872,7 +856,7 @@ def logger_func(stmt, args, fh=fh):
"""A logger that logs everything sent to a file object."""
now = datetime.datetime.now()
print >> fh, "Executing (%s):" % now.isoformat()
- print >> fh, unindent_statement(stmt)
+ print >> fh, textwrap.dedent(stmt)
print >> fh, "Arguments:"
pprint.pprint(args, fh)
return logger_func
View
@@ -201,14 +201,6 @@ def test_unpooled_disconnect():
ctx.close()
-def test_unindent_statement():
- assert dbkit.unindent_statement("foo\nbar") == "foo\nbar"
- assert dbkit.unindent_statement(" foo\n bar") == "foo\nbar"
- assert dbkit.unindent_statement(" foo\n bar") == "foo\nbar"
- assert dbkit.unindent_statement(" foo\n bar") == "foo\n bar"
- assert dbkit.unindent_statement(" foo\n bar") == "foo\nar"
-
-
def test_make_file_object_logger():
captured = StringIO.StringIO()
logger = dbkit.make_file_object_logger(captured)

0 comments on commit dcd8a39

Please sign in to comment.