diff options
| author | Tarek Ziad? <tarek@ziade.org> | 2010-02-25 00:33:31 -0500 |
|---|---|---|
| committer | Tarek Ziad? <tarek@ziade.org> | 2010-02-25 00:33:31 -0500 |
| commit | 53bb51a9472ec16e8dce38db9097969d1e5b9141 (patch) | |
| tree | dcec3b5df2bd73c3ca581f052a07a69fc41c91af /src/distutils2 | |
| parent | 092638bcb6089040570111749d3f689a57731907 (diff) | |
| download | disutils2-53bb51a9472ec16e8dce38db9097969d1e5b9141.tar.gz | |
now the Description field can be read back (no more EOL lost)
Diffstat (limited to 'src/distutils2')
| -rw-r--r-- | src/distutils2/metadata.py | 12 | ||||
| -rw-r--r-- | src/distutils2/tests/PKG-INFO | 6 | ||||
| -rw-r--r-- | src/distutils2/tests/test_dist.py | 2 | ||||
| -rw-r--r-- | src/distutils2/tests/test_metadata.py | 20 |
4 files changed, 33 insertions, 7 deletions
diff --git a/src/distutils2/metadata.py b/src/distutils2/metadata.py index 277dd89..48ff19c 100644 --- a/src/distutils2/metadata.py +++ b/src/distutils2/metadata.py @@ -50,7 +50,7 @@ PEP 345 - Metadata v1.2 - Obsoletes-Dist (multiple) """ - +import re import os import sys import platform @@ -87,7 +87,7 @@ except ImportError: # Encoding used for the PKG-INFO files PKG_INFO_ENCODING = 'utf-8' - +_LINE_PREFIX = re.compile('\n \|') _241_FIELDS = ('Metadata-Version', 'Name', 'Version', 'Platform', 'Summary', 'Description', 'Keywords', 'Home-page', 'Author', 'Author-email', @@ -217,6 +217,9 @@ class DistributionMetadata(object): value, marker = value.split(';') return _interpret(marker), value + def _remove_line_prefix(self, value): + return _LINE_PREFIX.sub('\n', value) + # # Public APIs # @@ -278,7 +281,10 @@ class DistributionMetadata(object): self._write_field(fileobject, field, ','.join(values)) continue if field not in _LISTFIELDS: + if field == 'Description': + values = values.replace('\n', '\n |') values = [values] + for value in values: self._write_field(fileobject, field, value) @@ -294,6 +300,8 @@ class DistributionMetadata(object): value = value.split(',') elif name in _UNICODEFIELDS: value = self._encode_field(value) + if name == 'Description': + value = self._remove_line_prefix(value) self._fields[name] = value def get_field(self, name): diff --git a/src/distutils2/tests/PKG-INFO b/src/distutils2/tests/PKG-INFO index c761086..f48546e 100644 --- a/src/distutils2/tests/PKG-INFO +++ b/src/distutils2/tests/PKG-INFO @@ -45,15 +45,13 @@ Description: CLVault |a keyring while the description is saved in a ``.clvault`` file in your |home directory. This file is created automatically the first time the command |is used. - + | |*clvault-get* copies the password for a given service in your clipboard, and |displays the associated user if any. - + | |*clvault-list* lists all registered services, with their description when |given. | | |Project page: http://bitbucket.org/tarek/clvault | - - diff --git a/src/distutils2/tests/test_dist.py b/src/distutils2/tests/test_dist.py index 9bfa2e7..fcf333b 100644 --- a/src/distutils2/tests/test_dist.py +++ b/src/distutils2/tests/test_dist.py @@ -391,7 +391,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard, dist = distutils2.dist.Distribution(attrs) meta = self.format_metadata(dist) - meta = meta.replace('\n' + 8 * ' ', '\n') + meta = meta.replace('\n' + 7 * ' ' + '|', '\n') self.assertTrue(long_desc in meta) def test_read_metadata(self): diff --git a/src/distutils2/tests/test_metadata.py b/src/distutils2/tests/test_metadata.py index 10237bf..f259463 100644 --- a/src/distutils2/tests/test_metadata.py +++ b/src/distutils2/tests/test_metadata.py @@ -73,6 +73,26 @@ class DistributionMetadataTestCase(unittest2.TestCase): metadata.read_file(StringIO(content)) self.assertEquals(metadata['Requires-Dist'], ['bar']) + def test_description(self): + PKG_INFO = os.path.join(os.path.dirname(__file__), 'PKG-INFO') + content = open(PKG_INFO).read() + content = content % sys.platform + metadata = DistributionMetadata() + metadata.read_file(StringIO(content)) + + # see if we can read the description now + DESC = os.path.join(os.path.dirname(__file__), 'LONG_DESC.txt') + wanted = open(DESC).read() + self.assertEquals(wanted, metadata['Description']) + + # save the file somewhere and make sure we can read it back + out = StringIO() + metadata.write_file(out) + out.seek(0) + metadata.read_file(out) + self.assertEquals(wanted, metadata['Description']) + + def test_suite(): return unittest2.makeSuite(DistributionMetadataTestCase) |
