diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/neo4j_util.py | 67 |
1 files changed, 31 insertions, 36 deletions
diff --git a/src/server/neo4j_util.py b/src/server/neo4j_util.py index 1e158237..44ead256 100644 --- a/src/server/neo4j_util.py +++ b/src/server/neo4j_util.py @@ -226,44 +226,8 @@ def generate_random_id__uuid(): """ return str(uuid.uuid4()) -def post_neo4j(url, data): - """ - @return dict object from the neo4j json POST response - """ - ret = post(url, data) - ret_data = json.load(ret) - - # [!] do not raise exception if ret_data['errors'] is not empty - - # this allows query-sets to partially succeed - - return ret_data - -def post(url, data): - assert(isinstance(data, dict)) # make sure we're not handed json strings - - post_data_json = json.dumps(data) - - req = request.Request(url) - req.add_header('User-Agent', 'rhizi-server/0.1') - req.add_header('Accept', 'application/json; charset=UTF-8') - req.add_header('Content-Type', 'application/json') - - req.add_header('X-Stream', 'true') # enable neo4j JSON streaming - - try: - ret = request.urlopen(req, post_data_json) - except urllib_error.HTTPError as e: - raise Exception('post request failed: code: {0}, reason: {1}'.format(e.code, e.reason)) - return ret -def quote__backtick(label): - """ - quote label (possibly containing spaces) with backticks - """ - return '`' + label + '`' - - def meta_attr_list_to_meta_attr_map(e_set, meta_attr='__label_set'): """ convert a list of maps each containing a meta_attr key into a @@ -306,6 +270,37 @@ def meta_attr_list_to_meta_attr_map(e_set, meta_attr='__label_set'): return ret +def post_neo4j(url, data): + """ + @return dict object from the neo4j json POST response + """ + ret = post(url, data) + ret_data = json.load(ret) + + # [!] do not raise exception if ret_data['errors'] is not empty - + # this allows query-sets to partially succeed + + return ret_data + +def post(url, data): + assert(isinstance(data, dict)) # make sure we're not handed json strings + + post_data_json = json.dumps(data) + + req = request.Request(url) + req.add_header('User-Agent', 'rhizi-server/0.1') + req.add_header('Accept', 'application/json; charset=UTF-8') + req.add_header('Content-Type', 'application/json') + + req.add_header('X-Stream', 'true') # enable neo4j JSON streaming + + try: + ret = request.urlopen(req, post_data_json) + except urllib_error.HTTPError as e: + raise Exception('post request failed: code: {0}, reason: {1}'.format(e.code, e.reason)) + + return ret + def validate_label(label): assert len(label) > 0 and (label[0].isupper() or label[0] == '_'), 'malformed label: ' + label pass |
