FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
asyncpg/asyncpg/serverversion.py at master · MagicStack/asyncpg · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
MagicStack
/
asyncpg
Public
Notifications
You must be signed in to change notification settings
Fork
464
Star
8.1k
Code
Issues
253
Pull requests
46
Discussions
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
asyncpg
/
asyncpg
/
serverversion.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
70 lines (58 loc) · 2.08 KB
Breadcrumbs
asyncpg
/
asyncpg
/
serverversion.py
Copy path
File metadata and controls
70 lines (58 loc) · 2.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright (C) 2016-present the asyncpg authors and contributors
# <see AUTHORS file>
#
# This module is part of asyncpg and is released under
# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
from
__future__
import
annotations
import
re
import
typing
from
.
types
import
ServerVersion
version_regex
:
typing
.
Final
=
re
.
compile
(
r"(Postgre[^\s]*)?\s*"
r"(?P<major>[0-9]+)\.?"
r"((?P<minor>[0-9]+)\.?)?"
r"(?P<micro>[0-9]+)?"
r"(?P<releaselevel>[a-z]+)?"
r"(?P<serial>[0-9]+)?"
)
class
_VersionDict
(
typing
.
TypedDict
):
major
:
int
minor
:
int
|
None
micro
:
int
|
None
releaselevel
:
str
|
None
serial
:
int
|
None
def
split_server_version_string
(
version_string
:
str
)
->
ServerVersion
:
version_match
=
version_regex
.
search
(
version_string
)
if
version_match
is
None
:
raise
ValueError
(
"Unable to parse Postgres "
f'version from "
{
version_string
}
"'
)
version
:
_VersionDict
=
version_match
.
groupdict
()
# type: ignore[assignment] # noqa: E501
for
ver_key
,
ver_value
in
version
.
items
():
# Cast all possible versions parts to int
try
:
version
[
ver_key
]
=
int
(
ver_value
)
# type: ignore[literal-required, call-overload] # noqa: E501
except
(
TypeError
,
ValueError
):
pass
if
version
[
"major"
]
<
10
:
return
ServerVersion
(
version
[
"major"
],
version
.
get
(
"minor"
)
or
0
,
version
.
get
(
"micro"
)
or
0
,
version
.
get
(
"releaselevel"
)
or
"final"
,
version
.
get
(
"serial"
)
or
0
,
)
# Since PostgreSQL 10 the versioning scheme has changed.
# 10.x really means 10.0.x. While parsing 10.1
# as (10, 1) may seem less confusing, in practice most
# version checks are written as version[:2], and we
# want to keep that behaviour consistent, i.e not fail
# a major version check due to a bugfix release.
return
ServerVersion
(
version
[
"major"
],
0
,
version
.
get
(
"minor"
)
or
0
,
version
.
get
(
"releaselevel"
)
or
"final"
,
version
.
get
(
"serial"
)
or
0
,
)
Back
|
FazBrowse Home
|
New Git URL