From d120d044e1391a1af26b6c547eb8b3913c60ac12 Mon Sep 17 00:00:00 2001 From: Ben Finney Date: Sat, 15 Aug 2015 16:18:16 +1000 Subject: [PATCH] =?utf8?q?Migrate=20from=20deprecated=20=E2=80=98rfc822?= =?utf8?q?=E2=80=99=20module=20to=20current=20=E2=80=98email.parser?= =?utf8?q?=E2=80=99=20module.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- dput/dcut.py | 2 +- dput/dput.py | 39 ++++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/dput/dcut.py b/dput/dcut.py index ce31b55..8e74f87 100755 --- a/dput/dcut.py +++ b/dput/dcut.py @@ -457,7 +457,7 @@ def create_commands(options, config, parse_changes): the_changes = parse_changes(chg_fd) chg_fd.close removecommands = ['rm --searchdirs ' + os.path.basename(changes_file)] - for file in the_changes.dict['files'].split('\n'): + for file in the_changes['files'].strip().split('\n'): # filename only fn = file.split()[4] rm = 'rm --searchdirs ' + fn diff --git a/dput/dput.py b/dput/dput.py index 053585d..daf7e31 100755 --- a/dput/dput.py +++ b/dput/dput.py @@ -35,7 +35,7 @@ import signal import subprocess import pwd import stat -import rfc822 +import email.parser from hashlib import md5, sha1 import importlib import pkgutil @@ -103,8 +103,11 @@ def parse_changes(chg_fd): chg_fd.readline() if not chg_fd.readline().find('Format') != -1: chg_fd.readline() - changes = rfc822.Message(chg_fd) - for a in changes.dict['files'].split('\n'): + changes_text = chg_fd.read() + changes = email.parser.HeaderParser().parsestr(changes_text) + if 'files' not in changes: + raise KeyError("No Files field in upload control file") + for a in changes['files'].strip().split('\n'): if len(a.split()) != 5: sys.stderr.write("Invalid Files line in .changes:\n %s\n" % a) sys.exit(1) @@ -263,8 +266,8 @@ def check_signature(filename): def check_upload_variant(changes, debug): """ Check if this is a binary_upload only or not. """ binary_upload = 0 - if 'architecture' in changes.dict: - arch = changes.dict['architecture'] + if 'architecture' in changes: + arch = changes['architecture'] if debug: print "D: Architecture: %s" % arch if arch.find('source') < 0: @@ -294,8 +297,8 @@ def verify_signature( def source_check(changes, debug): """ Check if a source tarball has to be included in the package or not. """ include_orig = include_tar = 0 - if 'version' in changes.dict: - version = changes.dict['version'] + if 'version' in changes: + version = changes['version'] if debug: print "D: Package Version: %s" % version # versions with a dash in them are for non-native only @@ -350,7 +353,7 @@ def verify_files( dsc_file = '' else: dsc_file = None - for file in changes.dict['files'].split('\n'): + for file in changes['files'].strip().split('\n'): # filename only filename = file.split()[4] if filename.find('.dsc') != -1: @@ -378,7 +381,7 @@ def verify_files( (include_orig_tar_gz, include_tar_gz) = source_check(changes, debug) # Check md5sum and the size - file_list = changes.dict['files'].split('\n') + file_list = changes['files'].strip().split('\n') hash_to_use = config.get('DEFAULT', 'hash') for line in file_list: (check_sum, size, section, priority, file) = line.split() @@ -608,7 +611,7 @@ def version_check(path, changes, debug): print "D: detected architecture: '%s'" % dpkg_architecture # Get filenames of deb files: - for file in changes.dict['files'].split('\n'): + for file in changes['files'].strip().split('\n'): filename = os.path.join(path, file.split()[4]) if filename.endswith('.deb'): if debug: @@ -618,23 +621,24 @@ def version_check(path, changes, debug): stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, close_fds=True) (dpkg_stdout, dpkg_stderr) = (dpkg_proc.stdout, dpkg_proc.stderr) - dpkg_output = rfc822.Message(dpkg_stdout) + dpkg_output = dpkg_stdout.read() dpkg_stdout.close() + dpkg_fields = email.parser.HeaderParser().parsestr(dpkg_output) dpkg_stderr_output = dpkg_stderr.read() dpkg_stderr.close() if debug and dpkg_stderr_output: print "D: dpkg stderr output:", repr(dpkg_stderr_output) if ( dpkg_architecture - and dpkg_output['architecture'] not in [ + and dpkg_fields['architecture'] not in [ 'all', dpkg_architecture]): if debug: print ( "D: not install-checking %s due to arch mismatch" % filename) else: - package_name = dpkg_output['package'] - version_number = dpkg_output['version'] + package_name = dpkg_fields['package'] + version_number = dpkg_fields['version'] if debug: print "D: Package to Check: %s" % package_name if debug: @@ -649,14 +653,15 @@ def version_check(path, changes, debug): stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, close_fds=True) (dpkg_stdout, dpkg_stderr) = (dpkg_proc.stdout, dpkg_proc.stderr) - dpkg_output = rfc822.Message(dpkg_stdout) + dpkg_output = dpkg_stdout.read() dpkg_stdout.close() + dpkg_fields = email.parser.HeaderParser().parsestr(dpkg_output) dpkg_stderr_output = dpkg_stderr.read() dpkg_stderr.close() if debug and dpkg_stderr_output: print "D: dpkg stderr output:", repr(dpkg_stderr_output) - if 'version' in dpkg_output: - installed_version = dpkg_output.dict['version'] + if 'version' in dpkg_fields: + installed_version = dpkg_fields['version'] if debug: print "D: Installed-Version: %s" % installed_version if debug: -- 2.11.4.GIT