__init__.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:prophet 作者: MKLab-ITI 项目源码 文件源码
def _generate_error_graph(self, pgraph, full_msg, uri = None) :
        """
        Generate an error message into the graph. This method is usually used reacting on exceptions.

        Later versions of pyMicrodata may have more detailed error conditions on which it wishes to react. At the moment, this
        is fairly crude...
        """
        if pgraph == None :
            retval = Graph()
        else :
            retval = pgraph

        pgraph.bind( "dc","http://purl.org/dc/terms/" )
        pgraph.bind( "xsd",'http://www.w3.org/2001/XMLSchema#' )
        pgraph.bind( "ht",'http://www.w3.org/2006/http#' )
        pgraph.bind( "pyMicrodata",'http://www.w3.org/2012/pyMicrodata/vocab#' )

        bnode = BNode()
        retval.add((bnode, ns_rdf["type"], ns_micro["Error"]))
        retval.add((bnode, ns_dc["description"], Literal(full_msg)))
        retval.add((bnode, ns_dc["date"], Literal(datetime.datetime.utcnow().isoformat(),datatype=ns_xsd["dateTime"])))

        if uri != None :
            htbnode = BNode()
            retval.add( (bnode, ns_micro["context"],htbnode) )
            retval.add( (htbnode, ns_rdf["type"], ns_ht["Request"]) )
            retval.add( (htbnode, ns_ht["requestURI"], Literal(uri)) )

        if self.http_status != None and self.http_status != 200:
            htbnode = BNode()
            retval.add( (bnode, ns_micro["context"],htbnode) )
            retval.add( (htbnode, ns_rdf["type"], ns_ht["Response"]) )
            retval.add( (htbnode, ns_ht["responseCode"], URIRef("http://www.w3.org/2006/http#%s" % self.http_status)) )

        return retval
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号