Show
Ignore:
Timestamp:
11/21/07 21:27:40 (17 years ago)
Author:
jerome
Message:

Improved plain text detection.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pkpgpdls/plain.py

    r493 r494  
    3535        """Returns True if data is plain text, else False. 
    3636         
    37            It's hard to detect a plain text file, so we just 
    38            read the first line, and if it doesn't end in CR or LF 
    39            we consider it's not plain text. 
    40             
    41            TODO : use first and last block's content instead of readline(). 
     37           It's hard to detect a plain text file, so we just try to 
     38           extract lines from the first block (sufficiently large). 
     39           If it's impossible to find one we consider it's not plain text. 
    4240        """    
    43         line = self.infile.readline() 
    44         self.infile.seek(0) 
    45         if line.endswith("\n") or line.endswith("\r") : 
     41        lines = firstblock.split("\r\n") 
     42        if len(lines) == 1 : 
     43            lines = lines[0].split("\r") 
     44            if len(lines) == 1 : 
     45                lines = lines[0].split("\n") 
     46        if len(lines) > 1 : 
    4647            self.logdebug("DEBUG: Input file seems to be in the plain text format.") 
    4748            return True