Skip to content

Commit 33cb09d

Browse files
committed
Refer to local binds in functions and module attributes in module bodies.
(Optimize the function a bit)
1 parent 80934b7 commit 33cb09d

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

postgresql/alock.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
"""
55
Tools for Advisory Locks
66
"""
7-
from abc import abstractmethod, abstractproperty
8-
from .python.element import Element
7+
import abc
8+
from .python import element
99

1010
__all__ = [
1111
'ALock',
1212
'ExclusiveLock',
1313
'ShareLock',
1414
]
1515

16-
class ALock(Element):
16+
class ALock(element.Element):
1717
"""
1818
Advisory Lock class for managing the acquisition and release of a sequence
1919
of PostgreSQL advisory locks.
@@ -32,13 +32,13 @@ def _e_metas(self,
3232
):
3333
yield None, headfmt(self.state, self.mode)
3434

35-
@abstractproperty
35+
@abc.abstractproperty
3636
def mode(self):
3737
"""
3838
The mode of the lock class.
3939
"""
4040

41-
@abstractproperty
41+
@abc.abstractproperty
4242
def __select_statements__(self):
4343
"""
4444
Implemented by subclasses to return the statements to try, acquire, and

postgresql/driver/pq3.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,11 +1775,17 @@ def _load_copy_chunks(self, chunks, *parameters):
17751775
def _load_tuple_chunks(self, chunks):
17761776
pte = self._raise_parameter_tuple_error
17771777
last = (element.SynchronizeMessage,)
1778+
1779+
Bind = element.Bind
1780+
Instruction = xact.Instruction
1781+
Execute = element.Execute
1782+
tuple = tuple
1783+
17781784
try:
17791785
for chunk in chunks:
17801786
bindings = [
17811787
(
1782-
element.Bind(
1788+
Bind(
17831789
b'',
17841790
self._pq_statement_id,
17851791
self._input_formats,
@@ -1788,13 +1794,13 @@ def _load_tuple_chunks(self, chunks):
17881794
),
17891795
(),
17901796
),
1791-
element.Execute(b'', 1),
1797+
Execute(b'', 1),
17921798
)
17931799
for t in chunk
17941800
]
17951801
bindings.append(last)
17961802
self.database._pq_push(
1797-
xact.Instruction(
1803+
Instruction(
17981804
chain.from_iterable(bindings),
17991805
asynchook = self.database._receive_async
18001806
),
@@ -2429,7 +2435,7 @@ def _establish(self):
24292435
# guts of connect()
24302436
self.pq = None
24312437
# if any exception occurs past this point, the connection
2432-
# will not be usable.
2438+
# object will not be usable.
24332439
timeout = self.connector.connect_timeout
24342440
sslmode = self.connector.sslmode or 'prefer'
24352441
failures = []

postgresql/pgpassfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# .pgpassfile - parse and lookup passwords in a pgpassfile
33
##
44
'Parse pgpass files and subsequently lookup a password.'
5-
from os.path import exists
5+
import os.path
66

77
def split(line, len = len):
88
line = line.strip()
@@ -54,7 +54,7 @@ def lookup_password_file(path, t):
5454
with open(path) as f:
5555
return lookup_password(parse(f), t)
5656

57-
def lookup_pgpass(d, passfile, exists = exists):
57+
def lookup_pgpass(d, passfile, exists = os.path.exists):
5858
# If the password file exists, lookup the password
5959
# using the config's criteria.
6060
if exists(passfile):

0 commit comments

Comments
 (0)