pyzotero 1.5.28__py3-none-any.whl → 1.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '1.5.28'
16
- __version_tuple__ = version_tuple = (1, 5, 28)
15
+ __version__ = version = '1.6.1'
16
+ __version_tuple__ = version_tuple = (1, 6, 1)
pyzotero/zotero.py CHANGED
@@ -24,8 +24,16 @@ import uuid
24
24
  import zipfile
25
25
  from collections import OrderedDict
26
26
  from functools import wraps
27
- from pathlib import Path
28
- from urllib.parse import parse_qs, parse_qsl, quote, urlencode, urlparse, urlunparse
27
+ from pathlib import Path, PurePosixPath
28
+ from urllib.parse import (
29
+ parse_qs,
30
+ parse_qsl,
31
+ quote,
32
+ unquote,
33
+ urlencode,
34
+ urlparse,
35
+ urlunparse,
36
+ )
29
37
 
30
38
  import bibtexparser
31
39
  import feedparser
@@ -272,8 +280,10 @@ class Zotero:
272
280
  """Store Zotero credentials"""
273
281
  if not local:
274
282
  self.endpoint = "https://api.zotero.org"
283
+ self.local = False
275
284
  else:
276
285
  self.endpoint = "http://localhost:23119/api"
286
+ self.local = True
277
287
  if library_id and library_type:
278
288
  self.library_id = library_id
279
289
  # library_type determines whether query begins w. /users or /groups
@@ -321,6 +331,22 @@ class Zotero:
321
331
  self.backoff = False
322
332
  self.backoff_duration = 0.0
323
333
 
334
+ def _check_for_component(self, url, component):
335
+ """Check a url path query fragment for a specific query parameter"""
336
+ if parse_qs(url).get(component):
337
+ return True
338
+ return False
339
+
340
+ def _striplocal(self, url):
341
+ """We need to remve the leading "/api" substring from urls if we're running in local mode"""
342
+ if self.local:
343
+ parsed = urlparse(url)
344
+ purepath = PurePosixPath(unquote(parsed.path))
345
+ newpath = "/".join(purepath.parts[2:])
346
+ replaced = parsed._replace(path="/" + newpath)
347
+ return urlunparse(replaced)
348
+ return url
349
+
324
350
  def _set_backoff(self, duration):
325
351
  """
326
352
  Set a backoff
@@ -406,10 +432,16 @@ class Zotero:
406
432
  self.self_link = request
407
433
  # ensure that we wait if there's an active backoff
408
434
  self._check_backoff()
409
- if params:
410
- params["locale"] = self.locale
411
- if not params:
412
- params = {"locale": self.locale}
435
+ # don't set locale if the url already contains it
436
+ # we always add a locale if it's a "standalone" or first call
437
+ needs_locale = not self.links or not self._check_for_component(
438
+ self.links.get("next"), "locale"
439
+ )
440
+ if needs_locale:
441
+ if params:
442
+ params["locale"] = self.locale
443
+ else:
444
+ params = {"locale": self.locale}
413
445
  self.request = requests.get(
414
446
  url=full_url, headers=self.default_headers(), params=params
415
447
  )
@@ -845,10 +877,11 @@ class Zotero:
845
877
  @retrieve
846
878
  def follow(self):
847
879
  """Return the result of the call to the URL in the 'Next' link"""
848
- if self.links.get("next"):
849
- return self.links.get("next")
850
- else:
851
- return
880
+ if n := self.links.get("next"):
881
+ newurl = self._striplocal(n)
882
+ print(newurl)
883
+ return newurl
884
+ return
852
885
 
853
886
  def iterfollow(self):
854
887
  """Generator for self.follow()"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyzotero
3
- Version: 1.5.28
3
+ Version: 1.6.1
4
4
  Summary: Python wrapper for the Zotero API
5
5
  Author-email: Stephan Hügel <urschrei@gmail.com>
6
6
  License: # Blue Oak Model License
@@ -0,0 +1,10 @@
1
+ _version.py,sha256=edFVVa8HpVPfLqL2y6CKtViSqJREfmXxInA-HCy-134,411
2
+ pyzotero/__init__.py,sha256=5QI4Jou9L-YJAf_oN9TgRXVKgt_Unc39oADo2Ch8bLI,243
3
+ pyzotero/zotero.py,sha256=Qk3vuJxv4rbD_Q0sg_8nc8QXVAboJ9_eZWrLuJLkW_4,76313
4
+ pyzotero/zotero_errors.py,sha256=UPhAmf2K05cnoeIl2wjufWQedepg7vBKb-ShU0TdlL4,2582
5
+ pyzotero-1.6.1.dist-info/AUTHORS,sha256=ZMicxg7lRScOYbxzMPznlzMbmrFIUIHwg-NvljEMbRQ,110
6
+ pyzotero-1.6.1.dist-info/LICENSE.md,sha256=bhy1CPMj1zWffD9YifFmSeBzPylsrhb1qP8OCEx5Etw,1550
7
+ pyzotero-1.6.1.dist-info/METADATA,sha256=TCxweUVtZbjMDFDrFtZMDzKCFm4j8VMNkwzbJ2kJUZ0,7204
8
+ pyzotero-1.6.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
9
+ pyzotero-1.6.1.dist-info/top_level.txt,sha256=BOPNkPk5VtNDCy_li7Xftx6k0zG8STGxh-KgckcxLEw,18
10
+ pyzotero-1.6.1.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- _version.py,sha256=0H-JgqeGiV_8mNGxbNI0y353Aqa7XZVSkG8ibJE_edo,413
2
- pyzotero/__init__.py,sha256=5QI4Jou9L-YJAf_oN9TgRXVKgt_Unc39oADo2Ch8bLI,243
3
- pyzotero/zotero.py,sha256=SIBYg38twZkZowO2MbZQXrF15IUJfnH0fBVF86xDr14,75234
4
- pyzotero/zotero_errors.py,sha256=UPhAmf2K05cnoeIl2wjufWQedepg7vBKb-ShU0TdlL4,2582
5
- pyzotero-1.5.28.dist-info/AUTHORS,sha256=ZMicxg7lRScOYbxzMPznlzMbmrFIUIHwg-NvljEMbRQ,110
6
- pyzotero-1.5.28.dist-info/LICENSE.md,sha256=bhy1CPMj1zWffD9YifFmSeBzPylsrhb1qP8OCEx5Etw,1550
7
- pyzotero-1.5.28.dist-info/METADATA,sha256=E692i0SYizzrEYVYMzjUUfKvGmRs9WoZTxxOxpah1ZI,7205
8
- pyzotero-1.5.28.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
9
- pyzotero-1.5.28.dist-info/top_level.txt,sha256=BOPNkPk5VtNDCy_li7Xftx6k0zG8STGxh-KgckcxLEw,18
10
- pyzotero-1.5.28.dist-info/RECORD,,