~ubuntu-branches/ubuntu/vivid/python-reportlab/vivid-proposed

« back to all changes in this revision

Viewing changes to src/reportlab/lib/yaml.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-01-12 02:16:21 UTC
  • mfrom: (1.2.9) (4.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20140112021621-f4mpp5qaj1dkq2yb
Tags: 2.8~20140112-1
* New upstream snapshot.
* Build python3 packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
dot endPre
38
38
- ends a preformatted object.
39
39
"""
40
 
__version__=''' $Id: yaml.py 3959 2012-09-27 14:39:39Z robin $ '''
41
 
 
 
40
__version__=''' $Id$ '''
42
41
 
43
42
import sys
44
 
import string
45
43
 
46
44
#modes:
47
45
PLAIN = 1
78
76
 
79
77
    def parseText(self, textBlock):
80
78
        "Parses the a possible multi-line text block"
81
 
        lines = string.split(textBlock, '\n')
 
79
        lines = textBlock.split('\n')
82
80
        for line in lines:
83
81
            self.readLine(line)
84
82
        self.endPara()
87
85
    def readLine(self, line):
88
86
        #this is the inner loop
89
87
        self._lineNo = self._lineNo + 1
90
 
        stripped = string.lstrip(line)
 
88
        stripped = line.lstrip()
91
89
        if len(stripped) == 0:
92
90
            if self._mode == PLAIN:
93
91
                self.endPara()
96
94
        elif line[0]=='.':
97
95
            # we have a command of some kind
98
96
            self.endPara()
99
 
            words = string.split(stripped[1:])
 
97
            words = stripped[1:].split()
100
98
            cmd, args = words[0], words[1:]
101
99
 
102
100
            #is it a parser method?
105
103
                #we have to hack the traceback
106
104
                try:
107
105
                    getattr(self,cmd)(*args)
108
 
                except TypeError, err:
 
106
                except TypeError as err:
109
107
                    sys.stderr.write("Parser method: %s(*%s) %s at line %d\n" % (cmd, args, err, self._lineNo))
110
108
                    raise
111
109
            else:
112
110
                # assume it is a paragraph style -
113
111
                # becomes the formatter's problem
114
112
                self.endPara()  #end the last one
115
 
                words = string.split(stripped, ' ', 1)
 
113
                words = stripped.split(' ', 1)
116
114
                assert len(words)==2, "Style %s but no data at line %d" % (words[0], self._lineNo)
117
115
                (styletag, data) = words
118
116
                self._style = styletag[1:]
124
122
    def endPara(self):
125
123
        #ends the current paragraph, or preformatted block
126
124
 
127
 
        text = string.join(self._buf, ' ')
 
125
        text = ' '.join(self._buf)
128
126
        if text:
129
127
            if self._mode == PREFORMATTED:
130
128
                #item 3 is list of lines
131
129
                self._results.append(('PREFORMATTED', self._style,
132
 
                                 string.join(self._buf,'\n')))
 
130
                                 '\n'.join(self._buf)))
133
131
            else:
134
132
                self._results.append(('PARAGRAPH', self._style, text))
135
133
        self._buf = []