当前位置: 首页>>代码示例>>Python>>正文


Python Configuration.get_value方法代码示例

本文整理汇总了Python中configuration.Configuration.get_value方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get_value方法的具体用法?Python Configuration.get_value怎么用?Python Configuration.get_value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在configuration.Configuration的用法示例。


在下文中一共展示了Configuration.get_value方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: url_handler

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import get_value [as 别名]
def url_handler(ref):
    uri = None
    prefix = None
    conf = Configuration()
    datasetBase = conf.get_value("datasetBase")
    webBase = conf.get_value("webBase")
    webResourcePrefix = conf.get_value("webResourcePrefix")

    if (len(webResourcePrefix) == 0):
        splitted = ref.split("/")
        prefix = splitted[0]
        if (prefix in get_supported_prefixes()):
            uri = "%s%s" % (datasetBase, ref[len(prefix)+1:])
            return uri, prefix
        else:
            prefix = None
            uri = datasetBase + ref
            return uri, prefix        
    else:
        if (ref.startswith(webResourcePrefix)):
            prefix = None
            uri = datasetBase + ref
            return uri, prefix
        else:
            splitted = ref.split("/")
            prefix = splitted[0]
            if (prefix in get_supported_prefixes()):
                uri = datasetBase + ref.replace(prefix+"/", conf.get_value("webResourcePrefix"))
                return uri, prefix
            else:
                raise ValueError("Unsupportet type '%s'" % splitted[0])
开发者ID:kiivihal,项目名称:djubby,代码行数:33,代码来源:http.py

示例2: get_document_url

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import get_value [as 别名]
def get_document_url(uri, prefix, conf=None):
    if (conf == None):
        conf = Configuration()
    webResourcePrefix = conf.get_value("webResourcePrefix")
    datasetBase = conf.get_value("datasetBase")
    webBase = conf.get_value("webBase")
    if (len(webResourcePrefix) == 0):
        return "%s%s/%s" % (webBase, prefix, uri[len(datasetBase):])
    else:
        return uri.replace(datasetBase, webBase).replace(webResourcePrefix, "%s/" % prefix)
开发者ID:kiivihal,项目名称:djubby,代码行数:12,代码来源:http.py

示例3: quote

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import get_value [as 别名]
def quote(uri):
    uri = uri2str(uri)
    #return urllib.quote(uri)
    conf = Configuration()
    fixUnescapedCharacters = conf.get_value("fixUnescapedCharacters")
    for c in fixUnescapedCharacters:
        uri = uri.replace(c, urllib.quote(c))
    return uri
开发者ID:kiivihal,项目名称:djubby,代码行数:10,代码来源:uri.py

示例4: dispatcher

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import get_value [as 别名]
def dispatcher(request, ref=None):
    logging.debug("Dispatching request on '%s'..." % ref)
    conf = Configuration()
    if (ref == None or len(ref) == 0):
        index = conf.get_value("indexResource")
        index = index.replace(conf.get_value("datasetBase"), conf.get_value("webBase"))
        logging.debug("Redirecting to the index resource...")
        return HttpResponseRedirect(index)
    else:
        try:
            uri, prefix = url_handler(ref)
            resource = Resource(uri)
        except ValueError, ve:
            logging.error("Error processing request for '%s': %s" % (ref, str(ve)))
            raise Http404(ve)
        except URLError, ue:
            logging.error("Error retrieving data for '%s': %s" % (ref, str(ue)))
            raise Http404(ue)
开发者ID:kiivihal,项目名称:djubby,代码行数:20,代码来源:dispatcher.py

示例5: __init__

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import get_value [as 别名]
class Resource:

    queries = {
                "ask"      : "ASK { GRAPH <%s> { <%s> ?p ?o } }",
                "describe" : "DESCRIBE <%s> FROM <%s>"
              }

    def __init__(self, uri):
        logging.debug("Trying to build resource with URI <%s>..." % uri)
        self.uri = uri2str(uri)
        self.conf = Configuration()
        self.graph = self.conf.graph
        self.endpoint = self.conf.endpoint
        if (self.__ask__()):
            logging.info("Successfully found the resource with URI <%s> on this dataset" % self.uri)
        else:
            #FIXME: patch to support incosistencies on the URIs
            cleanuri = self.uri
            self.uri = quote(self.uri)
            logging.debug("Not found on the first try, trying the encoded URI  <%s>..." % self.uri)
            if (self.__ask__()):
                logging.info("Successfully found the resource with URI <%s> on this dataset" % self.uri)
            else:
                raise ValueError("Resource with URI <%s> not found on this dataset" % self.uri)            

    def get_triples(self):
        sparql = SPARQLWrapper(self.endpoint)
        sparql.setQuery(self.queries["describe"] % (self.uri, self.graph))
        g = sparql.query().convert()
        logging.debug("Returning %d triples describing resource <%s>" % (len(g), self.uri))
        #FIXME: enrich with metadata
        for prefix, namespace in self.conf.data.namespaces():
            g.bind(prefix, namespace) 
        return g

    def get_uri(self):
        return uri

    def get_data_url(self):
        return get_document_url(self.uri, "data")

    def get_page_url(self):
        return get_document_url(self.uri, "page")

    def get_data(self):
        return get_data_xml()

    def get_data_xml(self):
        g = self.get_triples()
        return g.serialize(format="pretty-xml")

    def get_data_n3(self):
        g = self.get_triples()
        return g.serialize(format="n3")

    def get_page(self):
        return get_page_html()

    def get_page_html(self):
        g = self.get_triples()
        tpl = Template(self.__read_template__())

        data = {}
        data["uri"] = URI(self.uri)
        lang = self.conf.get_value("defaultLanguage")
        data["lang"] = lang
        label = rdf.get_value(g, self.uri, ns.rdfs["label"], lang)
        if (len(label)>0):
            data["label"] = label
        else:
            data["label"] = self.uri
        datasetBase = self.conf.get_value("datasetBase")
        webBase = self.conf.get_value("webBase")
        data["data"]  = self.get_data_url()
        data["project"] = self.conf.get_value("projectName")
        data["homelink"] = self.conf.get_value("projectHomepage")
        data["endpoint"] = self.conf.get_value("sparqlEndpoint")
        depiction = rdf.get_value(g, self.uri, ns.foaf["depiction"])
        if (len(depiction)>0):
            data["depiction"] = depiction

        data["rows"] = self.__get_rows__(g)

        ctx = Context(data)
        return tpl.render(ctx)

    def __ask__(self):
        sparql = SPARQLWrapper(self.endpoint)
        query = self.queries["ask"] % (self.graph, self.uri)
        sparql.setQuery(query)
        sparql.setReturnFormat(JSON)
        results = sparql.query().convert()
        if (results.has_key("boolean")):
            # expected answer according SPARQL Protocol
            if (results["boolean"]):
                return True
        elif (results.has_key("results") and results["results"].has_key("bindings") and len(results["results"]["bindings"])>0):
            # I don't know why, but virtuoso sometimes uses __ask_retval
            # http://docs.openlinksw.com/virtuoso/rdfsparql.html
            if (bool(results["results"]["bindings"][0]["__ask_retval"]["value"])):
#.........这里部分代码省略.........
开发者ID:kiivihal,项目名称:djubby,代码行数:103,代码来源:resource.py

示例6: uri2url

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import get_value [as 别名]
def uri2url(uri):
    conf = Configuration()
    datasetBase = conf.get_value("datasetBase")
    webBase = conf.get_value("webBase")
    return uri.replace(datasetBase, webBase)
开发者ID:kiivihal,项目名称:djubby,代码行数:7,代码来源:uri.py


注:本文中的configuration.Configuration.get_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。