1616from .protocol .element3 import CopyData , CopyDone , Complete , cat_messages
1717from .protocol .xact3 import Complete as xactComplete
1818
19- #: 100KB buffer for COPY messages by default.
20- default_buffer_size = 1024 * 100
19+ #: 10KB buffer for COPY messages by default.
20+ default_buffer_size = 1024 * 10
2121
2222class Fault (Exception ):
2323 """
@@ -33,28 +33,26 @@ def __init__(self, manager, faults):
3333 self .faults = faults
3434
3535 def __str__ (self ):
36- return "{0} faults occurred" .format (len (self .receivers ))
36+ return "{0} faults occurred" .format (len (self .faults ))
3737
3838class CopyFail (Exception ):
3939 """
40- Exception thrown by the CopyManager when the COPY failed.
40+ Exception thrown by the CopyManager when the COPY operation failed.
41+
42+ The 'manager' attribute the CopyManager that raised the CopyFail.
43+
44+ The 'reason' attribute is a string indicating why it failed.
45+
46+ The 'faults' attribute is a mapping of receivers to exceptions that were
47+ raised on exit.
4148 """
42- def __init__ (self , manager , reason , faults = None ):
49+ def __init__ (self , manager , reason = None , faults = None ):
4350 self .manager = manager
4451 self .reason = reason
4552 self .faults = faults or {}
4653
4754 def __str__ (self ):
48- return self .reason
49-
50- class NoReceivers (CopyFail ):
51- """
52- Exception thrown by the CopyManager when the COPY failed due to all the
53- receivers faulting out.
54- """
55- reason = 'no receivers remained after fault'
56- def __init__ (self , manager ):
57- self .manager = manager
55+ return self .reason or 'copy '
5856
5957# The identifier for PQv3 copy data.
6058PROTOCOL_PQv3 = "PQv3"
@@ -708,9 +706,9 @@ def __exit__(self, typ, val, tb):
708706
709707 # No receivers? It wasn't a success.
710708 if not self .receivers :
711- if typ is NoReceivers :
709+ if typ is CopyFail :
712710 raise
713- raise NoReceivers (self )
711+ raise CopyFail (self , "no receivers" )
714712
715713 exit_faults = {}
716714 for x in self .receivers :
@@ -743,7 +741,7 @@ def _service_producer(self):
743741 # Setup current data.
744742 if not self .receivers :
745743 # No receivers to take the data.
746- raise NoReceivers (self )
744+ raise CopyFail (self , "no receivers" )
747745
748746 try :
749747 nextdata = next (self .producer )
0 commit comments