From: Chris Lamb Date: Wed, 28 Oct 2009 11:19:31 +0000 (+0000) Subject: Split parsing of "Format:" string and validation of it. X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=c9ba1a13b41a4f21b72485d9d93008f4d16f71ac;p=dak.git Split parsing of "Format:" string and validation of it. Signed-off-by: Chris Lamb --- diff --git a/daklib/srcformats.py b/daklib/srcformats.py index 735b7b68..2b07c7ef 100644 --- a/daklib/srcformats.py +++ b/daklib/srcformats.py @@ -28,7 +28,7 @@ class SourceFormat(type): yield "contains source files not allowed in format %s" % cls.name @classmethod - def parse_format(cls, txt, is_a_dsc=False, field='files'): + def parse_format(cls, txt): format = re_verwithext.search(txt) if format is None: @@ -44,17 +44,19 @@ class SourceFormat(type): if format[2] is None: format = format[:2] + return format + + @classmethod + def validate_format(cls, format, is_a_dsc=False, field='files'): if is_a_dsc: if format != (1,0) and \ format != (3,0,"quilt") and format != (3,0,"native"): - raise UnknownFormatError, txt + raise UnknownFormatError, repr(format) else: if (format < (1,5) or format > (1,8)): - raise UnknownFormatError, txt + raise UnknownFormatError, repr(format) if field != "files" and format < (1,8): - raise UnknownFormatError, txt - - return format + raise UnknownFormatError, repr(format) class FormatOne(SourceFormat): __metaclass__ = SourceFormat diff --git a/daklib/utils.py b/daklib/utils.py index 5021483f..8362c57f 100755 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -523,7 +523,8 @@ def build_file_list(changes, is_a_dsc=0, field="files", hashname="md5sum"): if not changes.has_key(field): raise NoFilesFieldError - format = SourceFormat.parse_format(changes.get["format"], field, is_a_dsc) + format = SourceFormat.parse_format(changes.get["format"]) + SourceFormat.validate_format(format, is_a_dsc=False, field='files') includes_section = (not is_a_dsc) and field == "files" diff --git a/tests/test_srcformats.py b/tests/test_srcformats.py index 802f0ffb..9c62d831 100755 --- a/tests/test_srcformats.py +++ b/tests/test_srcformats.py @@ -107,16 +107,16 @@ class FormatTreeQuiltTestCase(SourceFormatTestCase): class ParseFormat(unittest.TestCase): def assertFormat(self, input, expected, **kwargs): - self.assertEqual( - srcformats.SourceFormat.parse_format(input, **kwargs), - expected, - ) + format = srcformats.SourceFormat.parse_format(input) + self.assertEqual(format, expected) + srcformats.SourceFormat.validate_format(format, **kwargs) def assertInvalidFormat(self, input, **kwargs): - self.assertRaises( - UnknownFormatError, - lambda: srcformats.SourceFormat.parse_format(input, **kwargs), - ) + try: + format = srcformats.SourceFormat.parse_format(input) + srcformats.SourceFormat.validate_format(format, **kwargs) + except UnknownFormatError: + return def testEmpty(self): self.assertInvalidFormat('')