version parsing: fix errors with 3.0.0_pre1 (!1735)

Python < 3.6 randomized the order of keys in dictionaries, unless
OrderedDict was used. Use OrderedDict to store the version suffixes.

When the order was randomized, the valid version string 3.0.0_pre1 did
not always pass the validation check. The suffix "pre" should always be
detected as such, but with the random order, it was sometimes detected
as "p" suffix (see below). The following letters "re" are not a valid
suffix_no (the number expected to follow the suffix) and so it failed.

suffixes = {
    "pre": ["pre", ...],
    "post": ["p". ...]
}
This commit is contained in:
Oliver Smith 2018-12-31 07:46:47 +01:00
parent 101a396c90
commit 7f956e2f72
1 changed files with 6 additions and 4 deletions

View File

@ -16,6 +16,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
import collections
"""
In order to stay as compatible to Alpine's apk as possible, this code
@ -122,10 +123,11 @@ def parse_suffix(rest):
C equivalent: get_token(), case TOKEN_SUFFIX
"""
suffixes = {
"pre": ["alpha", "beta", "pre", "rc"],
"post": ["cvs", "svn", "git", "hg", "p"]
}
suffixes = collections.OrderedDict([
("pre", ["alpha", "beta", "pre", "rc"]),
("post", ["cvs", "svn", "git", "hg", "p"]),
])
for name, suffixes in suffixes.items():
for i, suffix in enumerate(suffixes):