From b338e44b07c9fbd55ac02f954899f8b054fe04bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Tue, 7 Mar 2017 20:37:05 +0000 Subject: [PATCH] Properly deal with raw bibtex Fixes #72 --- pyzotero/zotero.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyzotero/zotero.py b/pyzotero/zotero.py index 05b75c1..21f68f1 100644 --- a/pyzotero/zotero.py +++ b/pyzotero/zotero.py @@ -135,6 +135,7 @@ def wrapped_f(self, *args, **kwargs): # JSON by default formats = { 'application/atom+xml': 'atom', + 'application/x-bibtex': 'bibtex', 'application/json': 'json', 'text/plain': 'plain', 'application/pdf; charset=utf-8': 'pdf', @@ -159,6 +160,7 @@ def wrapped_f(self, *args, **kwargs): } # select format, or assume JSON content_type_header = self.request.headers['Content-Type'].lower() + ";" + control_chars = re.compile('\s+') fmt = formats.get( # strip "; charset=..." segment content_type_header[0:content_type_header.index(';')], 'json') @@ -174,6 +176,8 @@ def wrapped_f(self, *args, **kwargs): processor = self.processors.get(content) # process the content correctly with a custom rule return processor(parsed) + if fmt == 'bibtex': + return [re.sub(control_chars, ' ', item) for item in retrieved.text.split('\n\n')] # it's binary, so return raw content elif fmt != 'json': return retrieved.content