From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/rpackage/
Date: Tue, 7 Aug 2012 08:50:26 +0000 (UTC) [thread overview]
Message-ID: <1344329359.9692add5a980cd10bd8e4841c9b8e55aa46a8d91.dywi@gentoo> (raw)
commit: 9692add5a980cd10bd8e4841c9b8e55aa46a8d91
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Aug 7 08:49:19 2012 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Aug 7 08:49:19 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=9692add5
descriptionreader: use bytes_try_decode() from strutil
---
roverlay/rpackage/descriptionreader.py | 61 +++++++++++++++++--------------
1 files changed, 33 insertions(+), 28 deletions(-)
diff --git a/roverlay/rpackage/descriptionreader.py b/roverlay/rpackage/descriptionreader.py
index a5e645e..354ac94 100644
--- a/roverlay/rpackage/descriptionreader.py
+++ b/roverlay/rpackage/descriptionreader.py
@@ -9,6 +9,7 @@
__all__ = [ 'DescriptionReader', 'make_desc_packageinfo', ]
import re
+import sys
import tarfile
import os.path
import time
@@ -207,38 +208,42 @@ class DescriptionReader ( object ):
"Starting to read file {f!r} ...\n".format ( f=filepath )
)
- if not ( isinstance ( filepath, str ) and filepath ):
- raise Exception ( "bad usage" )
-
- # read describes how to import the lines from a file (e.g. rstrip())
- # fh, th are file/tar handles
- read = th = fh = None
+ try:
+ # read describes how to import the lines from a file (e.g. rstrip())
+ # fh, th are file/tar handles
+ read = th = fh = None
+
+ if tarfile.is_tarfile ( filepath ):
+ # filepath is a tarball, open tar handle + file handle
+ th = tarfile.open ( filepath, mode='r' )
+ if pkg_name:
+ fh = th.extractfile (
+ pkg_name + os.path.sep + \
+ config.get ( 'DESCRIPTION.file_name' )
+ )
+ else:
+ fh = th.extractfile ( config.get ( 'DESCRIPTION.file_name' ) )
- if tarfile.is_tarfile ( filepath ):
- # filepath is a tarball, open tar handle + file handle
- th = tarfile.open ( filepath, mode='r' )
- if pkg_name:
- fh = th.extractfile (
- pkg_name + os.path.sep + config.get ( 'DESCRIPTION.file_name' )
+ else:
+ # open file handle only
+ # COULDFIX: .Z compressed tar files could be opened here
+ fh = open ( filepath, 'r' )
+
+ if sys.version_info >= ( 3, ):
+ # decode lines of they're only bytes, using isinstance ( <>, str )
+ # 'cause isinstance ( <str>, bytes ) returns True
+ # FIXME: encoding is unknown, could be ascii/iso8859*/utf8
+ read_lines = tuple (
+ strutil.bytes_try_decode ( l ).rstrip() for l in fh.readlines()
)
else:
- fh = th.extractfile ( config.get ( 'DESCRIPTION.file_name' ) )
-
- else:
- # open file handle only
- # COULDFIX: .Z compressed tar files could be opened here
- fh = open ( filepath, 'r' )
-
- # decode lines of they're only bytes, using isinstance ( <>, str )
- # 'cause isinstance ( <str>, bytes ) returns True
- read_lines = tuple (
- ( line if isinstance ( line, str ) else line.decode() ).rstrip()
- for line in fh.readlines()
- )
+ # python2 shouldn't need special decoding
+ read_lines = tuple ( l.rstrip() for l in fh.readlines() )
- fh.close()
- if not th is None: th.close()
- del fh, th
+ finally:
+ if 'fh' in locals() and fh: fh.close()
+ if 'th' in locals() and th: th.close()
+ del fh, th
if read_lines and hasattr ( self, 'write_desc_file' ):
try:
next reply other threads:[~2012-08-07 8:50 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-07 8:50 André Erdmann [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-02-16 1:35 [gentoo-commits] proj/R_overlay:master commit in: roverlay/rpackage/ Benda XU
2013-08-21 13:51 André Erdmann
2013-08-21 13:51 André Erdmann
2013-08-20 21:46 André Erdmann
2013-07-25 13:28 André Erdmann
2013-07-25 13:25 André Erdmann
2013-07-25 8:47 André Erdmann
2013-07-25 8:47 André Erdmann
2013-07-23 18:34 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23 18:34 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-11 16:29 André Erdmann
2013-04-25 16:44 André Erdmann
2013-02-09 20:45 André Erdmann
2012-07-30 8:52 André Erdmann
2012-07-06 22:19 André Erdmann
2012-07-03 17:48 André Erdmann
2012-07-02 16:52 André Erdmann
2012-06-29 22:48 André Erdmann
2012-06-28 15:55 André Erdmann
2012-06-28 15:55 André Erdmann
2012-06-27 14:46 André Erdmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1344329359.9692add5a980cd10bd8e4841c9b8e55aa46a8d91.dywi@gentoo \
--to=dywi@mailerd.de \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox