Changeset 39

Show
Ignore:
Timestamp:
Thu Jun 16 10:12:31 2005
Author:
fredrikc
Message:

Minidom bugfixes.

Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/transolution/tm/server/estreen.py

    r38 r39  
    6 6 from transolution.path_mod import path  
    7 7 port = 6315  
      8 version = 'Transolution TM server v0.1'  
    8 9  
    9 10 class TMException(Exception):pass  
     
    32 33  
    33 34     def version(self):  
    34           return 'Estreen TM server v0.01'  
      35         return version  
    34 35      
    35 36     def addTU(self,source,target):  
     
    86 87                   action='store', type='string', dest='slang',  
    87 88                   help='TM source language')  
      89     op.add_option('-t', '--tlang',default = 'sv-se',  
      90                   action='store', type='string', dest='tlang',  
      91                   help='TM target language')  
    88 92     op.add_option('-r', '--recursive',  
    89 93                   action='store_true', dest='recursive',  
     
    131 135         try:  
    132 136             key = tu.getKey(slang)  
      137             tu.getKey(tlang)  
    133 138         except IndexError,e:  
    134 139             continue  
     
    151 156     options = parseArgs()  
    152 157     slang = options.slang  
    153       tlang = 'sv-se'  
      158     tlang = options.tlang  
    153 158  
    154 159     tmidx = index.VectorIndex()  
     
    168 173  
    169 174     #Go into the main listener loop  
    170       print "TM server listening on port",port  
      175     print "TM server listening on port",options.port  
    170 175     server.serve_forever()  
    171 176  
    172 177 if __name__ == '__main__':  
    173       main()  
      178 ##    main()  
      179     tmidx = index.VectorIndex()  
      180     tmidx.nodesize = 40  
      181     tmidx.fuzz = 0  
    174 182  
    175   ##    xml1 = r'''<seg>first <bpt id="1" >xx</bpt>in tag<ept id="1">xx</ept> some more text</seg>'''  
    176   ##    xml2 = r'''<seg>first source <bpt id="1" >&lt;tag&gt;</bpt>in tag<ept id="1">&lt;/tag&gt;</ept> some more text</seg>'''  
    177   ##    xml3 = r'''<seg>first source in tag some more text</seg>'''  
    178   ##    tm = TMServer()  
    179   ##     
    180   ##    print tm.addTU(xml1,xml2)  
    181   ##    print "--------"  
    182   ##    print tm.lookup(xml3)  
      183     xml1 = r'''<seg>first <bpt id="1" >xx</bpt>in tag<ept id="1">xx</ept> some more text</seg>'''  
      184     xml2 = r'''<seg>first source <bpt id="1" >&lt;tag&gt;</bpt>in tag<ept id="1">&lt;/tag&gt;</ept> some more text</seg>'''  
      185     xml3 = r'''<seg>first source in tag some more text</seg>'''  
      186     tm = TMServer()  
      187      
      188     print tm.addTU(xml1,xml2)  
      189     print "--------"  
      190     print tm.lookup(xml3)  
  • trunk/transolution/xmlutils/dom_reader_writer.py

    r25 r39  
    32 32  
    33 33 def parseString(s,uri='urn:bogus:dummy'):  
    34       if dom_name == "4Suite Domlette" and (type(s) is unicode):  
    35           s = s.encode('utf-8')  
    36       return dom_parser.parseString(s,uri)  
      34     if dom_name == "4Suite Domlette":  
      35         if (type(s) is unicode):  
      36             s = s.encode('utf-8')  
      37         return dom_parser.parseString(s,uri)  
      38     else:  
      39         return dom_parser.parseString(s)  
    37 40  
    38 41 def toxml(node,stream=None,enc='utf-8',addheader=False):  
  • trunk/transolution/tmx/__init__.py

    r37 r39  
    3 3 from xml.dom import Node  
    4 4 from transolution.xmlutils import NodeCreator,createNodeAttr,EMPTY_NAMESPACE,dom_impl,loadXml  
      5  
      6 class TMXException(Exception):  
      7     pass  
      8 class TMXSyntaxError(TMXException):  
      9     pass  
    5 10  
    6 11 class tmxNote:  
     
    11 16         if doc.nodeName == u'note':  
    12 17             doc.normalize()  
    13               for attr in doc.attributes:  
    14                   attNS, attName = attr  
    15                   if attName == u'lang':  
    16                       self.lang = doc.getAttributeNS('xml','xml:lang')  
    17                   elif attName == u'o-encoding':  
    18                       self.oencoding = doc.getAttributeNS(EMPTY_NAMESPACE,'o-encoding')  
    19                   else:  
    20                       raise Exception, "Invalid TMX Syntax, uexpected attribute on note\n"  
      18             self.lang = doc.getAttributeNS('xml','xml:lang')  
      19             self.oencoding = doc.getAttributeNS(EMPTY_NAMESPACE,'o-encoding')  
    21 20             for str in doc.childNodes:  
    22 21                 if str.nodeType == Node.TEXT_NODE or str.nodeType == Node.CDATA_SECTION_NODE:  
    23 22                     self.data += str.data  
    24 23         else:  
    25               raise Exception, "Invalid TMX Syntax, expected note\n"  
      24             raise TMXSyntaxError("Invalid TMX Syntax, expected note\n")  
    25 24  
    26 25  
     
    34 33         if doc.nodeName == u'prop':  
    35 34             doc.normalize()  
    36               for attr in doc.attributes:  
    37                   attNS, attName = attr  
    38                   if attName == u'lang':  
    39                       self.lang = doc.getAttributeNS('xml','xml:lang')  
    40                   elif attName == u'o-encoding':  
    41                       self.oencoding = doc.getAttributeNS(EMPTY_NAMESPACE,'o-encoding')  
    42                   elif attName == u'type':  
    43                       self.type = doc.getAttributeNS(EMPTY_NAMESPACE,'type')  
    44                   else:  
    45                       raise Exception, "Invalid TMX Syntax, uexpected attribute on prop\n"  
      35             self.lang = doc.getAttributeNS('xml','xml:lang')  
      36             self.oencoding = doc.getAttributeNS(EMPTY_NAMESPACE,'o-encoding')  
      37             self.type = doc.getAttributeNS(EMPTY_NAMESPACE,'type')  
    46 38             for str in doc.childNodes:  
    47 39                 if str.nodeType == Node.TEXT_NODE or str.nodeType == Node.CDATA_SECTION_NODE:  
    48 40                     self.data += str.data  
    49 41         else:  
    50               raise Exception, "Invalid TMX Syntax, expected prop\n"  
      42             raise TMXSyntaxError("Invalid TMX Syntax, expected prop\n")  
    50 42    
    51 43 class tmxUde:  
     
    58 50             pass  
    59 51         else:  
    60               raise Exception, "Invalid TMX Syntax, expected ude\n"  
      52             raise TMXSyntaxError("Invalid TMX Syntax, expected ude\n")  
    60 52  
    61 53 class tmxMap:  
     
    69 61             pass  
    70 62         else:  
    71               raise Exception, "Invalid TMX Syntax, expected map\n"  
      63             raise TMXSyntaxError("Invalid TMX Syntax, expected map\n")  
    71 63  
    72 64 class tmxHeader:  
     
    92 84             pass  
    93 85         else:  
    94               raise Exception, "Invalid TMX Syntax, expected header\n"  
      86             raise TMXSyntaxError("Invalid TMX Syntax, expected header\n")  
    94 86  
    95 87 class tmxTu:  
     
    124 116                     self.tuvs.append(tmxTuv(child))  
    125 117                 else:  
    126                       raise Exception, "Invalid TMX Syntax, uexpected element in tu\n"  
      118                     raise TMXSyntaxError("Invalid TMX Syntax, uexpected element in tu\n")  
    126 118         else:  
    127               raise Exception, "Invalid TMX Syntax, expected tu\n"  
      119             raise TMXSyntaxError("Invalid TMX Syntax, expected tu\n")  
    127 119     def getKey(self,lang):  
    128 120         key = []  
     
    173 165                 else:  
    174 166                     raise Exception, "Invalid TMX Syntax, uexpected element in tuv\n"  
    175               for attr in doc.attributes:  
    176                   attNS, attName = attr  
    177                   if attName == u'lang':  
    178                       self.lang = doc.getAttributeNS('xml','lang')  
    179                   elif attName == u'o-encoding':  
    180                       self.oencoding = doc.getAttributeNS(EMPTY_NAMESPACE,'o-encoding')  
    181                   else:  
    182                       raise Exception, "Invalid TMX Syntax, uexpected attribute on tuv\n"  
      167                 self.lang = doc.getAttributeNS('xml','lang')  
      168                 self.oencoding = doc.getAttributeNS(EMPTY_NAMESPACE,'o-encoding')  
    183 169         else:  
    184               raise Exception, "Invalid TMX Syntax, expected tuv\n"  
      170             raise TMXSyntaxError("Invalid TMX Syntax, expected tuv\n")  
    184 170  
    185 171 class tmxSeg:  
     
    194 180                     self.data += str.data  
    195 181         else:  
    196               raise Exception, "Invalid TMX Syntax, expected seg\n"  
      182             raise TMXSyntaxError("Invalid TMX Syntax, expected seg\n")  
    196 182  
    197 183 class tmxBody:  
     
    206 192                     self.tus.append(tmxTu(child))  
    207 193         else:  
    208               raise Exception, "Invalid TMX Syntax, expected body\n"  
      194             raise TMXSyntaxError("Invalid TMX Syntax, expected body\n")  
    208 194  
    209 195 class tmxDoc:  
     
    223 209                     self.body = tmxBody(node)  
    224 210                 else:  
    225                       raise Exception, "Invalid TMX Syntax, expected body or header\n"  
      211                     raise TMXSyntaxError("Invalid TMX Syntax, expected body or header\n")  
    225 211         else:  
    226               raise Exception, "Invalid TMX Syntax, expected TMX\n"  
    227    
      212             raise TMXSyntaxError("Invalid TMX Syntax, expected TMX\n")  
    228 213  
    229 214