diff options
| author | ?ric Araujo <merwok@netwok.org> | 2011-09-18 20:20:13 +0200 |
|---|---|---|
| committer | ?ric Araujo <merwok@netwok.org> | 2011-09-18 20:20:13 +0200 |
| commit | 506cfea8bbd41e865bc36a836bdbc05aae8d74bb (patch) | |
| tree | 3bae418473347324060850aab8d34e162b33ecc9 /distutils2/metadata.py | |
| parent | 8c928044705a70bb845cb45f76edb6eb71393866 (diff) | |
| download | disutils2-506cfea8bbd41e865bc36a836bdbc05aae8d74bb.tar.gz | |
Fix the backport fixes.
Backports:
- sysconfig is now always imported from our backports
- when hashlib is not found, our backport is used instead of the md5
module (debatable; we could just drop hashlib)
Version-dependent features:
- PEP 370 features are only enabled for 2.6+
- the check for sys.dont_write_bytecode was fixed to use getattr
with a default value instead of hasattr
Idioms/syntax:
- octal literals lost their extra 0
- misused try/except blocks have been changed back to try/finally
(it?s legal in 2.4 too, it?s only try/except/finally that isn?t)
- exception catching uses the regular 2.x idiom instead of sys.exc_info
- file objects are closed within finally blocks (this causes much
whitespace changes but actually makes diff with packaging easier)
Renamed modules:
- some missed renamings (_thread, Queue, isAlive, urllib.urlsplit, etc.)
were fixed
Other:
- a few false positive replacements of ?packaging? by ?distutils2? in
comments or docstrings were reverted
- util.is_packaging regained its name
- assorted whitespace/comment/import changes to match packaging
Diffstat (limited to 'distutils2/metadata.py')
| -rw-r--r-- | distutils2/metadata.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/distutils2/metadata.py b/distutils2/metadata.py index 85adeb5..bf02716 100644 --- a/distutils2/metadata.py +++ b/distutils2/metadata.py @@ -3,8 +3,8 @@ Supports all metadata formats (1.0, 1.1, 1.2). """ -import codecs import re +import codecs import logging from StringIO import StringIO @@ -12,10 +12,10 @@ from email import message_from_file from distutils2 import logger from distutils2.markers import interpret from distutils2.version import (is_valid_predicate, is_valid_version, - is_valid_versions) + is_valid_versions) from distutils2.errors import (MetadataMissingError, - MetadataConflictError, - MetadataUnrecognizedVersionError) + MetadataConflictError, + MetadataUnrecognizedVersionError) try: # docutils is installed @@ -311,8 +311,10 @@ class Metadata(object): def read(self, filepath): """Read the metadata values from a file path.""" fp = codecs.open(filepath, 'r', encoding='utf-8') - self.read_file(fp) - fp.close() + try: + self.read_file(fp) + finally: + fp.close() def read_file(self, fileob): """Read the metadata values from a file object.""" @@ -335,8 +337,10 @@ class Metadata(object): def write(self, filepath): """Write the metadata fields to filepath.""" fp = codecs.open(filepath, 'w', encoding='utf-8') - self.write_file(fp) - fp.close() + try: + self.write_file(fp) + finally: + fp.close() def write_file(self, fileobject): """Write the PKG-INFO format data to a file object.""" |
