Added python3 support, pkg python3-decoratedstr
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Tue, 11 Feb 2014 16:18:43 +0000 (16:18 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Tue, 11 Feb 2014 16:18:43 +0000 (16:18 +0000)
debian/changelog
debian/control
debian/install [deleted file]
debian/python-decoratedstr.install [new file with mode: 0644]
debian/python3-decoratedstr.install [new file with mode: 0644]
debian/rules
decoratedstr.py

index 6710b90283f449e7b58a620258964a73850ce517..bd60a66139d641361292c584cc16fd616cc320cc 100644 (file)
@@ -1,9 +1,11 @@
-python-decoratedstr (0.4) UNRELEASED; urgency=low
+python-decoratedstr (0.5) UNRELEASED; urgency=low
   * Changed compat level to 9.
   * Switch from python-central to dh_python2.
   * Bumped standard version to 3.9.5
+  * Added python3 support
+  * Added new package python3-decoratedstr
 
- -- Jean-Michel Vourgère <jmv_deb@nirgal.com>  Tue, 11 Feb 2014 16:21:59 +0100
+ -- Jean-Michel Vourgère <jmv_deb@nirgal.com>  Tue, 11 Feb 2014 17:17:02 +0100
 
 python-decoratedstr (0.3) UNRELEASED; urgency=low
 
index 34a94af5288969d78bdfd6f7077eebc5c29e4a69..f2e049a5df286cc3fe2e368af27e31d33f5ea673 100644 (file)
@@ -2,15 +2,33 @@ Source: python-decoratedstr
 Section: python
 Priority: optional
 Maintainer: Jean-Michel Vourgère <jmv_deb@nirgal.com>
-Build-Depends: debhelper (>= 9), python-all (>=2.6.6-3~), dh-python
+Build-Depends: debhelper (>= 9),
+               python-all (>=2.6.6-3~),
+               python3-all,
+               dh-python
 Standards-Version: 3.9.5
 Vcs-Svn: svn://svn.nirgal.com/kod/python-decoratedstr
+X-Python-Version: >= 2.6
+X-Python3-Version: >= 3.2
 
 Package: python-decoratedstr
 Architecture: all
-Depends: ${misc:Depends}, ${python:Depends}
+Depends: ${misc:Depends}, ${python:Depends}, python-six
 Description: Python library for decorated strings
  Provide functions for accentuated characters and ligatures handling
  input: Œuf
  undecorated: Oeuf
- regex: (œ|[oòóôöøōŏő][eèéêëēĕėęě])[uùúûüũūŭůűų]f 
+ regex: (œ|[oòóôöøōŏő][eèéêëēĕėęě])[uùúûüũūŭůűų]f
+ .
+ This is the Python 2 version of the package.
+
+Package: python3-decoratedstr
+Architecture: all
+Depends: ${misc:Depends}, ${python3:Depends}, python3-six
+Description: Python library for decorated strings
+ Provide functions for accentuated characters and ligatures handling
+ input: Œuf
+ undecorated: Oeuf
+ regex: (œ|[oòóôöøōŏő][eèéêëēĕėęě])[uùúûüũūŭůűų]f
+ .
+ This is the Python 3 version of the package.
diff --git a/debian/install b/debian/install
deleted file mode 100644 (file)
index da26409..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-decoratedstr.py /usr/share/pyshared/
-decoratedstr /usr/bin
diff --git a/debian/python-decoratedstr.install b/debian/python-decoratedstr.install
new file mode 100644 (file)
index 0000000..da26409
--- /dev/null
@@ -0,0 +1,2 @@
+decoratedstr.py /usr/share/pyshared/
+decoratedstr /usr/bin
diff --git a/debian/python3-decoratedstr.install b/debian/python3-decoratedstr.install
new file mode 100644 (file)
index 0000000..72fda19
--- /dev/null
@@ -0,0 +1 @@
+decoratedstr.py /usr/lib/python3/dist-packages/
index 3b4e9bfcb499e18474a3fffc0f74f7f36cbb3240..1936dfb02a0f26523d1f51518f17b0b2815e8c83 100755 (executable)
@@ -2,4 +2,4 @@
 export DH_ALWAYS_EXCLUDE=.svn
 
 %:
-       dh $@ --with python2
+       dh $@ --with python2,python3
index efbb652f453c41b76915ec82753e420d802ad2a2..d226d42b592a743790a150387c14d53c5e009d1c 100755 (executable)
@@ -1,70 +1,73 @@
 #!/usr/bin/env python
 # -*- encoding: utf-8 -*-
 
+from __future__ import print_function, unicode_literals
+import six
+
 __all__ = ['remove_decoration', 'decorated_match']
 
 # for range \u00c0 \u0179
-char_to_alternatives_lower={
-    u'a': u'àáâãäåāăą',
-    u'c': u'çćĉċč',
-    u'd': u'ďđ',
-    u'e': u'èéêëēĕėęě',
-    u'g': u'ĝğġģ',
-    u'h': u'ĥħ',
-    u'i': u'ìíîïĩīĭįı',
-    u'j': u'ĵ',
-    u'k': u'ķ',
-    u'l': u'ĺļľŀł',
-    u'n': u'ñńņňʼnŋ',
-    u'o': u'òóôöøōŏő',
-    u'r': u'ŕŗř',
-    u's': u'śŝşš',
-    u't': u'ţťŧ',
-    u'u': u'ùúûüũūŭůűų',
-    u'w': u'ŵ',
-    u'y': u'ýÿŷ',
-    u'z': u'źżž',
+char_to_alternatives_lower = {
+    'a': 'àáâãäåāăą',
+    'c': 'çćĉċč',
+    'd': 'ďđ',
+    'e': 'èéêëēĕėęě',
+    'g': 'ĝğġģ',
+    'h': 'ĥħ',
+    'i': 'ìíîïĩīĭįı',
+    'j': 'ĵ',
+    'k': 'ķ',
+    'l': 'ĺļľŀł',
+    'n': 'ñńņňʼnŋ',
+    'o': 'òóôöøōŏő',
+    'r': 'ŕŗř',
+    's': 'śŝşš',
+    't': 'ţťŧ',
+    'u': 'ùúûüũūŭůűų',
+    'w': 'ŵ',
+    'y': 'ýÿŷ',
+    'z': 'źżž',
 }
 
 # This chars lower() function doesn't work
-char_to_alternatives_upper={
-    u'I': u'İ',
+char_to_alternatives_upper = {
+    'I': 'İ',
 }
-char_to_alternatives={} # idem, but with upper case too
-for char,alternatives in char_to_alternatives_lower.iteritems():
+char_to_alternatives = {} # idem, but with upper case too
+for char, alternatives in six.iteritems(char_to_alternatives_lower):
     char_to_alternatives[char] = alternatives
     char_to_alternatives[char.upper()] = alternatives.upper()
-for char,alternatives in char_to_alternatives_upper.iteritems():
+for char, alternatives in six.iteritems(char_to_alternatives_upper):
     char_to_alternatives[char] = alternatives
 
 alternative_to_char = {} # reverse
-for char,alternatives in char_to_alternatives_lower.iteritems():
+for char, alternatives in six.iteritems(char_to_alternatives_lower):
     for alternative in alternatives:
         alternative_to_char[alternative] = char
         alternative_to_char[alternative.upper()] = char.upper()
-for char,alternatives in char_to_alternatives_upper.iteritems():
+for char, alternatives in six.iteritems(char_to_alternatives_upper):
     for alternative in alternatives:
         alternative_to_char[alternative] = char
 
 # ligatures (only two chars supported)
 ligatures_expansions_lower = {
-    u'æ': u'ae',
-    # u'ij': u'ij', buggy: see http://en.wikipedia.org/wiki/Typographic_ligature
-    u'œ': u'oe',
+    'æ': 'ae',
+    # 'ij': 'ij', buggy: see http://en.wikipedia.org/wiki/Typographic_ligature
+    'œ': 'oe',
 }
 
 ligatures_expansions = {} # idem, but with upper case too
-for ligature, expansion in ligatures_expansions_lower.iteritems():
+for ligature, expansion in six.iteritems(ligatures_expansions_lower):
     ligatures_expansions[ligature] = expansion
     ligatures_expansions[ligature.upper()] = expansion[0].upper()+expansion[1:]
 
 ligatures_contractions = {} # reverse
-for ligature, expansion in ligatures_expansions_lower.iteritems():
+for ligature, expansion in six.iteritems(ligatures_expansions_lower):
     ligatures_contractions[expansion] = ligature
-    ligatures_contractions[expansion[0].upper()+expansion[1:]] =  ligature.upper()
+    ligatures_contractions[expansion[0].upper()+expansion[1:]] = ligature.upper()
 
 def remove_decoration(txt):
-    result = u''
+    result = ''
     for l in txt:
         l = alternative_to_char.get(l, l)
         l = ligatures_expansions.get(l, l)
@@ -72,38 +75,38 @@ def remove_decoration(txt):
     return result
 
 def decorated_match_single_char(c, casesensitive=False):
-    assert type(c)==unicode
+    assert type(c) == type('')
     if not casesensitive:
         c = c.lower()
-    result = c + char_to_alternatives.get(c, u'')
+    result = c + char_to_alternatives.get(c, '')
     if not casesensitive:
         u = result.upper()
         if result != u:
             result += u
-    if len(result)>1:
-        return u'['+result+u']'
+    if len(result) > 1:
+        return '['+result+']'
     else:
         return result
 
 def decorated_match(txt, casesensitive=False):
-    assert type(txt)==unicode
-    result = u''
+    assert type(txt) == type('')
+    result = ''
     txt = remove_decoration(txt)
     if not casesensitive:
         txt = txt.lower()
     i = 0
-    while i<len(txt):
+    while i < len(txt):
         c1 = txt[i] # current character
         c12 = txt[i:i+2] # both current and next characters. Contains a single char on last iteration so that it never matches, that is OK
         ligature = ligatures_contractions.get(c12, None)
         if ligature:
-            result += u'('+ligature
+            result += '('+ligature
             if not casesensitive:
-                result += u'|'+ligature.upper()
-            result += u'|'+decorated_match_single_char(c12[0], casesensitive) \
+                result += '|'+ligature.upper()
+            result += '|'+decorated_match_single_char(c12[0], casesensitive) \
                           +decorated_match_single_char(c12[1], casesensitive) \
-                   +u')'
-            i+=1 # skip next character, we allready did both
+                   +')'
+            i += 1 # skip next character, we allready did both
         else:
             result += decorated_match_single_char(c1, casesensitive)
         i += 1
@@ -120,13 +123,22 @@ if __name__ == '__main__':
     (options, args) = parser.parse_args()
 
     if not args:
-        print >> sys.stderr, u'Missing required parameter. Try "Œuf"'
+        print('Missing required parameter. Try "Œuf"', file=sys.stderr)
         sys.exit(1)
-    input = unicode(' '.join(args), options.charset)
-    #print "input:", input                            # Œuf
-    #print "undecorated:", remove_decoration(input)   # Oeuf
-    #print "regex:", decorated_match(input)           # (œ|Œ|[oòóôöøōŏőOÒÓÔÖØŌŎŐ][eèéêëēĕėęěEÈÉÊËĒĔĖĘĚ])[uùúûüũūŭůűųUÙÚÛÜŨŪŬŮŰŲ][fF]
+    if six.PY2:
+        input = unicode(b' '.join(args), options.charset)
+    else:
+        input = ' '.join(args)
+    #print("input:", input)                            # Œuf
+    #print("undecorated:", remove_decoration(input))   # Oeuf
+    #print("regex:", decorated_match(input))           # (œ|Œ|[oòóôöøōŏőOÒÓÔÖØŌŎŐ][eèéêëēĕėęěEÈÉÊËĒĔĖĘĚ])[uùúûüũūŭůűųUÙÚÛÜŨŪŬŮŰŲ][fF]
     if options.regexp:
-        print decorated_match(input, options.casesensitive).encode(options.charset)
+        if six.PY2:
+            print(decorated_match(input, options.casesensitive).encode(options.charset))
+        else:
+            print(decorated_match(input, options.casesensitive))
     else:
-        print remove_decoration(input).encode(options.charset)
+        if six.PY2:
+            print(remove_decoration(input).encode(options.charset))
+        else:
+            print(remove_decoration(input))