Show
Ignore:
Timestamp:
10/06/08 00:22:07 (16 years ago)
Author:
jerome
Message:

Removed spaces at EOL.

Files:
1 modified

Legend:

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

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3333    """A parser for QPDL (aka SPL2) documents.""" 
    3434    format = "QPDL (aka SPL2)" 
    35     mediasizes = {  
     35    mediasizes = { 
    3636                    # The first values are identical to that of PCLXL 
    3737                    0 : "Letter", 
     
    5757                    23 : "C6", 
    5858                    24 : "Folio", 
    59                  }    
    60                   
    61     mediasources = {              
     59                 } 
     60 
     61    mediasources = { 
    6262                     # Again, values are identical to that of PCLXL 
    6363                     0 : "Default", 
     
    7070                     7 : "ThirdCassette", 
    7171                   } 
    72              
    73     def isValid(self) :     
     72 
     73    def isValid(self) : 
    7474        """Returns True if data is QPDL aka SPL2, else False.""" 
    7575        if ((self.firstblock[:128].find("\033%-12345X") != -1) and \ 
     
    7777              (self.firstblock.find("LANGUAGE = QPDL") != -1))) : 
    7878            return True 
    79         else :     
     79        else : 
    8080            return False 
    81              
     81 
    8282    def beginPage(self, nextpos) : 
    8383        """Indicates the beginning of a new page, and extracts media information.""" 
    8484        self.pagecount += 1 
    85          
     85 
    8686        copies = unpack(self.unpackShort, self.minfile[nextpos+1:nextpos+3])[0] 
    8787        mediasize = ord(self.minfile[nextpos+3]) 
    8888        mediasource = ord(self.minfile[nextpos+8]) 
    8989        duplexmode = unpack(self.unpackShort, self.minfile[nextpos+10:nextpos+12])[0] 
    90          
    91         self.pages[self.pagecount] = { "copies" : copies,  
     90 
     91        self.pages[self.pagecount] = { "copies" : copies, 
    9292                                       "mediasize" : self.mediasizes.get(mediasize, str(mediasize)), 
    9393                                       "mediasource" : self.mediasources.get(mediasource, str(mediasource)), 
    9494                                       "duplex" : duplexmode, 
    95                                      }  
     95                                     } 
    9696        return 16       # Length of a page header 
    97          
    98     def endPage(self, nextpos) :     
     97 
     98    def endPage(self, nextpos) : 
    9999        """Indicates the end of a page.""" 
    100100        epcopies = unpack(self.unpackShort, self.minfile[nextpos:nextpos+2])[0] 
     
    103103            self.logdebug("ERROR: discrepancy between beginPage (%i) and endPage (%i) copies" % (bpcopies, epcopies)) 
    104104        return 2        # Length of a page footer 
    105          
     105 
    106106    def beginBand(self, nextpos) : 
    107107        """Indicates the beginning of a new band.""" 
    108108        bandlength = unpack(self.unpackLong, self.minfile[nextpos+6:nextpos+10])[0] 
    109109        return bandlength + 10 # Length of a band header - length of checksum 
    110          
     110 
    111111    def littleEndian(self) : 
    112112        """Toggles to little endianness.""" 
     
    115115        self.unpackLong = self.unpackType[4] 
    116116        return 0 
    117          
     117 
    118118    def bigEndian(self) : 
    119119        """Toggles to big endianness.""" 
     
    122122        self.unpackLong = self.unpackType[4] 
    123123        return 0 
    124      
    125     def escape(self, nextpos) :     
     124 
     125    def escape(self, nextpos) : 
    126126        """Handles the ESC code.""" 
    127127        pos = endpos = nextpos 
     
    137137                    quotes += 1 
    138138                endpos += 1 
    139                  
    140             # Store this in a per page mapping.     
     139 
     140            # Store this in a per page mapping. 
    141141            # NB : First time will be at page 0 (i.e. **before** page 1) ! 
    142142            stuff = self.escapedStuff.setdefault(self.pagecount, []) 
     
    144144            self.logdebug("Escaped datas : [%s]" % repr(minfile[pos : endpos])) 
    145145        return endpos - pos 
    146          
    147     def maybeEOF(self, nextpos) :     
     146 
     147    def maybeEOF(self, nextpos) : 
    148148        """Tries to detect the EOF marker.""" 
    149149        if self.minfile[nextpos:nextpos+9] == self.eofmarker : 
    150150            return 9 
    151         else :     
     151        else : 
    152152            return 0 
    153          
     153 
    154154    def getJobSize(self) : 
    155155        """Counts pages in a QPDL (SPL2) document. 
    156          
     156 
    157157           Algorithm by Jerome Alet. 
    158             
     158 
    159159           The documentation used for this was : 
    160           
     160 
    161161           Sp�fication Technique (documentation non officielle) 
    162162           Le Language SPL2 
     
    165165        """ 
    166166        # Initialize table of tags 
    167         self.tags = [ lambda pos : 0 ] * 256     
     167        self.tags = [ lambda pos : 0 ] * 256 
    168168        self.tags[0x00] = self.beginPage 
    169169        self.tags[0x01] = self.endPage 
     
    171171        self.tags[0x0c] = self.beginBand 
    172172        self.tags[0x1b] = self.escape # The escape code 
    173          
     173 
    174174        self.eofmarker = "\033%-12345X" 
    175          
     175 
    176176        infileno = self.infile.fileno() 
    177         self.pages = { 0 : { "copies" : 1,  
    178                              "orientation" : "Default",  
    179                              "mediatype" : "Plain",  
    180                              "mediasize" : "Default",  
    181                              "mediasource" : "Default",  
     177        self.pages = { 0 : { "copies" : 1, 
     178                             "orientation" : "Default", 
     179                             "mediatype" : "Plain", 
     180                             "mediasize" : "Default", 
     181                             "mediasource" : "Default", 
    182182                             "duplex" : None, 
    183                            }  
    184                      }       
     183                           } 
     184                     } 
    185185        self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 
    186186        self.pagecount = 0 
     
    195195                    pos += 1 
    196196                    pos += tags[tag](pos) 
    197             except IndexError : # EOF ?             
     197            except IndexError : # EOF ? 
    198198                pass 
    199199        finally : 
    200200            self.minfile.close() 
    201              
     201 
    202202        defaultduplexmode = "Simplex" 
    203203        defaultpapersize = "" 
    204         defaultpjlcopies = 1     
     204        defaultpjlcopies = 1 
    205205        oldpjlcopies = -1 
    206206        oldduplexmode = "" 
     
    208208        for pnum in range(1, self.pagecount + 1) : 
    209209            # NB : is number of copies is 0, the page won't be output 
    210             # but the formula below is still correct : we want  
     210            # but the formula below is still correct : we want 
    211211            # to decrease the total number of pages in this case. 
    212212            page = self.pages.get(pnum, self.pages.get(1, { "copies" : 1, "mediasize" : "Default", "duplex" : None })) 
     
    227227                    pjlcopies = nbqty 
    228228                else : 
    229                     if oldpjlcopies == -1 :     
     229                    if oldpjlcopies == -1 : 
    230230                        pjlcopies = defaultpjlcopies 
    231                     else :     
    232                         pjlcopies = oldpjlcopies     
    233                 if page["duplex"] :         
     231                    else : 
     232                        pjlcopies = oldpjlcopies 
     233                if page["duplex"] : 
    234234                    duplexmode = page["duplex"] 
    235                 else :     
     235                else : 
    236236                    defaultdm = pjlparser.default_variables.get("DUPLEX", "") 
    237237                    if defaultdm : 
    238238                        if defaultdm.upper() == "ON" : 
    239239                            defaultduplexmode = "Duplex" 
    240                         else :     
     240                        else : 
    241241                            defaultduplexmode = "Simplex" 
    242242                    envdm = pjlparser.environment_variables.get("DUPLEX", "") 
     
    244244                        if envdm.upper() == "ON" : 
    245245                            duplexmode = "Duplex" 
    246                         else :     
     246                        else : 
    247247                            duplexmode = "Simplex" 
    248                     else :         
     248                    else : 
    249249                        if not oldduplexmode : 
    250250                            duplexmode = defaultduplexmode 
    251                         else :     
     251                        else : 
    252252                            duplexmode = oldduplexmode 
    253253                defaultps = pjlparser.default_variables.get("PAPER", "") 
     
    257257                if envps : 
    258258                    papersize = envps 
    259                 else :     
     259                else : 
    260260                    if not oldpapersize : 
    261261                        papersize = defaultpapersize 
    262                     else :     
     262                    else : 
    263263                        papersize = oldpapersize 
    264             else :         
     264            else : 
    265265                if oldpjlcopies == -1 : 
    266266                    pjlcopies = defaultpjlcopies 
    267                 else :     
     267                else : 
    268268                    pjlcopies = oldpjlcopies 
    269269                if not oldduplexmode : 
    270270                    duplexmode = defaultduplexmode 
    271                 else :     
     271                else : 
    272272                    duplexmode = oldduplexmode 
    273                 if not oldpapersize :     
     273                if not oldpapersize : 
    274274                    papersize = defaultpapersize 
    275                 else :     
     275                else : 
    276276                    papersize = oldpapersize 
    277277                duplexmode = oldduplexmode 
     
    279279            if page["mediasize"] != "Default" : 
    280280                papersize = page["mediasize"] 
    281             if not duplexmode :     
     281            if not duplexmode : 
    282282                duplexmode = oldduplexmode or defaultduplexmode 
    283             oldpjlcopies = pjlcopies     
     283            oldpjlcopies = pjlcopies 
    284284            oldduplexmode = duplexmode 
    285285            oldpapersize = papersize 
    286286            copies = max(pjlcopies, page["copies"]) # Was : pjlcopies * page["copies"] 
    287287            self.pagecount += (copies - 1) 
    288             self.logdebug("%s*%s*%s*%s" % (copies,  
    289                                            papersize,  
    290                                            page["mediasource"],  
     288            self.logdebug("%s*%s*%s*%s" % (copies, 
     289                                           papersize, 
     290                                           page["mediasource"], 
    291291                                           duplexmode)) 
    292292        return self.pagecount