35 | | """Returns True if data is plain text, else False. |
36 | | |
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. |
40 | | """ |
41 | | lines = self.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 : |
47 | | self.logdebug("DEBUG: Input file seems to be in the plain text format.") |
| 35 | """Returns True if data is an image format supported by PIL, else False.""" |
| 36 | try : |
| 37 | image = Image.open(self.filename) |
| 38 | except IOError : |
| 39 | return False |
| 40 | else : |
53 | | """Counts pages in a plain text document.""" |
54 | | pagesize = 66 # TODO : Does this vary wrt the default page size ? |
55 | | # TODO : /etc/papersize and /etc/paper.config |
56 | | pagecount = 0 |
57 | | linecount = 0 |
58 | | for line in self.infile : |
59 | | if line.endswith("\n") : |
60 | | linecount += 1 |
61 | | if (linecount > pagesize) : |
62 | | pagecount += 1 |
63 | | linecount = 0 |
64 | | else : |
65 | | cnt = line.count("\f") |
66 | | if cnt : |
67 | | pagecount += cnt |
68 | | linecount = 0 |
69 | | else : |
70 | | raise pdlparser.PDLParserError, "Unsupported file format. Please send the file to %s" % version.__authoremail__ |
71 | | return pagecount + 1 # NB : empty files are catched in isValid() |
| 44 | """Counts pages in an image file.""" |
| 45 | index = 0 |
| 46 | image = Image.open(self.filename) |
| 47 | try : |
| 48 | while True : |
| 49 | index += 1 |
| 50 | image.seek(index) |
| 51 | except EOFError : |
| 52 | pass |
| 53 | return index |