[kernel] r18493 - dists/trunk/linux-2.6/debian/lib/python/debian_linux

Bastian Blank waldi at alioth.debian.org
Wed Jan 11 18:03:28 UTC 2012


Author: waldi
Date: Wed Jan 11 18:03:27 2012
New Revision: 18493

Log:
debian/lib/python: Use unicode always.

Modified:
   dists/trunk/linux-2.6/debian/lib/python/debian_linux/debian.py
   dists/trunk/linux-2.6/debian/lib/python/debian_linux/gencontrol.py
   dists/trunk/linux-2.6/debian/lib/python/debian_linux/utils.py

Modified: dists/trunk/linux-2.6/debian/lib/python/debian_linux/debian.py
==============================================================================
--- dists/trunk/linux-2.6/debian/lib/python/debian_linux/debian.py	Wed Jan 11 17:46:47 2012	(r18492)
+++ dists/trunk/linux-2.6/debian/lib/python/debian_linux/debian.py	Wed Jan 11 18:03:27 2012	(r18493)
@@ -5,6 +5,7 @@
 
 from . import utils
 
+
 class Changelog(list):
     _rules = r"""
 ^
@@ -74,32 +75,32 @@
     def __init__(self, version):
         match = self._version_re.match(version)
         if match is None:
-            raise RuntimeError("Invalid debian version")
+            raise RuntimeError(u"Invalid debian version")
         self.epoch = None
         if match.group("epoch") is not None:
             self.epoch = int(match.group("epoch"))
         self.upstream = match.group("upstream")
         self.revision = match.group("revision")
 
-    def __str__(self):
+    def __unicode__(self):
         return self.complete
 
     @property
     def complete(self):
         if self.epoch is not None:
-            return "%d:%s" % (self.epoch, self.complete_noepoch)
+            return u"%d:%s" % (self.epoch, self.complete_noepoch)
         return self.complete_noepoch
 
     @property
     def complete_noepoch(self):
         if self.revision is not None:
-            return "%s-%s" % (self.upstream, self.revision)
+            return u"%s-%s" % (self.upstream, self.revision)
         return self.upstream
 
     @property
     def debian(self):
         from warnings import warn
-        warn("debian argument was replaced by revision", DeprecationWarning, stacklevel=2)
+        warn(u"debian argument was replaced by revision", DeprecationWarning, stacklevel=2)
         return self.revision
 
 
@@ -144,7 +145,7 @@
         super(VersionLinux, self).__init__(version)
         match = self._version_linux_re.match(version)
         if match is None:
-            raise RuntimeError("Invalid debian linux version")
+            raise RuntimeError(u"Invalid debian linux version")
         d = match.groupdict()
         self.linux_modifier = d['modifier']
         self.linux_version = d['version']
@@ -174,7 +175,7 @@
     def __len__(self):
         return self._data.__len__()
 
-    def __str__(self):
+    def __unicode__(self):
         return ' '.join(sorted(self))
 
     def add(self, value):
@@ -198,11 +199,11 @@
         self.short = []
         self.long = []
         if value is not None:
-            short, long = value.split("\n", 1)
+            short, long = value.split(u"\n", 1)
             self.append(long)
             self.append_short(short)
 
-    def __str__(self):
+    def __unicode__(self):
         wrap = utils.TextWrapper(width=74, fix_sentence_endings=True).wrap
         short = ', '.join(self.short)
         long_pars = []
@@ -214,10 +215,10 @@
     def append(self, str):
         str = str.strip()
         if str:
-            self.long.extend(str.split("\n.\n"))
+            self.long.extend(str.split(u"\n.\n"))
 
     def append_short(self, str):
-        for i in [i.strip() for i in str.split(",")]:
+        for i in [i.strip() for i in str.split(u",")]:
             if i:
                 self.short.append(i)
 
@@ -234,8 +235,8 @@
         if value:
             self.extend(value, override_arches)
 
-    def __str__(self):
-        return ', '.join([str(i) for i in self])
+    def __unicode__(self):
+        return ', '.join([unicode(i) for i in self])
 
     def _search_value(self, value):
         for i in self:
@@ -247,7 +248,7 @@
         if isinstance(value, basestring):
             value = PackageRelationGroup(value, override_arches)
         elif not isinstance(value, PackageRelationGroup):
-            raise ValueError("got %s" % type(value))
+            raise ValueError(u"got %s" % type(value))
         j = self._search_value(value)
         if j:
             j._update_arches(value)
@@ -258,7 +259,7 @@
         if isinstance(value, basestring):
             value = [j.strip() for j in re.split(',', value.strip())]
         elif not isinstance(value, (list, tuple)):
-            raise ValueError("got %s" % type(value))
+            raise ValueError(u"got %s" % type(value))
         for i in value:
             self.append(i, override_arches)
 
@@ -268,8 +269,8 @@
         if value:
             self.extend(value, override_arches)
 
-    def __str__(self):
-        return ' | '.join([str(i) for i in self])
+    def __unicode__(self):
+        return ' | '.join([unicode(i) for i in self])
 
     def _search_value(self, value):
         for i, j in itertools.izip(self, value):
@@ -314,12 +315,12 @@
         OP_GT = 6
 
         operators = {
-                '<<': OP_LT,
-                '<=': OP_LE,
-                '=': OP_EQ,
-                '!=': OP_NE,
-                '>=': OP_GE,
-                '>>': OP_GT,
+                u'<<': OP_LT,
+                u'<=': OP_LE,
+                u'=': OP_EQ,
+                u'!=': OP_NE,
+                u'>=': OP_GE,
+                u'>>': OP_GT,
         }
 
         operators_neg = {
@@ -341,7 +342,7 @@
         def __neg__(self):
             return self.__class__(self.operators_text[self.operators_neg[self._op]])
 
-        def __str__(self):
+        def __unicode__(self):
             return self.operators_text[self._op]
 
     def __init__(self, value=None, override_arches=None):
@@ -353,18 +354,18 @@
         if override_arches:
             self.arches = list(override_arches)
 
-    def __str__(self):
+    def __unicode__(self):
         ret = [self.name]
         if self.operator is not None and self.version is not None:
-            ret.extend([' (', str(self.operator), ' ', self.version, ')'])
+            ret.extend((u' (', unicode(self.operator), u' ', self.version, u')'))
         if self.arches:
-            ret.extend([' [', ' '.join(self.arches), ']'])
+            ret.extend((u' [', u' '.join(self.arches), u']'))
         return ''.join(ret)
 
     def parse(self, value):
         match = self._re.match(value)
         if match is None:
-            raise RuntimeError("Can't parse dependency %s" % value)
+            raise RuntimeError(u"Can't parse dependency %s" % value)
         match = match.groups()
         self.name = match[0]
         if match[1] is not None:
@@ -380,14 +381,14 @@
 
 class Package(dict):
     _fields = collections.OrderedDict((
-        ('Package', str),
-        ('Source', str),
+        ('Package', unicode),
+        ('Source', unicode),
         ('Architecture', PackageArchitecture),
-        ('Section', str),
-        ('Priority', str),
-        ('Maintainer', str),
-        ('Uploaders', str),
-        ('Standards-Version', str),
+        ('Section', unicode),
+        ('Priority', unicode),
+        ('Maintainer', unicode),
+        ('Uploaders', unicode),
+        ('Standards-Version', unicode),
         ('Build-Depends', PackageRelation),
         ('Build-Depends-Indep', PackageRelation),
         ('Provides', PackageRelation),

Modified: dists/trunk/linux-2.6/debian/lib/python/debian_linux/gencontrol.py
==============================================================================
--- dists/trunk/linux-2.6/debian/lib/python/debian_linux/gencontrol.py	Wed Jan 11 17:46:47 2012	(r18492)
+++ dists/trunk/linux-2.6/debian/lib/python/debian_linux/gencontrol.py	Wed Jan 11 18:03:27 2012	(r18493)
@@ -1,3 +1,4 @@
+import codecs
 from collections import OrderedDict
 
 from .debian import *
@@ -278,7 +279,7 @@
         def subst(match):
             return vars[match.group(1)]
 
-        return re.sub(r'@([-_a-z]+)@', subst, str(s))
+        return re.sub(r'@([-_a-z]+)@', subst, unicode(s))
 
     def write(self, packages, makefile):
         self.write_control(packages.itervalues())
@@ -290,7 +291,7 @@
         f.close()
 
     def write_control(self, list):
-        self.write_rfc822(file("debian/control", 'w'), list)
+        self.write_rfc822(codecs.open("debian/control", 'w', 'utf-8'), list)
 
     def write_makefile(self, makefile):
         f = file("debian/rules.gen", 'w')
@@ -300,5 +301,6 @@
     def write_rfc822(self, f, list):
         for entry in list:
             for key, value in entry.iteritems():
-                f.write("%s: %s\n" % (key, value))
-            f.write('\n')
+                print key, repr(unicode(value))
+                f.write(u"%s: %s\n" % (key, value))
+            f.write(u'\n')

Modified: dists/trunk/linux-2.6/debian/lib/python/debian_linux/utils.py
==============================================================================
--- dists/trunk/linux-2.6/debian/lib/python/debian_linux/utils.py	Wed Jan 11 17:46:47 2012	(r18492)
+++ dists/trunk/linux-2.6/debian/lib/python/debian_linux/utils.py	Wed Jan 11 18:03:27 2012	(r18493)
@@ -1,3 +1,4 @@
+import codecs
 import os
 import re
 import textwrap
@@ -21,7 +22,7 @@
         for dir in self.dirs:
             filename = "%s/%s.in" % (dir, name)
             if os.path.exists(filename):
-                f = file(filename)
+                f = codecs.open(filename, 'r', 'utf-8')
                 if prefix == 'control':
                     return read_control(f)
                 return f.read()
@@ -56,14 +57,14 @@
                 break
             if line[0] in ' \t':
                 if not last:
-                    raise ValueError('Continuation line seen before first header')
+                    raise ValueError(u'Continuation line seen before first header')
                 lines.append(line.lstrip())
                 continue
             if last:
-                e[last] = '\n'.join(lines)
+                e[last] = u'\n'.join(lines)
             i = line.find(':')
             if i < 0:
-                raise ValueError("Not a header, not a continuation: ``%s''" % line)
+                raise ValueError(u"Not a header, not a continuation: ``%s''" % line)
             last = line[:i]
             lines = [line[i + 1:].lstrip()]
         if last:



More information about the Kernel-svn-changes mailing list