File: formatter_TextFile.py

package info (click to toggle)
python-happydoc 2.0-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,176 kB
  • ctags: 3,347
  • sloc: python: 11,321; makefile: 88; sh: 77
file content (285 lines) | stat: -rw-r--r-- 8,225 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#
# COPYRIGHT
#
#   Permission to use, copy, modify, and distribute this software and
#   its documentation for any purpose and without fee is hereby
#   granted, provided that the above copyright notice appear in all
#   copies and that both that copyright notice and this permission
#   notice appear in supporting documentation, and that the name of Doug
#   Hellmann not be used in advertising or publicity pertaining to
#   distribution of the software without specific, written prior
#   permission.
# 
# DISCLAIMER
#
#   DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
#   INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
#   NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
#   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
#   OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
#   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
#   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 


"""Formatter which produces output in plain ASCII text format.

"""

__rcs_info__ = {
    #
    #  Creation Information
    #
    'module_name':'$RCSfile: formatter_TextFile.py,v $',
    'creator':'Doug Hellmann <doug@hellfly.net>',
    'project':'HappyDoc',
    'created':'Sat, 03-Jun-2000 17:58:02 EDT',
    #
    #  Current Information
    #
    'author':'$Author: doughellmann $',
    'version':'$Revision: 1.1 $',
    'date':'$Date: 2001/10/24 21:27:35 $',
    }
try:
    __version__ = __rcs_info__['version'].split(' ')[1]
except:
    __version__ = '0.0'

#
# Import system modules
#
import string
import os
import types

#
# Import Local modules
#
import happydoclib.formatter.fileformatterbase

#
# Module
#

def entryPoint():
    "Return information about this module for the dynamic loader."
    return {
        'name':'Text',
        'factory':TextFormatter,
        }



class TextFormatter(happydoclib.formatter.fileformatterbase.FileBasedFormatter):
    """Formatter which produces plain ASCII text.

    Parameters
          
       filenamePrefix -- A prefix to append to the base names of files
                         and directories being created.  This is
                         useful for situations where the names which
                         would be automatically generated might cause
                         a name clash or conflict.
      
    """

    def writeText(self, text, output, textFormat, quote=1):
        'Output the text string to the information source.'
        if not text:
            return
        text = string.strip(text)
        if text:
            lines = string.split(text, '\n')
            for line in lines:
                line = string.strip(line)
                if line and line[0] == ' ':
                    line = line[8:]
                elif line and line[0] == '\t':
                    line = line[1:]
                self.writeRaw('\t%s\n' % line, output)
            self.writeRaw('\n', output)
        return

    def writeExceptionListForFunction(self, output, function, listHeader):
        """Write the list of exceptions raised by a function.

        Parameters

          output -- Where to write.

          function -- FunctionInfo from parseinfo module.

          listHeader -- Header for list being generated.

        """
        self.listHeader(output, listHeader)
        exception_names = function.getExceptionNames()
        exception_names.sort()
        #output_reduced_name = output.name[len(self._docset.getDocsetBaseDirectory())+1:]
        for name in exception_names:
            exception_class = self._docset.getClassInfo(name)
            if exception_class:
                ref = self.getReference(exception_class,
                                        #output_reduced_name,
                                        output.name
                                        )
            else:
                ref = self.getPythonReference( name )
            self.listItem(output, self.formatCode(ref, 'PlainText'))
        self.listFooter(output)
        return
    
    ##
    ## OUTPUT DESTINATIONS
    ##

    def getFilenameExtension(self):
        'Returns the extension to use when creating files for this formatter.'
        return 'txt'

    def getRootNodeName(self):
        "Return the name of the root node for the documentation tree."
        return 'toc.txt'
    
    ##
    ## STRUCTURED OUTPUT METHODS
    ##

    def listHeader(self, output, title=None, allowMultiColumn=0):
        if title:
            self.writeRaw('\n-- %s --\n\n' % title, output)
        #else:
        #    self.writeRaw('\n-- ** --\n\n', output)
        return

    def listItem(self, output, text):
        self.writeRaw('\t* %s\n' % text, output)
        return

    def listHeader(self, output, title=None, allowMultiColumn=1):
        if title:
            self.writeRaw('==> %s <==\n' % title, output)
        return

    def listFooter(self, output):
        self.writeRaw('\n', output)
        return

    def descriptiveListHeader(self, output, title):
        self.listHeader(output, title)
        return

    def descriptiveListItem(self, output, item, description, descriptionFormat):
        self.writeRaw('\t%s : %s\n\n' % (item, string.strip(description)), output)
        return

    def descriptiveListFooter(self, output):
        self.listFooter(output)
        return

    def sectionHeader(self, output, title):
        self.writeRaw('\n** %s **\n\n' % title, output)
        return

    def sectionFooter(self, output):
        self.writeRaw('\n', output)
        return

    def itemHeader(self, output, infoObject):
        title = infoObject.getName()
        self.writeRaw('\n== %s ==\n\n' % title, output)
        return

    def itemFooter(self, output):
        self.writeRaw('\n', output)
        return

    def dividingLine(self, output, fill='-', span=80):
        '''Output a sectional dividing line.

        Parameters:

            output -- destination for written output

            fill="-" -- character to use to draw the line

            span=80 -- width of line to draw
            
        '''
        span = span / len(fill)
        self.writeRaw(fill * span, output)
        self.writeRaw('\n\n', output)
        return
    
    def pushSectionLevel(self, output):
        pass

    def popSectionLevel(self, output):
        pass

    def getPythonReference(self, moduleName):
        if moduleName in self.sys_modules:
            return moduleName + ' (standard module)'
            #return 'http://www.python.org/doc/current/lib/module-%(moduleName)s.html' % locals()
        else:
            return moduleName
    
    def getReference(self, infoSource, relativeSource, name=None):
        #
        # Figure out the name of the infoSource
        #
        if not name:
            if type(infoSource) == types.FileType:
                name = happydoclib.path.basename(infoSource.name)
            elif type(infoSource) == types.StringType:
                name = happydoclib.path.basename(infoSource)
            else:
                name = infoSource.getName()
            
        info = {
            'name':name,
            'link':self.getOutputNameForObject(infoSource),
            }
        ref = '%(name)s (see %(link)s)' % info
        return ref

    def getLocalReference(self, infoSource):
        info = {
            'name':infoSource.getName(),
            }
        ref = '%(name)s (see %(name)s)' % info
        return ref

    def getInternalReference(self, infoSource):
        info = {
            'name':infoSource.getName(),
            }
        ref = '%(name)s (see %(name)s)' % info
        return ref

    def getNamedReference(self, infoSource, name, relativeSource):
        info = {
            'name':infoSource.getName(),
            'target':name,
            }
        ref = '%(target)s (see %(target)s in %(name)s)' % info
        return ref
        

    def indent(self, output):
        return

    def dedent(self, output):
        return
    
    
    def formatCode(self, text, textFormat):
        return text

    def formatKeyword(self, text):
        return text
    
    def comment(self, text, output):
        return