summaryrefslogtreecommitdiffstats
path: root/contrib/python
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-08-04 08:18:33 +0300
committerrobot-piglet <[email protected]>2025-08-04 08:32:58 +0300
commit093752a2164d4bbe855bc009b02fde83f567a510 (patch)
tree27d7c62ab7c06935b9aba3c932ee5c52859bfdf4 /contrib/python
parentff3a97061dfac561c329c86b3022e304fa50b7aa (diff)
Intermediate changes
commit_hash:535975d5ee0c3311ef82ff8f5b03e89402f58afa
Diffstat (limited to 'contrib/python')
-rw-r--r--contrib/python/pg8000/.dist-info/METADATA7
-rw-r--r--contrib/python/pg8000/README.md5
-rw-r--r--contrib/python/pg8000/pg8000/converters.py145
-rw-r--r--contrib/python/pg8000/pg8000/core.py19
-rw-r--r--contrib/python/pg8000/ya.make2
5 files changed, 107 insertions, 71 deletions
diff --git a/contrib/python/pg8000/.dist-info/METADATA b/contrib/python/pg8000/.dist-info/METADATA
index b0979f46fc9..b8e7e656413 100644
--- a/contrib/python/pg8000/.dist-info/METADATA
+++ b/contrib/python/pg8000/.dist-info/METADATA
@@ -1,6 +1,6 @@
Metadata-Version: 2.4
Name: pg8000
-Version: 1.31.3
+Version: 1.31.4
Summary: PostgreSQL interface library
Project-URL: Homepage, https://github.com/tlocke/pg8000
Author: The Contributors
@@ -2137,6 +2137,11 @@ twine upload dist/*
## Release Notes
+### Version 1.31.4, 2025-07-20
+
+- Various speed optimisations.
+
+
### Version 1.31.3, 2025-07-19
- Simplify the `indentifier()` function by always quoting.
diff --git a/contrib/python/pg8000/README.md b/contrib/python/pg8000/README.md
index a7650de1fba..d351b68c4ea 100644
--- a/contrib/python/pg8000/README.md
+++ b/contrib/python/pg8000/README.md
@@ -2107,6 +2107,11 @@ twine upload dist/*
## Release Notes
+### Version 1.31.4, 2025-07-20
+
+- Various speed optimisations.
+
+
### Version 1.31.3, 2025-07-19
- Simplify the `indentifier()` function by always quoting.
diff --git a/contrib/python/pg8000/pg8000/converters.py b/contrib/python/pg8000/pg8000/converters.py
index 3587943bbd4..9a3c0937599 100644
--- a/contrib/python/pg8000/pg8000/converters.py
+++ b/contrib/python/pg8000/pg8000/converters.py
@@ -7,6 +7,7 @@ from datetime import (
)
from decimal import Decimal
from enum import Enum
+from functools import singledispatch
from ipaddress import (
IPv4Address,
IPv4Network,
@@ -468,64 +469,60 @@ def array_string_escape(v):
return val
-def array_out(ar):
- result = []
- for v in ar:
- if isinstance(v, list):
- val = array_out(v)
+@singledispatch
+def array_out(val):
+ return make_param(PY_TYPES, val)
- elif isinstance(v, tuple):
- val = f'"{composite_out(v)}"'
- elif v is None:
- val = "NULL"
+@array_out.register
+def _(val: list):
+ result = [array_out(v) for v in val]
+ return f'{{{",".join(result)}}}'
- elif isinstance(v, dict):
- val = array_string_escape(json_out(v))
- elif isinstance(v, (bytes, bytearray)):
- val = f'"\\{bytes_out(v)}"'
+@array_out.register
+def _(val: tuple):
+ return f'"{composite_out(val)}"'
- elif isinstance(v, str):
- val = array_string_escape(v)
- else:
- val = make_param(PY_TYPES, v)
+@array_out.register
+def _(val: None):
+ return "NULL"
- result.append(val)
- return f'{{{",".join(result)}}}'
+@array_out.register
+def _(val: dict):
+ return array_string_escape(json_out(val))
-def composite_out(ar):
- result = []
- for v in ar:
- if isinstance(v, list):
- val = array_out(v)
+@array_out.register(bytes)
+@array_out.register(bytearray)
+def _(val):
+ return f'"\\{bytes_out(val)}"'
- elif isinstance(v, tuple):
- val = composite_out(v)
- elif v is None:
- val = ""
+@array_out.register
+def _(val: str):
+ return array_string_escape(val)
- elif isinstance(v, dict):
- val = array_string_escape(json_out(v))
- elif isinstance(v, (bytes, bytearray)):
- val = f'"\\{bytes_out(v)}"'
+@singledispatch
+def composite_out(val):
+ return array_out(val)
- elif isinstance(v, str):
- val = array_string_escape(v)
- else:
- val = make_param(PY_TYPES, v)
-
- result.append(val)
+@composite_out.register
+def _(val: tuple):
+ result = [composite_out(v) for v in val]
return f'({",".join(result)})'
+@composite_out.register
+def _(val: None):
+ return ""
+
+
def record_in(data):
state = ParserState.Out
results = []
@@ -785,25 +782,55 @@ def identifier(sql):
return f'"{sql}"'
+@singledispatch
def literal(value):
- if value is None:
- return "NULL"
- elif isinstance(value, bool):
- return "TRUE" if value else "FALSE"
- elif isinstance(value, (int, float, Decimal)):
- return str(value)
- elif isinstance(value, (bytes, bytearray)):
- return f"X'{value.hex()}'"
- elif isinstance(value, Datetime):
- return f"'{datetime_out(value)}'"
- elif isinstance(value, Date):
- return f"'{date_out(value)}'"
- elif isinstance(value, Time):
- return f"'{time_out(value)}'"
- elif isinstance(value, Timedelta):
- return f"'{interval_out(value)}'"
- elif isinstance(value, list):
- return f"'{array_out(value)}'"
- else:
- val = str(value).replace("'", "''")
- return f"'{val}'"
+ val = str(value).replace("'", "''")
+ return f"'{val}'"
+
+
+def _(value: None):
+ return "NULL"
+
+
+def _(value: bool):
+ return "TRUE" if value else "FALSE"
+
+
+def _(value):
+ return str(value)
+
+
+def _(value):
+ return f"X'{value.hex()}'"
+
+
+def _(value: Datetime):
+ return f"'{datetime_out(value)}'"
+
+
+def _(value: Date):
+ return f"'{date_out(value)}'"
+
+
+def _(value: Time):
+ return f"'{time_out(value)}'"
+
+
+def _(value: Timedelta):
+ return f"'{interval_out(value)}'"
+
+
+def _(value: list):
+ return f"'{array_out(value)}'"
diff --git a/contrib/python/pg8000/pg8000/core.py b/contrib/python/pg8000/pg8000/core.py
index 0fa3e6bf088..f4f59f22434 100644
--- a/contrib/python/pg8000/pg8000/core.py
+++ b/contrib/python/pg8000/pg8000/core.py
@@ -147,19 +147,17 @@ def _flush(sock):
def _read(sock, size):
- got = 0
- buff = []
+ buff = bytearray()
try:
- while got < size:
- block = sock.read(size - got)
+ while len(buff) < size:
+ block = sock.read(size - len(buff))
if block == b"":
raise InterfaceError("network error")
- buff.append(block)
- got += len(block)
+ buff.extend(block)
except OSError as e:
raise InterfaceError("network error") from e
- return b"".join(buff)
+ return bytes(buff)
def _write(sock, d):
@@ -764,10 +762,11 @@ class CoreConnection:
return context
def _send_message(self, code, data):
+ buff = bytearray(code)
+ buff.extend(i_pack(len(data) + 4))
+ buff.extend(data)
try:
- _write(self._sock, code)
- _write(self._sock, i_pack(len(data) + 4))
- _write(self._sock, data)
+ _write(self._sock, bytes(buff))
except ValueError as e:
if str(e) == "write to closed file":
raise InterfaceError("connection is closed")
diff --git a/contrib/python/pg8000/ya.make b/contrib/python/pg8000/ya.make
index d8d0cb5f92e..949b64fa399 100644
--- a/contrib/python/pg8000/ya.make
+++ b/contrib/python/pg8000/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(1.31.3)
+VERSION(1.31.4)
LICENSE(BSD-3-Clause)