예제 #1
0
 def __str__(self):
     res=cStringIO.StringIO()
     w=res.write
     if self.tag != "TEXT":
         w("<%s" %self.tag)
         # attributes which will produce arg = "val"
         attr1 = [ k for k in self.attrs 
             if not isinstance(self.attrs[k],bool) ]
         w("".join([' %s="%s"' 
             %(k.replace('_','-'),self.attrs[k]) for k in attr1]))
         # attributes with no argument
         # if value is False, don't generate anything
         attr2 = [ k for k in self.attrs if self.attrs[k] is True ]
         w("".join([' %s' %k for k in attr2]))
         w(">")
     if self.tag in ONE_LINE:
         w('\n')
     #w(str(self.inner_HTML))                
     #@LM: unicode needs to be encoded                
     w(str(utils.getUtf8String(self.inner_HTML)))
     
     for child in self.children:
         w(str(child))
     if self.tag in CLOSING_TAGS:
         w("</%s>" %self.tag)
     if self.tag in LINE_BREAK_AFTER:
         w('\n')
     if hasattr(self,"brothers"):
         for brother in self.brothers:
             w(str(brother))
     return res.getvalue()
예제 #2
0
def query(db, query_string):

    query_string = utils.getUtf8String(query_string)

    # z1 = time.clock()
    # print "QUERY:  ",query_string
    # try:
    last_result = db.execute(query_string)
    #     except (sqlite.OperationalError)  as (strerror):
    #         print "E: pysqlite2._sqlite.OperationalError", strerror
    #         print "query: ", query_string
    #         return None
    # print "  - sql take:", (time.clock()-z1)
    return last_result
예제 #3
0
 def query(self, query):
     #import time                
     query = utils.getUtf8String(query)
     
     #z1 = time.clock()                
     #print "QUERY:  ",query
     try:
         last_result = self.db.execute(query)
     except (sqlite.OperationalError)  as (strerror):            
         print "E: pysqlite2._sqlite.OperationalError", strerror
         print "query: ", query
         return None
     #except:
     #    print "E: query fatal error", sys.exc_info()[0]
     #    print "query: ", query
     #    return None
     #print "  - sql take:", (time.clock()-z1)
                     
     return last_result