commit:     3796605e387a22caf80af7c81b5bc74152744fa4
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Wed May 14 03:56:31 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Wed May 14 03:56:31 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=3796605e

Adds unicode string compatibility support.

This commit allows string compatibility between py2 and py3 as well as
ensuring that the necessary strings that need to be unicode, stay
unicode in both py2 and py3 when running layman.

---
 layman/api.py              | 20 ++++++++-------
 layman/db.py               | 10 ++++----
 layman/dbbase.py           |  8 +++---
 layman/makeconf.py         | 22 ++++++++--------
 layman/overlays/overlay.py | 62 ++++++++++++++++++++++++----------------------
 layman/remotedb.py         |  2 +-
 layman/utils.py            |  4 ++-
 7 files changed, 67 insertions(+), 61 deletions(-)

diff --git a/layman/api.py b/layman/api.py
index 475691b..cbf3f76 100755
--- a/layman/api.py
+++ b/layman/api.py
@@ -13,6 +13,8 @@
 #              Brian Dolbec <[email protected]>
 #
 
+from __future__ import print_function
+
 import os
 
 from layman.config import BareConfig
@@ -428,21 +430,21 @@ class LaymanAPI(object):
         >>> b.close()
 
         >>> api.get_available()
-        [u'wrobel', u'wrobel-stable']
-        >>> all = api.get_all_info(u'wrobel')
+        ['wrobel', 'wrobel-stable']
+        >>> all = api.get_all_info('wrobel')
         >>> info = all['wrobel']
         >>> info['status']
-        u'official'
+        'official'
         >>> info['description']
-        u'Test'
+        'Test'
         >>> info['sources']
-        [(u'https://overlays.gentoo.org/svn/dev/wrobel', 'Subversion', None)]
+        [('https://overlays.gentoo.org/svn/dev/wrobel', 'Subversion', None)]
 
-        #{u'wrobel': {'status': u'official',
-        #'owner_name': None, 'description': u'Test',
+        #{'wrobel': {'status': 'official',
+        #'owner_name': None, 'description': 'Test',
         #'src_uris': <generator object source_uris at 0x167c3c0>,
-        #'owner_email': u'[email protected]',
-        #'quality': u'experimental', 'name': u'wrobel', 'supported': True,
+        #'owner_email': '[email protected]',
+        #'quality': 'experimental', 'name': 'wrobel', 'supported': True,
         #'src_types': <generator object source_types at 0x167c370>,
         #'official': True,
         #'priority': 10, 'feeds': [], 'irc': None, 'homepage': None}}

diff --git a/layman/db.py b/layman/db.py
index 6530147..ce03e13 100644
--- a/layman/db.py
+++ b/layman/db.py
@@ -111,11 +111,11 @@ class DB(DbBase):
         # * Running command "/usr/bin/rsync -rlptDvz --progress --delete 
--delete-after --timeout=180 --exclude="distfiles/*" --exclude="local/*" 
--exclude="packages/*" "rsync://gunnarwrobel.de/wrobel-stable/*" 
"/tmp/file.../wrobel-stable""...
         # >>> c = DbBase([write, ], dict())
         # >>> c.overlays.keys()
-        # [u'wrobel-stable']
+        # ['wrobel-stable']
 
         # >>> m = MakeConf(config, b.overlays)
         # >>> [i.name for i in m.overlays] #doctest: +ELLIPSIS
-        # [u'wrobel-stable']
+        # ['wrobel-stable']
 
         # >>> os.unlink(write)
         >>> os.unlink(write2)
@@ -195,16 +195,16 @@ class DB(DbBase):
         # * Running command "/usr/bin/svn co 
"https://overlays.gentoo.org/svn/dev/wrobel/"; "/tmp/file.../wrobel""...
         # >>> c = DbBase([write, ], dict())
         # >>> c.overlays.keys()
-        # [u'wrobel', u'wrobel-stable']
+        # ['wrobel', 'wrobel-stable']
 
         # >>> b.delete(b.select('wrobel'))
         # >>> c = DbBase([write, ], dict())
         # >>> c.overlays.keys()
-        # [u'wrobel-stable']
+        # ['wrobel-stable']
 
         # >>> m = MakeConf(config, b.overlays)
         # >>> [i.name for i in m.overlays] #doctest: +ELLIPSIS
-        # [u'wrobel-stable']
+        # ['wrobel-stable']
 
         # >>> os.unlink(write)
         >>> os.unlink(write2)

diff --git a/layman/dbbase.py b/layman/dbbase.py
index 475ce44..8fa3ba8 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -149,10 +149,10 @@ class DbBase(object):
         >>> config = {'output': output, 'svn_command': '/usr/bin/svn', 
'rsync_command':'/usr/bin/rsync'}
         >>> a = DbBase(config, [here + '/tests/testfiles/global-overlays.xml', 
])
         >>> a.overlays.keys()
-        [u'wrobel', u'wrobel-stable']
+        ['wrobel', 'wrobel-stable']
 
         >>> list(a.overlays['wrobel-stable'].source_uris())
-        [u'rsync://gunnarwrobel.de/wrobel-stable']
+        ['rsync://gunnarwrobel.de/wrobel-stable']
         '''
         try:
             document = ET.fromstring(text)
@@ -214,7 +214,7 @@ class DbBase(object):
         >>> b.write(write)
         >>> c = DbBase({"output": Message() }, [write,])
         >>> c.overlays.keys()
-        [u'wrobel-stable']
+        ['wrobel-stable']
 
         >>> os.unlink(write)
         >>> os.rmdir(tmpdir)
@@ -245,7 +245,7 @@ class DbBase(object):
         >>> config = {'output': output, 'svn_command': '/usr/bin/svn', 
'rsync_command':'/usr/bin/rsync'}
         >>> a = DbBase(config, [here + '/tests/testfiles/global-overlays.xml', 
])
         >>> list(a.select('wrobel-stable').source_uris())
-        [u'rsync://gunnarwrobel.de/wrobel-stable']
+        ['rsync://gunnarwrobel.de/wrobel-stable']
         '''
         self.output.debug("DbBase.select(), overlay = %s" % overlay, 5)
         if not overlay in self.overlays.keys():

diff --git a/layman/makeconf.py b/layman/makeconf.py
index 1abe318..52762a2 100644
--- a/layman/makeconf.py
+++ b/layman/makeconf.py
@@ -50,16 +50,16 @@ class MakeConf:
     >>> a.path = write
     >>> a.add(b.overlays['wrobel-stable'])
     >>> [i.name for i in a.overlays]
-    [u'wrobel-stable', u'wrobel-stable']
+    ['wrobel-stable', 'wrobel-stable']
     >>> a.add(b.overlays['wrobel'])
     >>> [i.name for i in a.overlays]
-    [u'wrobel', u'wrobel-stable', u'wrobel-stable']
+    ['wrobel', 'wrobel-stable', 'wrobel-stable']
     >>> a.delete(b.overlays['wrobel-stable'])
     >>> [i.name for i in a.overlays]
-    [u'wrobel']
+    ['wrobel']
     >>> a.add(b.overlays['wrobel-stable'])
     >>> [i.name for i in a.overlays]
-    [u'wrobel', u'wrobel-stable']
+    ['wrobel', 'wrobel-stable']
     >>> a.delete(b.overlays['wrobel'])
     >>> n_md5 = str(hashlib.md5(open(write).read()).hexdigest())
     >>> o_md5 == n_md5
@@ -105,9 +105,9 @@ class MakeConf:
         >>> config['make_conf'] = write
         >>> b = MakeConf(config, c.overlays)
         >>> [i.name for i in b.overlays]
-        [u'wrobel', u'wrobel-stable']
+        ['wrobel', 'wrobel-stable']
         >>> b.extra
-        [u'/usr/local/portage/ebuilds/testing', 
u'/usr/local/portage/ebuilds/stable', u'/usr/local/portage/kolab2', 
u'/usr/local/portage/gentoo-webapps-overlay/experimental', 
u'/usr/local/portage/gentoo-webapps-overlay/production-ready']
+        ['/usr/local/portage/ebuilds/testing', 
'/usr/local/portage/ebuilds/stable', '/usr/local/portage/kolab2', 
'/usr/local/portage/gentoo-webapps-overlay/experimental', 
'/usr/local/portage/gentoo-webapps-overlay/production-ready']
 
         >>> os.unlink(write)
         >>> import shutil
@@ -139,7 +139,7 @@ class MakeConf:
         >>> [i.name for i in b.overlays]
         []
         >>> b.extra
-        [u'/usr/local/portage/ebuilds/testing', 
u'/usr/local/portage/ebuilds/stable', u'/usr/local/portage/kolab2', 
u'/usr/local/portage/gentoo-webapps-overlay/experimental', 
u'/usr/local/portage/gentoo-webapps-overlay/production-ready']
+        ['/usr/local/portage/ebuilds/testing', 
'/usr/local/portage/ebuilds/stable', '/usr/local/portage/kolab2', 
'/usr/local/portage/gentoo-webapps-overlay/experimental', 
'/usr/local/portage/gentoo-webapps-overlay/production-ready']
 
         >>> os.unlink(write)
         >>> import shutil
@@ -164,9 +164,9 @@ class MakeConf:
         >>> c = DB(config)
         >>> a = MakeConf(config, c.overlays)
         >>> [i.name for i in a.overlays]
-        [u'wrobel-stable']
+        ['wrobel-stable']
         >>> a.extra
-        [u'/usr/local/portage/ebuilds/testing', 
u'/usr/local/portage/ebuilds/stable', u'/usr/local/portage/kolab2', 
u'/usr/local/portage/gentoo-webapps-overlay/experimental', 
u'/usr/local/portage/gentoo-webapps-overlay/production-ready']
+        ['/usr/local/portage/ebuilds/testing', 
'/usr/local/portage/ebuilds/stable', '/usr/local/portage/kolab2', 
'/usr/local/portage/gentoo-webapps-overlay/experimental', 
'/usr/local/portage/gentoo-webapps-overlay/production-ready']
         '''
         if os.path.isfile(self.path):
             self.content()
@@ -230,9 +230,9 @@ class MakeConf:
         >>> config['make_conf'] = write
         >>> b = MakeConf(config, c.overlays)
         >>> [i.name for i in b.overlays]
-        [u'wrobel-stable']
+        ['wrobel-stable']
         >>> b.extra
-        [u'/usr/local/portage/ebuilds/testing', 
u'/usr/local/portage/ebuilds/stable', u'/usr/local/portage/kolab2', 
u'/usr/local/portage/gentoo-webapps-overlay/experimental', 
u'/usr/local/portage/gentoo-webapps-overlay/production-ready']
+        ['/usr/local/portage/ebuilds/testing', 
'/usr/local/portage/ebuilds/stable', '/usr/local/portage/kolab2', 
'/usr/local/portage/gentoo-webapps-overlay/experimental', 
'/usr/local/portage/gentoo-webapps-overlay/production-ready']
 
         >>> os.unlink(write)
         >>> import shutil

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 0c2d042..174518b 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -20,6 +20,8 @@
 #
 ''' Basic overlay class.'''
 
+from __future__ import unicode_literals
+
 __version__ = "0.2"
 
 
#===============================================================================
@@ -85,15 +87,15 @@ class Overlay(object):
         >>> output = Message()
         >>> a = Overlay({'output': output}, overlays[0])
         >>> a.name
-        u'wrobel'
+        'wrobel'
         >>> a.is_official()
         True
         >>> list(a.source_uris())
-        [u'https://overlays.gentoo.org/svn/dev/wrobel']
+        ['https://overlays.gentoo.org/svn/dev/wrobel']
         >>> a.owner_email
-        u'[email protected]'
+        '[email protected]'
         >>> a.description
-        u'Test'
+        'Test'
         >>> a.priority
         10
         >>> b = Overlay({'output': output}, overlays[1])
@@ -208,7 +210,7 @@ class Overlay(object):
         else:
             self.status = None
 
-        self.quality = u'experimental'
+        self.quality = 'experimental'
         if 'quality' in xml.attrib:
             if xml.attrib['quality'] in set(QUALITY_LEVELS):
                 self.quality = encode(xml.attrib['quality'])
@@ -304,7 +306,7 @@ class Overlay(object):
         else:
             self.status = None
 
-        self.quality = u'experimental'
+        self.quality = 'experimental'
         if len(overlay['quality']):
             if overlay['quality'] in set(QUALITY_LEVELS):
                 self.quality = encode(overlay['quality'])
@@ -453,55 +455,55 @@ class Overlay(object):
         <BLANKLINE>
         '''
 
-        result = u''
+        result = ''
 
-        result += self.name + u'\n' + (len(self.name) * u'~')
+        result += self.name + '\n' + (len(self.name) * '~')
 
         if len(self.sources) == 1:
-            result += u'\nSource  : ' + self.sources[0].src
+            result += '\nSource  : ' + self.sources[0].src
         else:
-            result += u'\nSources:'
+            result += '\nSources:'
             for i, v in enumerate(self.sources):
                 result += '\n  %d. %s' % (i + 1, v.src)
             result += '\n'
 
         if self.owner_name != None:
-            result += u'\nContact : %s <%s>' \
+            result += '\nContact : %s <%s>' \
                 % (self.owner_name, self.owner_email)
         else:
-            result += u'\nContact : ' + self.owner_email
+            result += '\nContact : ' + self.owner_email
         if len(self.sources) == 1:
-            result += u'\nType    : ' + self.sources[0].type
+            result += '\nType    : ' + self.sources[0].type
         else:
-            result += u'\nType    : ' + '/'.join(
+            result += '\nType    : ' + '/'.join(
                 sorted(set(e.type for e in self.sources)))
-        result += u'; Priority: ' + str(self.priority) + u'\n'
-        result += u'Quality : ' + self.quality + u'\n'
+        result += '; Priority: ' + str(self.priority) + '\n'
+        result += 'Quality : ' + self.quality + '\n'
 
 
         description = self.description
-        description = re.compile(u' +').sub(u' ', description)
-        description = re.compile(u'\n ').sub(u'\n', description)
-        result += u'\nDescription:'
-        result += u'\n  '.join((u'\n' + description).split(u'\n'))
-        result += u'\n'
+        description = re.compile(' +').sub(' ', description)
+        description = re.compile('\n ').sub('\n', description)
+        result += '\nDescription:'
+        result += '\n  '.join(('\n' + description).split('\n'))
+        result += '\n'
 
         if self.homepage != None:
             link = self.homepage
-            link = re.compile(u' +').sub(u' ', link)
-            link = re.compile(u'\n ').sub(u'\n', link)
-            result += u'\nLink:'
-            result += u'\n  '.join((u'\n' + link).split(u'\n'))
-            result += u'\n'
+            link = re.compile(' +').sub(' ', link)
+            link = re.compile('\n ').sub('\n', link)
+            result += '\nLink:'
+            result += '\n  '.join(('\n' + link).split('\n'))
+            result += '\n'
 
         if self.irc != None:
-            result += u'\nIRC : ' + self.irc + u'\n'
+            result += '\nIRC : ' + self.irc + '\n'
 
         if len(self.feeds):
-            result += u'\n%s:' % ((len(self.feeds) == 1) and "Feed" or "Feeds")
+            result += '\n%s:' % ((len(self.feeds) == 1) and "Feed" or "Feeds")
             for i in self.feeds:
-                result += u'\n  %s' % i
-            result += u'\n'
+                result += '\n  %s' % i
+            result += '\n'
 
         return encoder(result, self._encoding_)
 

diff --git a/layman/remotedb.py b/layman/remotedb.py
index 38d9fa8..b010e51 100644
--- a/layman/remotedb.py
+++ b/layman/remotedb.py
@@ -160,7 +160,7 @@ class RemoteDB(DbBase):
         >>> os.unlink(a.filepath(config['overlays'])+'.xml')
 
         >>> a.overlays.keys()
-        [u'wrobel', u'wrobel-stable']
+        ['wrobel', 'wrobel-stable']
 
         >>> import shutil
         >>> shutil.rmtree(tmpdir)

diff --git a/layman/utils.py b/layman/utils.py
index f174215..efb3231 100644
--- a/layman/utils.py
+++ b/layman/utils.py
@@ -21,6 +21,8 @@
 
 '''Utility functions to deal with xml nodes. '''
 
+from __future__ import unicode_literals
+
 __version__ = '$Id: utils.py 236 2006-09-05 20:39:37Z wrobel $'
 
 
#===============================================================================
@@ -197,7 +199,7 @@ def create_overlay_dict(**kwargs):
         'feeds': [],
         'sources': [('','','')],
         'priority': 50,
-        'quality': u'experimental',
+        'quality': 'experimental',
         'status': '',
         'official': False,
         'supported': False,

Reply via email to