示例#1
0
 def __init__(self, batch, job_id, uri, status_code=None, location=None, content=None):
     self.batch = batch
     self.job_id = job_id
     self.uri = URI(uri)
     self.status_code = status_code or 200
     self.location = URI(location)
     self.content = content
示例#2
0
 def apply_uri(u):
     uri_object = URI(u)
     if uri_object.scheme == "bolt":
         self.__settings.setdefault("bolt_port", 7687)
     if uri_object.scheme == "https":
         self.__settings["secure"] = True
     if uri_object.host:
         self.__settings["host"] = uri_object.host
     if uri_object.port:
         self.__settings["%s_port" % uri_object.scheme] = uri_object.port
示例#3
0
    def __init__(self, uri, metadata=None, headers=None):
        uri = URI(uri)
        self._resource = _Resource.__init__(self, uri)
        self._headers = dict(headers or {})
        self.__base = super(Resource, self)
        if metadata is None:
            self.__initial_metadata = None
        else:
            self.__initial_metadata = dict(metadata)
        self.__last_get_response = None

        uri = uri.string
        dbms_uri = uri[:uri.find("/", uri.find("//") + 2)] + "/"
        if dbms_uri == uri:
            self.__dbms = self
        else:
            from py2neo.database import DBMS
            self.__dbms = DBMS(dbms_uri)
        self.__ref = NotImplemented
示例#4
0
    def __init__(self, uri, metadata=None, headers=None):
        uri = URI(uri)
        self._resource = _Resource.__init__(self, uri)
        self._headers = dict(headers or {})
        self.__base = super(Resource, self)
        if metadata is None:
            self.__initial_metadata = None
        else:
            self.__initial_metadata = dict(metadata)
        self.__last_get_response = None

        uri = uri.string
        dbms_uri = uri[:uri.find("/", uri.find("//") + 2)] + "/"
        if dbms_uri == uri:
            self.__dbms = self
        else:
            from py2neo.database import DBMS
            self.__dbms = DBMS(dbms_uri)
        self.__ref = NotImplemented
示例#5
0
文件: core.py 项目: LiuYuQ/beifen
 def ensure_downloaded(self, edition, version):
     dist_path = os.path.join(self.home, "dist")
     try:
         os.makedirs(dist_path)
     except FileExistsError:
         pass
     filename = os.path.join(dist_path, dist_archive_name(edition, version))
     if os.path.isfile(filename):
         return filename
     try:
         return download(edition, version, dist_path)
     except NetworkAddressError:
         uri = URI(NEO4J_DIST)
         raise RuntimeError("Not able to connect to %s" % uri.host)
示例#6
0
def main():
    try:
        script, format_, args = sys.argv[0], sys.argv[1], sys.argv[2:]
    except IndexError:
        _help(sys.argv[0])
        sys.exit(1)

    uri = URI(os.getenv("NEO4J_URI", ServiceRoot.DEFAULT_URI)).resolve("/")
    service_root = ServiceRoot(uri.string)

    loader = GeoffLoader(service_root.graph)
    load = loader.load
    results = []

    try:
        while args:
            arg = args.pop(0)
            if arg.startswith("-"):
                if arg in ("-f", "--file"):
                    filename = args.pop(0)
                    with codecs.open(filename, encoding="utf-8") as f:
                        data = f.read()
                    results = load(data)
                elif arg in ("-x", "--xml"):
                    load = loader.load_xml
                else:
                    raise ValueError("Unknown option %s" % arg)
            else:
                results = load(arg)
            try:
                for result in results:
                    max_key_len = max(map(len, result.keys()))
                    for key in sorted(result):
                        reference = result.get_ref(key)
                        print("%s %s" % (key.ljust(max_key_len), reference))
            except TypeError:
                pass
    except Exception as error:
        sys.stderr.write(error.args[0])
        sys.stderr.write("\n")
        sys.exit(1)
示例#7
0
    def remove(self, key=None, value=None, entity=None):
        """ Remove any entries from the index which match the parameters
        supplied. The allowed parameter combinations are:

        `key`, `value`, `entity`
            remove a specific entity indexed under a given key-value pair

        `key`, `value`
            remove all entities indexed under a given key-value pair

        `key`, `entity`
            remove a specific entity indexed against a given key but with
            any value

        `entity`
            remove all occurrences of a specific entity regardless of
            key and value

        """
        if key and value and entity:
            t = ResourceTemplate(self.resource.uri.string +
                                 "/{key}/{value}/{entity}")
            t.expand(key=key, value=value, entity=entity._id).delete()
        elif key and value:
            uris = [
                URI(entity.resource.metadata["indexed"])
                for entity in self.get(key, value)
            ]
            batch = LegacyWriteBatch(self.graph)
            for uri in uris:
                batch.append_delete(uri)
            batch.run()
        elif key and entity:
            t = ResourceTemplate(self.resource.uri.string + "/{key}/{entity}")
            t.expand(key=key, entity=entity._id).delete()
        elif entity:
            t = ResourceTemplate(self.resource.uri.string + "/{entity}")
            t.expand(entity=entity._id).delete()
        else:
            raise TypeError("Illegal parameter combination for index removal")
示例#8
0
文件: env.py 项目: csharpie/neo4fun
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import os

from py2neo.packages.httpstream.packages.urimagic import URI


__all__ = ["NEO4J_AUTH", "NEO4J_DIST", "NEO4J_HOME", "NEO4J_URI"]


#: Auth string, stored as `user:password`.
NEO4J_AUTH = os.getenv("NEO4J_AUTH", None)

#: Base URI for downloading Neo4j distribution archives.
NEO4J_DIST = os.getenv("NEO4J_DIST", "http://dist.neo4j.org/")

#: Default path for GraphServer instances.
NEO4J_HOME = os.getenv("NEO4J_HOME", ".")

#: Default URI for ServiceRoot instances.
NEO4J_URI = URI(os.getenv("NEO4J_URI", "http://localhost:7474/"))
示例#9
0
# Copyright 2011-2014, Nigel Small
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import os

from py2neo import ServiceRoot
from py2neo.packages.httpstream.packages.urimagic import URI


__all__ = ["DIST_SCHEME", "DIST_HOST", "NEO4J_HOME", "NEO4J_URI"]


DIST_SCHEME = os.getenv("NEO4J_DIST_SCHEME", "http")
DIST_HOST = os.getenv("NEO4J_DIST_HOST", "dist.neo4j.org")

NEO4J_HOME = os.getenv("NEO4J_HOME", ".")
NEO4J_URI = URI(os.getenv("NEO4J_URI", ServiceRoot.DEFAULT_URI))
示例#10
0
def main():
    import os
    import sys
    from py2neo.core import ServiceRoot
    from py2neo.packages.httpstream.packages.urimagic import URI
    script, args = sys.argv[0], sys.argv[1:]
    if not args:
        _help(script)
        sys.exit(0)
    uri = URI(os.getenv("NEO4J_URI", ServiceRoot.DEFAULT_URI)).resolve("/")
    service_root = ServiceRoot(uri.string)
    out = sys.stdout
    output_format = None
    command_line = CypherCommandLine(service_root.graph)
    command_line.begin()
    while args:
        arg = args.pop(0)
        if arg.startswith("-"):
            if arg in ("-p", "--parameter"):
                key = args.pop(0)
                value = args.pop(0)
                command_line.set_parameter(key, value)
            elif arg in ("-f", ):
                command_line.set_parameter_filename(args.pop(0))
            elif arg in ("-h", "--human"):
                output_format = None
            elif arg in ("-j", "--json"):
                output_format = "json"
            elif arg in ("-c", "--csv"):
                output_format = "csv"
            elif arg in ("-t", "--tsv"):
                output_format = "tsv"
            else:
                raise ValueError("Unrecognised option %s" % arg)
        else:
            try:
                results = command_line.execute(arg)
            except CypherError as error:
                sys.stderr.write("%s: %s\n\n" %
                                 (error.__class__.__name__, error.args[0]))
            else:
                for result in results:
                    if output_format == "json":
                        records = [
                            compact(
                                dict(
                                    zip(result.columns, map(dehydrate,
                                                            record))))
                            for record in result
                        ]
                        out.write(
                            json.dumps(records,
                                       ensure_ascii=False,
                                       sort_keys=True,
                                       indent=2))
                        out.write("\n")
                    elif output_format in ("csv", "tsv"):
                        separator = "," if output_format == "csv" else "\t"
                        out.write(
                            separator.join(
                                json.dumps(column,
                                           separators=",:",
                                           ensure_ascii=False)
                                for column in result.columns))
                        out.write("\n")
                        for record in result:
                            out.write(
                                separator.join(
                                    json.dumps(dehydrate(value),
                                               separators=",:",
                                               ensure_ascii=False,
                                               sort_keys=True)
                                    for value in record))
                            out.write("\n")
                    else:
                        out.write(repr(result))
                    out.write("\n")
    try:
        command_line.commit()
    except CypherTransactionError as error:
        sys.stderr.write(error.args[0])
        sys.stderr.write("\n")
示例#11
0
 def apply_uri(u):
     uri_object = URI(u)
     if uri_object.user_info:
         apply_auth(uri_object.user_info)
示例#12
0
# -*- coding: utf-8 -*-

import os

from py2neo import ServiceRoot
from py2neo.packages.httpstream.packages.urimagic import URI

FACEBOOK_APP_ID = '539322962865082'
FACEBOOK_APP_SECRET = 'bb32c614be336ba032605ef00873f1ed'
NEO4J_DATABASE_URL = '%sdb/data/' % \
                     URI(os.getenv('GRAPHENEDB_URL', ServiceRoot.DEFAULT_URI))\
                         .resolve('/')