Changeset 156 for table_parser


Ignore:
Timestamp:
21/11/10 01:21:34 (18 months ago)
Author:
nigel.sim
Message:

fixed indentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • table_parser/table_parser.py

    r155 r156  
    3232    def append(self,item): 
    3333        if self.data != None: 
    34         print "Overwriting %s"%self.data 
     34            print "Overwriting %s"%self.data 
    3535        self.data = item 
    3636 
     
    4242    def __init__(self, parser=None): 
    4343        """ 
    44     The parser is a method which will be passed the doc at the end 
    45     of the parsing. Useful if TableParser is within an inner loop and 
    46     you want to automatically process the document. If it is omitted then 
    47     it will do nothing 
    48     """ 
     44        The parser is a method which will be passed the doc at the end 
     45        of the parsing. Useful if TableParser is within an inner loop and 
     46        you want to automatically process the document. If it is omitted then 
     47        it will do nothing 
     48        """ 
    4949        self._tag = None 
    50     self._buf = None 
    51     self._attrs = None 
    52     self.doc = None # Where the document will be stored 
    53     self._stack = None 
    54     self._parser = parser 
    55     self.reset() 
     50        self._buf = None 
     51        self._attrs = None 
     52        self.doc = None # Where the document will be stored 
     53        self._stack = None 
     54        self._parser = parser 
     55        self.reset() 
    5656        return 
    5757 
    5858    def reset(self): 
    5959        HTMLParser.reset(self) 
    60     self.doc = [] 
    61     self._stack = [self.doc] 
    62     self._buf = '' 
     60        self.doc = [] 
     61        self._stack = [self.doc] 
     62        self._buf = '' 
    6363 
    6464    def close(self): 
    6565        HTMLParser.close(self) 
    66     if self._parser != None: 
    67         self._parser(self.doc) 
     66        if self._parser != None: 
     67            self._parser(self.doc) 
    6868 
    6969    def handle_starttag(self, tag, attrs): 
    7070        self._tag = tag 
    71     self._attrs = attrs 
    72     if lower(tag) == 'table': 
    73         self._buf = '' 
     71        self._attrs = attrs 
     72        if lower(tag) == 'table': 
     73            self._buf = '' 
    7474            self._stack.append(Table()) 
    75     elif lower(tag) == 'tr': 
    76         self._buf = '' 
     75        elif lower(tag) == 'tr': 
     76            self._buf = '' 
    7777            self._stack.append(Row()) 
    78     elif lower(tag) == 'td': 
    79         self._buf = '' 
     78        elif lower(tag) == 'td': 
     79            self._buf = '' 
    8080            self._stack.append(Cell()) 
    8181 
     
    8383 
    8484    def handle_endtag(self, tag): 
    85     if lower(tag) == 'table': 
    86         t = None 
    87         while not isinstance(t, Table): 
     85        if lower(tag) == 'table': 
     86            t = None 
     87            while not isinstance(t, Table): 
    8888                t = self._stack.pop() 
    89         r = top(self._stack) 
     89            r = top(self._stack) 
    9090            r.append(t) 
    9191 
    92     elif lower(tag) == 'tr': 
    93         t = None 
    94         while not isinstance(t, Row): 
     92        elif lower(tag) == 'tr': 
     93            t = None 
     94            while not isinstance(t, Row): 
    9595                t = self._stack.pop() 
    96         r = top(self._stack) 
     96            r = top(self._stack) 
    9797            r.append(t) 
    9898 
    99     elif lower(tag) == 'td': 
    100         c = None 
    101         while not isinstance(c, Cell): 
     99        elif lower(tag) == 'td': 
     100            c = None 
     101            while not isinstance(c, Cell): 
    102102                c = self._stack.pop() 
    103         t = top(self._stack) 
    104         if isinstance(t, Row): 
    105             # We can not currently have text and other table elements in the same cell. 
    106         # Table elements get precedence 
    107             if c.data == None: 
     103            t = top(self._stack) 
     104            if isinstance(t, Row): 
     105                # We can not currently have text and other table elements in the same cell. 
     106                # Table elements get precedence 
     107                if c.data == None: 
    108108                    t.append(self._buf) 
    109         else: 
    110             t.append(c.data) 
    111         else: 
    112             print "Cell not in a row, rather in a %s"%t 
     109                else: 
     110                    t.append(c.data) 
     111            else: 
     112                print "Cell not in a row, rather in a %s"%t 
    113113        self._tag = None 
    114114        #print "Encountered the end of a %s tag" % tag 
Note: See TracChangeset for help on using the changeset viewer.