File: PlainTextWriter.py

package info (click to toggle)
python-xml 0.8.4-10.1%2Blenny1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,972 kB
  • ctags: 10,628
  • sloc: python: 46,730; ansic: 14,354; xml: 968; makefile: 201; sh: 20
file content (53 lines) | stat: -rw-r--r-- 1,504 bytes parent folder | download | duplicates (3)
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
########################################################################
#
# File Name:            PlainTextWriter.py
#
#
"""
Implements a text output writer for XSLT processor output
WWW: http://4suite.com/4XSLT        e-mail: support@4suite.com

Copyright (c) 1999-2000 Fourthought Inc., USA.   All Rights Reserved.
See  http://4suite.com/COPYRIGHT  for license and copyright information
"""

from xml.xslt import NullWriter
from xml.dom import EMPTY_NAMESPACE
from xml.dom.ext.Printer import utf8_to_code

class PlainTextWriter(NullWriter.NullWriter):
    def __init__(self, outputParams, stream=None):
        NullWriter.NullWriter.__init__(self, outputParams, stream)
        self._mediaType = outputParams.mediaType or 'text/plain'
        self._encoding = outputParams.encoding
        
    def getMediaType(self):
        return self._mediaType
  
    def startDocument(self):
        return

    def endDocument(self):
        return
    
    def text(self, text, escapeOutput=1):
        if self._encoding:
            self._stream.write(utf8_to_code(text, self._encoding))
        else:
            # Defaults to UTF-8
            self._stream.write(text)
    
    def attribute(self, name, value, namespace=EMPTY_NAMESPACE):
        return

    def processingInstruction(self, target, data):
        return

    def comment(self, body):
        return

    def startElement(self, name, namespace=EMPTY_NAMESPACE, extraNss=None):
        return

    def endElement(self, name):
        return