39
39
40
40
csv .field_size_limit (10485760 ) # The default value is 128KB; upping to 10MB. See SPL-12117 for background on this issue
41
41
42
- if sys .platform == 'win32' :
42
+ # SPL-175233 -- python3 stdout is already binary
43
+ if sys .platform == 'win32' and sys .version_info <= (3 , 0 ):
43
44
# Work around the fact that on Windows '\n' is mapped to '\r\n'. The typical solution is to simply open files in
44
45
# binary mode, but stdout is already open, thus this hack. 'CPython' and 'PyPy' work differently. We assume that
45
46
# all other Python implementations are compatible with 'CPython'. This might or might not be a valid assumption.
@@ -339,6 +340,8 @@ class CsvDialect(csv.Dialect):
339
340
doublequote = True
340
341
skipinitialspace = False
341
342
lineterminator = '\r \n '
343
+ if sys .version_info >= (3 , 0 ) and sys .platform == 'win32' :
344
+ lineterminator = '\n '
342
345
quoting = csv .QUOTE_MINIMAL
343
346
344
347
@@ -361,6 +364,10 @@ def read(self, ifile):
361
364
name , value = None , None
362
365
363
366
for line in ifile :
367
+ # SPL-175233 -- input is buffered, needs to be decoded
368
+ if sys .version_info >= (3 , 0 ):
369
+ line = line .decode ()
370
+
364
371
if line == '\n ' :
365
372
break
366
373
item = line .split (':' , 1 )
@@ -658,6 +665,13 @@ class RecordWriterV1(RecordWriter):
658
665
659
666
def flush (self , finished = None , partial = None ):
660
667
668
+ # SPL-175233
669
+ def writeEOL ():
670
+ if sys .version_info >= (3 , 0 ) and sys .platform == 'win32' :
671
+ write ('\n ' )
672
+ else :
673
+ write ('\r \n ' )
674
+
661
675
RecordWriter .flush (self , finished , partial ) # validates arguments and the state of this instance
662
676
663
677
if self ._record_count > 0 or (self ._chunk_count == 0 and 'messages' in self ._inspector ):
@@ -678,9 +692,9 @@ def flush(self, finished=None, partial=None):
678
692
write (message_level (level , level ))
679
693
write ('=' )
680
694
write (text )
681
- write ( ' \r \n ' )
695
+ writeEOL ( )
682
696
683
- write ( ' \r \n ' )
697
+ writeEOL ( )
684
698
685
699
elif messages is not None :
686
700
0 commit comments