[diff] deal with py3k string types

Related to #267910.

authorJulien Cristau <julien.cristau@logilab.fr>
changeset5a242c279995
branchdefault
phasepublic
hiddenno
parent revision#be56e667d39b [buildobjs] use six to declare metaclasses
child revision#18791c4c4ae2 [yams] deal with py3k string types and builtin module
files modified by this revision
diff.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1413451448 -7200
# Thu Oct 16 11:24:08 2014 +0200
# Node ID 5a242c279995837b1464ad131f11aef592389767
# Parent be56e667d39b2046f16ff9986c9d5e16ac815f40
[diff] deal with py3k string types

Related to #267910.

diff --git a/diff.py b/diff.py
@@ -24,18 +24,20 @@
1 
2  import subprocess
3  import tempfile
4  import os
5 
6 +from six import string_types, text_type
7 +
8  from yams.constraints import (SizeConstraint,
9                                UniqueConstraint,
10                                StaticVocabularyConstraint)
11  from yams.reader import SchemaLoader
12 
13 
14  def quoted(obj):
15 -    if isinstance(obj, basestring):
16 +    if isinstance(obj, string_types):
17          # NOT repr, because .....
18          # strings here turn out as unicode strings (from the repo side)
19          # but are (mostly) really str in the schema.py source
20          # and we don't want a bogus diff about '...' vs u'...'
21          if "'" in obj:
@@ -83,11 +85,11 @@
22          if rule:
23              out.append('%s%s: %s' %
24                         ('\t' + '\t' * scope.indentation,
25                          quoted(p),
26                          format_tuple(format_expression(r)
27 -                                     if not isinstance(r, basestring) else quoted(r)
28 +                                     if not isinstance(r, string_types) else quoted(r)
29                                for r in rule)))
30      return ' {%s\n%s\n%s}' % (' # default perms' if isdefault else '',
31                                ',\n'.join(out),
32                                '\t' * scope.indentation)
33 
@@ -140,11 +142,11 @@
34                      ret['maxsize'] = constraint.max
35                  elif isinstance(constraint, UniqueConstraint):
36                      ret['unique'] = True
37                  elif isinstance(constraint, StaticVocabularyConstraint):
38                      if relation.object.type == 'String':
39 -                        transform = unicode
40 +                        transform = text_type
41                      else:
42                          transform = identity
43                      ret['vocabulary'] = [transform(x)
44                                           for x in constraint.vocabulary()]
45                  else: