Skip to content

Commit 31c6555

Browse files
author
James William Pye
committed
Rename .COPY(...) to .transfer(...)
1 parent 54647a2 commit 31c6555

3 files changed

Lines changed: 15 additions & 22 deletions

File tree

postgresql/copyman.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44
"""
55
Manage complex COPY operations; one-to-many COPY streaming.
66
7-
Primarily this module houses the `CopyManager` class.
8-
9-
>>> import postgresql
10-
>>> src = postgresql.open(...)
11-
>>> dst = postgresql.open(...)
12-
>>> from postgresql.copyman import COPY
13-
>>>
14-
>>> COPY(src.prepare("COPY"), dst.prepare("COPY"))
7+
Primarily this module houses the `CopyManager` class, and the `transfer`
8+
function for a high-level interface to using the `CopyManager`.
159
"""
1610
import sys
1711
from abc import abstractmethod, abstractproperty
@@ -815,17 +809,16 @@ def __next__(self):
815809
self._stats = (0, 0)
816810
return current_stats
817811

818-
def COPY(producer, *receivers, progress = None):
812+
def transfer(producer, *receivers):
813+
"""
814+
Perform a COPY operation using the given statements::
815+
816+
>>> import copyman
817+
>>> copyman.transfer(src.prepare("COPY table TO STDOUT"), dst.prepare("COPY table FROM STDIN"))
818+
"""
819819
cm = CopyManager(
820820
StatementProducer(producer),
821821
*[x if isinstance(x, Receiver) else StatementReceiver(x) for x in receivers]
822822
)
823-
try:
824-
if progress:
825-
pass
826-
else:
827-
cm.run()
828-
except Fault as e:
829-
typ, val, tb = next(iter(e.faults.values()))
830-
raise val
823+
cm.run()
831824
return (cm.producer.total_messages, cm.producer.total_bytes)

postgresql/documentation/copyman.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ be used when transferring COPY data to and from arbitrary Python
1616
interfaces.
1717

1818
Direct connection-to-connection COPY operations can be performed using the
19-
high-level `postgresql.copyman.COPY` function::
19+
high-level `postgresql.copyman.transfer` function::
2020

21-
>>> from postgresql.copyman import COPY
21+
>>> from postgresql import copyman
2222
>>> send_stmt = source.prepare("COPY (SELECT i FROM generate_series(1, 1000000) AS g(i)) TO STDOUT")
2323
>>> destination.execute("CREATE TEMP TABLE loading_table (i int8)")
2424
>>> receive_stmt = destination.prepare("COPY loading_table FROM STDIN")
25-
>>> total_rows, total_bytes = COPY(send_stmt, receive_stmt)
25+
>>> total_rows, total_bytes = copyman.transfer(send_stmt, receive_stmt)
2626

2727
However, if more control is needed, the `postgresql.copyman.CopyManager` class
2828
should be used directly.

postgresql/test/test_copyman.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def testEmptyRows(self):
360360
def testCopyOne(self):
361361
from io import BytesIO
362362
b = BytesIO()
363-
copyman.COPY(
363+
copyman.transfer(
364364
prepare('COPY (SELECT 1) TO STDOUT'),
365365
copyman.CallReceiver(b.writelines)
366366
)
@@ -371,7 +371,7 @@ def testCopyOne(self):
371371
def testCopyNone(self):
372372
from io import BytesIO
373373
b = BytesIO()
374-
copyman.COPY(
374+
copyman.transfer(
375375
prepare('COPY (SELECT 1 LIMIT 0) TO STDOUT'),
376376
copyman.CallReceiver(b.writelines)
377377
)

0 commit comments

Comments
 (0)