|
62 | 62 | ) |
63 | 63 |
|
64 | 64 |
|
| 65 | +def verify_attribute(attribute): |
| 66 | + if isinstance(attribute, string_types) and attribute.isdigit(): |
| 67 | + return int(attribute) |
| 68 | + |
| 69 | + return attribute |
| 70 | + |
| 71 | + |
65 | 72 | def parse_version(major=None, minor=None, patch=None, patch_minor=None): |
66 | 73 | # Returns version number tuple, attributes will be integer if they're numbers |
67 | | - if major is not None and isinstance(major, string_types): |
68 | | - major = int(major) if major.isdigit() else major |
69 | | - if minor is not None and isinstance(minor, string_types): |
70 | | - minor = int(minor) if minor.isdigit() else minor |
71 | | - if patch is not None and isinstance(patch, string_types): |
72 | | - patch = int(patch) if patch.isdigit() else patch |
73 | | - if patch_minor is not None and isinstance(patch_minor, string_types): |
74 | | - patch_minor = int(patch_minor) if patch_minor.isdigit() else patch_minor |
75 | | - if patch_minor: |
76 | | - return (major, minor, patch, patch_minor) |
77 | | - elif patch: |
78 | | - return (major, minor, patch) |
79 | | - elif minor: |
80 | | - return (major, minor) |
81 | | - elif major: |
82 | | - return (major,) |
83 | | - else: |
84 | | - return tuple() |
| 74 | + major = verify_attribute(major) |
| 75 | + minor = verify_attribute(minor) |
| 76 | + patch = verify_attribute(patch) |
| 77 | + patch_minor = verify_attribute(patch_minor) |
| 78 | + |
| 79 | + return filter(None, (major, minor, patch, patch_minor)) |
85 | 80 |
|
86 | 81 |
|
87 | 82 | Browser = namedtuple('Browser', ['family', 'version', 'version_string']) |
|
0 commit comments