Exemple #1
0
    def test_lookup(self):
        "Test the lookup of the standard printers"
        # Check the constants are supported
        self.assertTrue(lookup(XML_W) is not None)
        self.assertTrue(lookup(HTML_W) is not None)
        self.assertTrue(lookup(XHTML_W) is not None)

        # Check unknown values raise ValueError
        self.assertRaises(ValueError, lookup, 'bogus')
Exemple #2
0
    def test_lookup(self):
        "Test the lookup of the standard printers"
        # Check the constants are supported
        self.assertTrue(lookup(XML_W) is not None)
        self.assertTrue(lookup(HTML_W) is not None)
        self.assertTrue(lookup(XHTML_W) is not None)

        # Check unknown values raise ValueError
        self.assertRaises(ValueError, lookup, 'bogus')
Exemple #3
0
def convert_body(body, content_type, encoding, writer):
    if isinstance(body, str):
        if content_type is None:
            content_type = "text/plain"
        return [body], content_type, len(body)

    if isinstance(body, tree.entity):
        # XXX have Amara tell me the content type (with encoding)
        # This is trac #29
        if content_type is None:
            if "html" in writer.lower():
                content_type = "text/html"
            else:
                content_type = "application/xml"
        w = writers.lookup(writer)
        body = body.xml_encode(w, encoding)
        return [body], content_type, len(body)

    if isinstance(body, unicode):
        body = body.encode(encoding)
        if content_type is None:
            content_type = "text/plain; charset=%s" % (encoding, )
        return [body], content_type, len(body)

    # Probably one of the normal WSGI responses
    if content_type is None:
        content_type = "text/plain"
    return body, content_type, None
Exemple #4
0
    def scanXMLDocument(self, path):
        i=0
        
        self.XML_W = lookup("xml")
        self.doc = bindery.parse(path)

        self.control.SetText(open(path).read())
        self.control.EmptyUndoBuffer()
        self.control.Colourise(0, -1)

        # line numbers in the margin
        self.control.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
        self.control.SetMarginWidth(1, 25)

        #self.control.BeginTextColour((255,0,0))
        #self.control.SetValue(self.doc.xml_encode(self.XML_W))
        self.Sentences = []

        for i in range (0, self.control.GetNumberOfLines()):
            Line = self.control.GetLineText(i)
            Line.strip()

        #To remove spaces in the line
        Line = re.sub(r"\s+", "", Line, flags=re.UNICODE)

        if (Line[0]=='<') & (Line[1]=='S') & (Line[2]=='i'):
            """
            Everytime we encouter '<Si' at the beginning
            of a line, we append the Sentence Tab with
            the line number
            """
            self.Sentences.append(i)
Exemple #5
0
def convert_body(body, content_type, encoding, writer):
    if isinstance(body, str):
        if content_type is None:
            content_type = "text/plain"
        return [body], content_type, len(body)

    if isinstance(body, tree.entity):
        # XXX have Amara tell me the content type (with encoding)
        # This is trac #29
        if content_type is None:
            if "html" in writer.lower():
                content_type = "text/html"
            else:
                content_type = "application/xml"
        w = writers.lookup(writer)
        body = body.xml_encode(w, encoding)
        return [body], content_type, len(body)

    if isinstance(body, unicode):
        body = body.encode(encoding)
        if content_type is None:
            content_type = "text/plain; charset=%s" % (encoding,)
        return [body], content_type, len(body)

    # Probably one of the normal WSGI responses
    if content_type is None:
        content_type = "text/plain"
    return body, content_type, None
Exemple #6
0
 def test_xbel_2(self):  
     #BM1 = 'http://hg.4suite.org/amara/trunk/raw-file/bb6c40828b2d/demo/7days/bm1.xbel'
     #BM2 = 'http://hg.4suite.org/amara/trunk/raw-file/bb6c40828b2d/demo/7days/bm2.xbel'
     doc1 = bindery.parse(FILE('bm1.xbel'))
     doc2 = bindery.parse(FILE('bm2.xbel'))
     
     merge(doc1.xbel, doc2.xbel)
     normalize_whitespace(doc1)
     output = doc1.xml_encode(lookup("xml-indent")) + '\n'
     self.assertEqual(output, open(FILE('merged-2.xbel')).read())
Exemple #7
0
 def test_write_to_stdout(self):
     "Check that the default output is to stdout"
     xml_w = lookup('xml')
     t = tree.parse("<root>entr&#233;e</root>")
     stream = StringIO()
     try:
         sys.stdout = stream
         t.xml_write()
         self.assertEqual(
             stream.getvalue(), '<?xml version="1.0" encoding="UTF-8"?>\n'
             '<root>entr\xc3\xa9e</root>')
     finally:
         sys.stdout = sys.__stdout__
Exemple #8
0
 def test_write_to_stdout(self):
     "Check that the default output is to stdout"
     xml_w = lookup('xml')
     t = tree.parse("<root>entr&#233;e</root>")
     stream = StringIO()
     try:
         sys.stdout = stream
         t.xml_write()
         self.assertEqual(stream.getvalue(),
                          '<?xml version="1.0" encoding="UTF-8"?>\n'
                          '<root>entr\xc3\xa9e</root>')
     finally:
         sys.stdout = sys.__stdout__
Exemple #9
0
    def parseXMLDocument(self, path):
        i=0
        
        self.XML_W = lookup("xml")
        self.doc = bindery.parse(path)

        #self.control.SetText(open(path).read())
        self.control.EmptyUndoBuffer()
        self.control.Colourise(0, -1)

        # line numbers in the margin
        self.control.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
        self.control.SetMarginWidth(1, 25)

        #self.control.BeginTextColour((255,0,0))
        self.control.SetValue(self.doc.xml_encode(self.XML_W))
        self.Sentences = []
Exemple #10
0
    def parseXMLDocument(self, path):
        i=0
        
        self.XML_W = lookup("xml")
        try:
            self.doc = bindery.parse(path)
        except amara.lib.IriError:
            self.doc = bindery.parse(path, standalone=True)
            
        #self.control.SetText(open(path).read())
        self.control.EmptyUndoBuffer()
        self.control.Colourise(0, -1)

        # line numbers in the margin
        self.control.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
        self.control.SetMarginWidth(1, 25)

        self.control.SetValue(self.doc.xml_encode(self.XML_W).decode("utf-8").replace("<S id=","\n <S id=").replace("&lt;", u"\u2039").replace("&gt;", u"\u203A"))
Exemple #11
0
    def test_encode(self):
        xml_w = lookup('xml')
        t = tree.parse("<root>entr&#233;e</root>")

        # Default is UTF-8.
        self.assert_(xml_compare(t.xml_encode(),
                    '<?xml version="1.0" encoding="UTF-8"?>\n'
                    '<root>entr\xc3\xa9e</root>'))
        self.assert_(xml_compare(t.xml_encode(XML_W),
                    '<?xml version="1.0" encoding="UTF-8"?>\n'
                    '<root>entr\xc3\xa9e</root>'))
        self.assert_(xml_compare(t.xml_encode(xml_w),
                    '<?xml version="1.0" encoding="UTF-8"?>\n'
                    '<root>entr\xc3\xa9e</root>'))

        # Try latin-1 output.
        self.assert_(xml_compare(t.xml_encode(encoding='iso-8859-1'),
                    '<?xml version="1.0" encoding="iso-8859-1"?>\n'
                    '<root>entr\xe9e</root>'))
Exemple #12
0
    def test_html(self):
        "Simple check of HTML output"
        t = tree.parse("""<?xml version='1.0'?>
<disclaimer>
  <p>The opinions represented herein represent those of the individual
  and should not be interpreted as official policy endorsed by this
  organization.</p>
</disclaimer>
""")

        
        self.assertEqual(t.xml_encode(HTML_W), """<disclaimer>
  <p>The opinions represented herein represent those of the individual
  and should not be interpreted as official policy endorsed by this
  organization.</p>
</disclaimer>""")
        html_w = lookup(HTML_W)
        self.assertEqual(t.xml_encode(html_w), """<disclaimer>
  <p>The opinions represented herein represent those of the individual
  and should not be interpreted as official policy endorsed by this
  organization.</p>
</disclaimer>""")
Exemple #13
0
    def parseXMLDocument(self, path):
        i=0
        
        self.XML_W = lookup("xml")
        try:
            self.doc = bindery.parse(path)
        except amara.lib.IriError:
            schema = "../Musica/Archive.dtd"
            self.doc = bindery.parse(path, uri=schema, validate=True)
            #xml_print(self.doc)
            
        #self.control.SetText(open(path).read())
        self.control.EmptyUndoBuffer()
        self.control.Colourise(0, -1)

        # line numbers in the margin
        self.control.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
        self.control.SetMarginWidth(1, 25)

        #self.control.BeginTextColour((255,0,0))
        self.control.SetValue(self.doc.xml_encode(self.XML_W).decode("utf-8"))
        #self.control.SetValue(unicode(open(path).read()))
        self.Sentences = []
Exemple #14
0
    def test_html(self):
        "Simple check of HTML output"
        t = tree.parse("""<?xml version='1.0'?>
<disclaimer>
  <p>The opinions represented herein represent those of the individual
  and should not be interpreted as official policy endorsed by this
  organization.</p>
</disclaimer>
""")

        self.assertEqual(
            t.xml_encode(HTML_W), """<disclaimer>
  <p>The opinions represented herein represent those of the individual
  and should not be interpreted as official policy endorsed by this
  organization.</p>
</disclaimer>""")
        html_w = lookup(HTML_W)
        self.assertEqual(
            t.xml_encode(html_w), """<disclaimer>
  <p>The opinions represented herein represent those of the individual
  and should not be interpreted as official policy endorsed by this
  organization.</p>
</disclaimer>""")
Exemple #15
0
    def scanXMLDocument(self, path):
        i=0

        self.XML_W = lookup("xml")
        self.doc = bindery.parse(path)

        #self.control.BeginTextColour((255,0,0))
        self.control.SetValue(self.doc.xml_encode(self.XML_W))
        self.Sentences = []

        for i in range (0, self.control.GetNumberOfLines()):
            Line = self.control.GetLineText(i)
            Line.strip()

            #To remove spaces in the line
            Line = re.sub(r"\s+", "", Line, flags=re.UNICODE)

            if (Line[0]=='<') & (Line[1]=='S') & (Line[2]=='i'):
                """
                Everytime we encouter '<Si' at the beginning
                of a line, we append the Sentence Tab with
                the line number
                """
                self.Sentences.append(i)
Exemple #16
0
    def test_encode(self):
        xml_w = lookup('xml')
        t = tree.parse("<root>entr&#233;e</root>")

        # Default is UTF-8.
        self.assert_(
            xml_compare(
                t.xml_encode(), '<?xml version="1.0" encoding="UTF-8"?>\n'
                '<root>entr\xc3\xa9e</root>'))
        self.assert_(
            xml_compare(
                t.xml_encode(XML_W), '<?xml version="1.0" encoding="UTF-8"?>\n'
                '<root>entr\xc3\xa9e</root>'))
        self.assert_(
            xml_compare(
                t.xml_encode(xml_w), '<?xml version="1.0" encoding="UTF-8"?>\n'
                '<root>entr\xc3\xa9e</root>'))

        # Try latin-1 output.
        self.assert_(
            xml_compare(
                t.xml_encode(encoding='iso-8859-1'),
                '<?xml version="1.0" encoding="iso-8859-1"?>\n'
                '<root>entr\xe9e</root>'))
Exemple #17
0
 def test_register(self):
     "Check that register() works"
     self.assertRaises(ValueError, lookup, "new-printer")
     register('new-printer', object)
     self.assertTrue(lookup('new-printer') is not None)
Exemple #18
0
 def test_register(self):
     "Check that register() works"
     self.assertRaises(ValueError, lookup, "new-printer")
     register('new-printer', object)
     self.assertTrue(lookup('new-printer') is not None)