Commit e46e15df authored by Erik Hetzner's avatar Erik Hetzner

Merged in mcepl/zot4rst/exception_handling (pull request #1)

Exception_handling
parents c7e83c45 8cda4617
*.pyc
zot4rst.egg-info/
import docutils
import logging
logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
level=logging.DEBUG)
import random
import string
import xciterst
......@@ -52,6 +55,7 @@ def cite_role(role, rawtext, text, lineno, inliner,
"""Text role for citations."""
xciterst.check_citeproc()
logging.debug('parsing text = %s', text)
[first_cluster, second_cluster] = CiteParser().parse(text)
nodeset = []
if first_cluster is not None:
......
# -*- coding: utf-8 -*-
import docutils, docutils.parsers.rst
import json
import logging
logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
level=logging.DEBUG)
import urllib2
import zot4rst.jsonencoder
import docutils
import docutils.parsers.rst
import xciterst
import xciterst.directives
import xciterst.roles
from xciterst.util import html2rst
import zot4rst.jsonencoder
#from xciterst.util import html2rst
DEFAULT_CITATION_STYLE = "http://www.zotero.org/styles/chicago-author-date"
BIBLIOGRAPHY_REQUEST_URL = "http://localhost:23119/zotxt/items"
class ZoteroConnection(xciterst.CiteprocWrapper):
def __init__(self, style, **kwargs):
self.local_items = {}
self._in_text_style = True # XXXX should get from zotxt
self._in_text_style = True # XXXX should get from zotxt
super(ZoteroConnection, self).__init__()
@property
......@@ -24,13 +31,23 @@ class ZoteroConnection(xciterst.CiteprocWrapper):
return self._in_text_style
def citeproc_process(self, clusters):
request_json = { "styleId" : "chicago-author-date",
"citationGroups" : clusters }
data = json.dumps(request_json, indent=2,cls=zot4rst.jsonencoder.ZoteroJSONEncoder)
req = urllib2.Request("http://localhost:23119/zotxt/bibliography", data, {'Content-Type': 'application/json'})
f = urllib2.urlopen(req)
resp_json = f.read()
f.close()
logging.debug('clusters = %s', clusters)
request_json = {
"format": "bibliography",
"styleId": "chicago-author-date",
"citationGroups": clusters
}
data = json.dumps(request_json, indent=2,
cls=zot4rst.jsonencoder.ZoteroJSONEncoder)
try:
req = urllib2.Request(BIBLIOGRAPHY_REQUEST_URL,
data, {'Content-Type': 'application/json'})
f = urllib2.urlopen(req)
resp_json = f.read()
f.close()
except:
logging.warning('cannot open URL %s', BIBLIOGRAPHY_REQUEST_URL)
raise
resp = json.loads(resp_json)
return [resp['citationClusters'], resp['bibliography']]
......@@ -38,16 +55,17 @@ class ZoteroConnection(xciterst.CiteprocWrapper):
prefixed = {}
for k in items.keys():
v = items[k]
prefixed["MY-%s"%(k)] = v
v['id'] = "MY-%s"%(v['id'])
prefixed["MY-%s" % (k)] = v
v['id'] = "MY-%s" % (v['id'])
return prefixed
def load_biblio(self, path):
self.local_items = json.load(open(path))
self.methods.registerLocalItems(self.prefix_items(self.local_items));
self.methods.registerLocalItems(self.prefix_items(self.local_items))
def init(style=None):
if style is None: style = DEFAULT_CITATION_STYLE
if style is None:
style = DEFAULT_CITATION_STYLE
xciterst.cluster_tracker = xciterst.ClusterTracker()
xciterst.citeproc = ZoteroConnection(style)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment