3939
4040csv .field_size_limit (10485760 ) # The default value is 128KB; upping to 10MB. See SPL-12117 for background on this issue
4141
42- if sys .platform == 'win32' :
42+ # SPL-175233 -- python3 stdout is already binary
43+ if sys .platform == 'win32' and sys .version_info <= (3 , 0 ):
4344 # Work around the fact that on Windows '\n' is mapped to '\r\n'. The typical solution is to simply open files in
4445 # binary mode, but stdout is already open, thus this hack. 'CPython' and 'PyPy' work differently. We assume that
4546 # 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):
339340 doublequote = True
340341 skipinitialspace = False
341342 lineterminator = '\r \n '
343+ if sys .version_info >= (3 , 0 ) and sys .platform == 'win32' :
344+ lineterminator = '\n '
342345 quoting = csv .QUOTE_MINIMAL
343346
344347
@@ -361,6 +364,10 @@ def read(self, ifile):
361364 name , value = None , None
362365
363366 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+
364371 if line == '\n ' :
365372 break
366373 item = line .split (':' , 1 )
@@ -658,6 +665,13 @@ class RecordWriterV1(RecordWriter):
658665
659666 def flush (self , finished = None , partial = None ):
660667
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+
661675 RecordWriter .flush (self , finished , partial ) # validates arguments and the state of this instance
662676
663677 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):
678692 write (message_level (level , level ))
679693 write ('=' )
680694 write (text )
681- write ( ' \r \n ' )
695+ writeEOL ( )
682696
683- write ( ' \r \n ' )
697+ writeEOL ( )
684698
685699 elif messages is not None :
686700
0 commit comments