summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2014-01-22 00:03:10 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2014-01-22 00:03:10 +0100
commitf907c405cf233b4ef14817952c11979125b4732c (patch)
treef7829f02722ce56db1011310bb99f898a1de2b1b /factory
parent5cd2ba8b89a1dc575b818f8c7be20dd3f0f6c05a (diff)
downloadfactory-boy-f907c405cf233b4ef14817952c11979125b4732c.tar
factory-boy-f907c405cf233b4ef14817952c11979125b4732c.tar.gz
Fix log_pprint (Closes #123).
Diffstat (limited to 'factory')
-rw-r--r--factory/utils.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/factory/utils.py b/factory/utils.py
index 48c6eed..b27fd77 100644
--- a/factory/utils.py
+++ b/factory/utils.py
@@ -20,6 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
+from __future__ import unicode_literals
+
import collections
#: String for splitting an attribute name into a
@@ -96,11 +98,26 @@ def import_object(module_name, attribute_name):
return getattr(module, attribute_name)
+def _safe_repr(obj):
+ try:
+ obj_repr = repr(obj)
+ except UnicodeError:
+ return '<bad_repr object at %s>' % id(obj)
+
+ try: # Convert to "text type" (= unicode)
+ return '%s' % obj_repr
+ except UnicodeError: # non-ascii bytes repr on Py2
+ return obj_repr.decode('utf-8')
+
+
def log_pprint(args=(), kwargs=None):
kwargs = kwargs or {}
return ', '.join(
- [str(arg) for arg in args] +
- ['%s=%r' % item for item in kwargs.items()]
+ [repr(arg) for arg in args] +
+ [
+ '%s=%s' % (key, _safe_repr(value))
+ for key, value in kwargs.items()
+ ]
)