File tree Expand file tree Collapse file tree 1 file changed +18
-10
lines changed
Expand file tree Collapse file tree 1 file changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -666,22 +666,30 @@ def __openstmt(self):
666666 if accessMode == "r+" :
667667 # By checking the 'newlines' attribute the appropriate adjustment for
668668 # the file being opened can be determined.
669+
670+ try :
671+ # newline attribute is only set after a line is read
672+ # manually identify newlines in case newlines attribute isn't supported
673+ fileline = self .__file_handles [filenum ].readline ()
674+ newlines = ""
675+ for ichar in range (len (fileline )- 1 ,- 1 ,- 1 ):
676+ if fileline [ichar ] not in ['\n ' ,'\r ' ]:
677+ break
678+ newlines = fileline [ichar :]
679+ except :
680+ newlines = None
681+
669682 if hasattr (self .__file_handles [filenum ],'newlines' ):
670- try :
671- # newline attribute is only set after a line is read
672- self .__file_handles [filenum ].readline ()
673- except :
674- pass
675683 newlines = self .__file_handles [filenum ].newlines
676- else :
677- newlines = None
678-
684+
679685 self .__file_handles [filenum ].seek (0 )
680686 filelen = 0
681- if newlines != None :
687+
688+ if newlines is not None :
682689 newlineAdj = len (newlines ) - 1
683690 else :
684- # If using version of Python that doesn't have newlines attribute
691+ # If we wern't able to determine an appropriate value and
692+ # using version of Python that doesn't have newlines attribute
685693 # use adjustment appropriate for Windows formatted files
686694 newlineAdj = 1
687695
You can’t perform that action at this time.
0 commit comments