Skip to content

Commit

Permalink
Properly deal with raw bibtex
Browse files Browse the repository at this point in the history
Fixes #72
  • Loading branch information
urschrei committed Mar 7, 2017
1 parent 86c7436 commit b338e44
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pyzotero/zotero.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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')
Expand All @@ -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
Expand Down

0 comments on commit b338e44

Please sign in to comment.