[yum-commits] Branch 'yum-3_2_X' - 2 commits - yum/Errors.py yum/i18n.py yum/misc.py
skvidal at osuosl.org
skvidal at osuosl.org
Tue Dec 16 16:09:03 UTC 2008
yum/Errors.py | 5 +++++
yum/i18n.py | 31 ++++++++++++++++++++++++++++++-
yum/misc.py | 29 +----------------------------
3 files changed, 36 insertions(+), 29 deletions(-)
New commits:
commit 66f1747e63b9dead528e257cba827f4281f3ce61
Merge: 5c45771... edc44ae...
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Tue Dec 16 11:08:16 2008 -0500
Merge branch 'yum-3_2_X' of ssh://yum.baseurl.org/srv/projects/yum/git/yum into yum-3_2_X
* 'yum-3_2_X' of ssh://yum.baseurl.org/srv/projects/yum/git/yum:
pt_BR translation updates by Igor Pires Soares
Add o as list option, for FEDORA-2008-9779 among others
Use our utf8/non-broken, textwrap, for yum info-security
Use our utf8/non-broken, textwrap, for yum info
Add textwrap.wrap/fill ... as the core versions are broken in various ways
Stop skip-broken from looping in weird cases
diff --cc yum/i18n.py
index d967167,fb7a5ac..46a4318
--- a/yum/i18n.py
+++ b/yum/i18n.py
@@@ -274,38 -275,85 +274,115 @@@ def utf8_valid(msg)
if ucs is None:
return False
return True
+
+ def utf8_text_wrap(text, width=70, initial_indent='', subsequent_indent=''):
+ """ Works like we want textwrap.wrap() to work, uses utf-8 data and
+ doesn't screw up lists/blocks/etc. """
+ # Tested with:
+ # yum info robodoc gpicview php-pear-Net-Socket wmctrl ustr moreutils
+ # mediawiki-HNP ocspd insight yum mousepad
+ # ...at 120, 80 and 40 chars.
+ passed_unicode = isinstance(text, unicode)
+
+ def _indent_at_beg(line):
+ count = 0
+ byte = 'X'
+ for byte in line:
+ if byte != ' ':
+ break
+ count += 1
+ list_chr = utf8_width_chop(line[count:], 1)[1]
+ if list_chr in ("-", "*", ".", "o",
+ "\xe2\x80\xa2", "\xe2\x80\xa3", "\xe2\x88\x98"):
+ nxt = _indent_at_beg(line[count+len(list_chr):])
+ nxt = nxt[1] or nxt[0]
+ if nxt:
+ return count, count + 1 + nxt
+ return count, 0
+
+ initial_indent = to_utf8(initial_indent)
+ subsequent_indent = to_utf8(subsequent_indent)
+
+ text = to_utf8(text).rstrip('\n')
+ lines = to_utf8(text).replace('\t', ' ' * 8).split('\n')
+
+ ret = []
+ indent = initial_indent
+ wrap_last = False
+ csab = 0
+ cspc_indent = 0
+ for line in lines:
+ line = line.rstrip(' ')
+ (lsab, lspc_indent) = (csab, cspc_indent)
+ (csab, cspc_indent) = _indent_at_beg(line)
+ if wrap_last and cspc_indent:
+ ret.append(indent.rstrip(' '))
+ indent = subsequent_indent
+ wrap_last = False
+ if wrap_last:
+ line = line.lstrip(' ')
+ cspc_indent = lspc_indent
+
+ if (utf8_width(indent) + utf8_width(line)) <= width:
+ wrap_last = False
+ ret.append(indent + line)
+ indent = subsequent_indent
+ continue
+
+ wrap_last = True
+ words = line.split(' ')
+ line = indent
+ while words:
+ word = words.pop(0)
+ if (utf8_width(line) + utf8_width(word)) > width:
+ ret.append(line.rstrip(' '))
+ line = subsequent_indent + ' ' * cspc_indent
+ line += word
+ line += ' '
+ indent = line.rstrip(' ') + ' '
+ if wrap_last:
+ ret.append(indent.rstrip(' '))
+
+ if passed_unicode:
+ return map(to_unicode, ret)
+ return ret
+
+ def utf8_text_fill(text, *args, **kwargs):
+ """ Works like we want textwrap.fill() to work, uses utf-8 data and
+ doesn't screw up lists/blocks/etc. """
+ return '\n'.join(utf8_text_wrap(text, *args, **kwargs))
# ----------------------------- END utf8 -----------------------------
+def to_unicode(obj, encoding='utf-8', errors='replace'):
+ ''' convert a 'str' to 'unicode' '''
+ if isinstance(obj, basestring):
+ if not isinstance(obj, unicode):
+ obj = unicode(obj, encoding, errors)
+ return obj
+
+def to_utf8(obj, errors='replace'):
+ '''convert 'unicode' to an encoded utf-8 byte string '''
+ if isinstance(obj, unicode):
+ obj = obj.encode('utf-8', errors)
+ return obj
+
+# Don't use this, to_unicode should just work now
+def to_unicode_maybe(obj, encoding='utf-8', errors='replace'):
+ ''' Don't ask don't tell, only use when you must '''
+ try:
+ return to_unicode(obj, encoding, errors)
+ except UnicodeEncodeError:
+ return obj
+
+def to_str(obj):
+ """ Convert something to a string, if it isn't one. """
+ # NOTE: unicode counts as a string just fine. We just want objects to call
+ # their __str__ methods.
+ if not isinstance(obj, basestring):
+ obj = str(obj)
+ return obj
+
+
try:
'''
Setup the yum translation domain and make _() translation wrapper
commit 5c4577185666afe7928073924f8c1ebd71de07ac
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Tue Dec 16 11:06:24 2008 -0500
to make exception reporting work on python 2.6.
thanks to Ignacio Vazquez for finding the specific problem.
closes rh bug #475633
diff --git a/yum/Errors.py b/yum/Errors.py
index 4bccd86..be6bda2 100644
--- a/yum/Errors.py
+++ b/yum/Errors.py
@@ -18,6 +18,8 @@
Exceptions and Errors thrown by yum.
"""
+from i18n import to_unicode
+
class YumBaseError(Exception):
"""
Base Yum Error. All other Errors thrown by yum should inherit from
@@ -29,6 +31,9 @@ class YumBaseError(Exception):
def __str__(self):
return "%s" %(self.value,)
+ def __unicode__(self):
+ return '%s' % to_unicode(self.value)
+
class YumGPGCheckError(YumBaseError):
pass
diff --git a/yum/i18n.py b/yum/i18n.py
index bcc895e..d967167 100755
--- a/yum/i18n.py
+++ b/yum/i18n.py
@@ -13,7 +13,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-from yum.misc import to_unicode, to_utf8
def dummy_wrapper(str):
'''
@@ -277,6 +276,36 @@ def utf8_valid(msg):
return True
# ----------------------------- END utf8 -----------------------------
+def to_unicode(obj, encoding='utf-8', errors='replace'):
+ ''' convert a 'str' to 'unicode' '''
+ if isinstance(obj, basestring):
+ if not isinstance(obj, unicode):
+ obj = unicode(obj, encoding, errors)
+ return obj
+
+def to_utf8(obj, errors='replace'):
+ '''convert 'unicode' to an encoded utf-8 byte string '''
+ if isinstance(obj, unicode):
+ obj = obj.encode('utf-8', errors)
+ return obj
+
+# Don't use this, to_unicode should just work now
+def to_unicode_maybe(obj, encoding='utf-8', errors='replace'):
+ ''' Don't ask don't tell, only use when you must '''
+ try:
+ return to_unicode(obj, encoding, errors)
+ except UnicodeEncodeError:
+ return obj
+
+def to_str(obj):
+ """ Convert something to a string, if it isn't one. """
+ # NOTE: unicode counts as a string just fine. We just want objects to call
+ # their __str__ methods.
+ if not isinstance(obj, basestring):
+ obj = str(obj)
+ return obj
+
+
try:
'''
Setup the yum translation domain and make _() translation wrapper
diff --git a/yum/misc.py b/yum/misc.py
index 108283b..e0e8256 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -40,6 +40,7 @@ except ImportError:
raise ValueError, "Bad checksum type"
from Errors import MiscError
+from i18n import to_unicode, to_unicode_maybe, to_utf8, to_str
_share_data_store = {}
_share_data_store_u = {}
@@ -777,34 +778,6 @@ def setup_locale(override_codecs=True, override_time=False):
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
sys.stdout.errors = 'replace'
-def to_unicode(obj, encoding='utf-8', errors='replace'):
- ''' convert a 'str' to 'unicode' '''
- if isinstance(obj, basestring):
- if not isinstance(obj, unicode):
- obj = unicode(obj, encoding, errors)
- return obj
-
-def to_utf8(obj, errors='replace'):
- '''convert 'unicode' to an encoded utf-8 byte string '''
- if isinstance(obj, unicode):
- obj = obj.encode('utf-8', errors)
- return obj
-
-# Don't use this, to_unicode should just work now
-def to_unicode_maybe(obj, encoding='utf-8', errors='replace'):
- ''' Don't ask don't tell, only use when you must '''
- try:
- return to_unicode(obj, encoding, errors)
- except UnicodeEncodeError:
- return obj
-
-def to_str(obj):
- """ Convert something to a string, if it isn't one. """
- # NOTE: unicode counts as a string just fine. We just want objects to call
- # their __str__ methods.
- if not isinstance(obj, basestring):
- obj = str(obj)
- return obj
def get_my_lang_code():
mylang = locale.getlocale()
More information about the Yum-commits
mailing list