(version_string: str)
| 30 | |
| 31 | |
| 32 | def split_server_version_string(version_string: str) -> ServerVersion: |
| 33 | version_match = version_regex.search(version_string) |
| 34 | |
| 35 | if version_match is None: |
| 36 | raise ValueError( |
| 37 | "Unable to parse Postgres " |
| 38 | f'version from "{version_string}"' |
| 39 | ) |
| 40 | |
| 41 | version: _VersionDict = version_match.groupdict() # type: ignore[assignment] # noqa: E501 |
| 42 | for ver_key, ver_value in version.items(): |
| 43 | # Cast all possible versions parts to int |
| 44 | try: |
| 45 | version[ver_key] = int(ver_value) # type: ignore[literal-required, call-overload] # noqa: E501 |
| 46 | except (TypeError, ValueError): |
| 47 | pass |
| 48 | |
| 49 | if version["major"] < 10: |
| 50 | return ServerVersion( |
| 51 | version["major"], |
| 52 | version.get("minor") or 0, |
| 53 | version.get("micro") or 0, |
| 54 | version.get("releaselevel") or "final", |
| 55 | version.get("serial") or 0, |
| 56 | ) |
| 57 | |
| 58 | # Since PostgreSQL 10 the versioning scheme has changed. |
| 59 | # 10.x really means 10.0.x. While parsing 10.1 |
| 60 | # as (10, 1) may seem less confusing, in practice most |
| 61 | # version checks are written as version[:2], and we |
| 62 | # want to keep that behaviour consistent, i.e not fail |
| 63 | # a major version check due to a bugfix release. |
| 64 | return ServerVersion( |
| 65 | version["major"], |
| 66 | 0, |
| 67 | version.get("minor") or 0, |
| 68 | version.get("releaselevel") or "final", |
| 69 | version.get("serial") or 0, |
| 70 | ) |
searching dependent graphs…