From 2bd6c5e262df918334e1237d8d61611df2451f73 Mon Sep 17 00:00:00 2001 From: Alexander Saltanov Date: Thu, 3 Oct 2013 03:31:04 +0400 Subject: [PATCH] Remove options and protocols in source line with regex. Fixes #4311 --- library/packaging/apt_repository | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/library/packaging/apt_repository b/library/packaging/apt_repository index 577e4a866d..83c2619dea 100644 --- a/library/packaging/apt_repository +++ b/library/packaging/apt_repository @@ -133,16 +133,14 @@ class SourcesList(object): return os.path.abspath(os.path.join(apt_pkg.config.find_dir('Dir::Etc::sourceparts'), filename)) def _suggest_filename(self, line): - def _remove_protocol(s): - if '://' in s: - return s.split('://')[1] - else: - return s - def _cleanup_filename(s): return '_'.join(re.sub('[^a-zA-Z0-9]', ' ', s).split()) - parts = [_remove_protocol(part) for part in line.split() if part not in VALID_SOURCE_TYPES] + # Drop options and protocols. + line = re.sub('\[[^\]]+\]', '', line) + line = re.sub('\w+://', '', line) + + parts = [part for part in line.split() if part not in VALID_SOURCE_TYPES] return '%s.list' % _cleanup_filename(' '.join(parts[:1])) def _parse(self, line, raise_if_invalid_or_disabled=False):