Exemplo n.º 1
0
def parse_attribute(str):
    open = find(str, '{')
    if open>=0:
        close = find(str, '}', open) 
        if close>=0:
            nl = NodeList()
            nl.add(TextNode(encode_attribute_value(str[0:open])))

            val = str[open+1:close]
            code = __builtin__.compile(val, val, "eval")
            
            nl.add(EncodedEvalNode(code, encode_attribute_value))
            nl.add(parse_attribute(str[close+1:]))
            return nl
                   
    return TextNode(encode_attribute_value(str))
Exemplo n.º 2
0
def run():
    passed, info = (1, '')

    url = "http://test.com:8000/foo#bar"
    expected = "http%3a//test.com%3a8000/foo%23bar"
    # with one arg passed
    if encode_URI(url)!=expected:
        passed, info = (0, info + 'encode_URI failed -- %s!=%s\n' % (encode_URI(url, safe='/'), expected))
    # with one two args passed        
    if encode_URI(url, safe='/')!=expected:
        passed, info = (0, info + 'encode_URI failed -- %s!=%s\n' % (encode_URI(url, safe='/'), expected))

    val = """&"<'"""
    expected = """&amp;&quot;&lt;'"""
    if encode_attribute_value(val)!=expected:
        passed, info = (0, info + 'encode_attribute_value failed -- %s!=%s\n' % (encode_attribute_value(val), expected))        

    val = """&<"""
    expected = """&amp;&lt;"""
    if encode_character_data(val)!=expected:
        passed, info = (0, info + 'encode_attribute_value failed -- %s!=%s\n' % (encode_character_data(val), expected))     
    
    return (passed, info)
Exemplo n.º 3
0
    def property(self, predicate, object, literal_object=0):
        (namespace, localName) = split_property(predicate)   
        prefix = self.namespaces[namespace]

        # TODO: Is this what we want to do if object is None?
        if object==None or object=="":
            object = ""
            literal_object = 1
            
        if literal_object:
            self.stream.write( "    <%s:%s>%s</%s:%s>\n" % (prefix, localName, encode_character_data(object), prefix, localName) )
        else:
            if self.baseURI and object[0:len(self.baseURI)+1]==self.baseURI+"#":
                object = object[len(self.baseURI):]
            self.stream.write( "    <%s:%s rdf:resource=\"%s\"/>\n" % (prefix, localName, encode_attribute_value(object)) )            
Exemplo n.º 4
0
 def subject_start(self, subject):
     self.stream.write( "  <rdf:Description" )
     if self.baseURI and subject[0:len(self.baseURI)+1]==self.baseURI+"#":
         self.stream.write( " rdf:ID=\"%s\">\n" % subject[len(self.baseURI)+1:])       
     else:
         self.stream.write( " rdf:about=\"%s\">\n" % encode_attribute_value(subject) )