jwbmisc 0.0.6__py3-none-any.whl → 0.0.7__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.
jwbmisc/_version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.0.6'
32
- __version_tuple__ = version_tuple = (0, 0, 6)
31
+ __version__ = version = '0.0.7'
32
+ __version_tuple__ = version_tuple = (0, 0, 7)
33
33
 
34
34
  __commit_id__ = commit_id = None
jwbmisc/passwd.py CHANGED
@@ -1,5 +1,6 @@
1
1
  import subprocess as sp
2
2
  import os
3
+ from urllib.parse import urlparse, parse_qs
3
4
  from pathlib import Path
4
5
 
5
6
  PASS_BIN = os.environ.get("JWBMISC_PASS_BIN", "pass")
@@ -11,11 +12,18 @@ def get_pass(*pass_keys: str):
11
12
 
12
13
  for pass_key in pass_keys:
13
14
  if pass_key.startswith("pass://"):
14
- k = pass_key.removeprefix("pass://")
15
- lnum = 1
16
- if "?" in k:
17
- k, lnum = k.rsplit("?", 1)
18
- return _call_unix_pass(k, int(lnum))
15
+ url = urlparse(pass_key, scheme="pass")
16
+ query = parse_qs(url.query)
17
+ lines = query.get("lines", ["1"])[0]
18
+ format = query.get("format", ["raw"])[0]
19
+ if lines == "all":
20
+ lines = None
21
+ else:
22
+ lines = [int(n) - 1 for n in lines.split(",")]
23
+ netloc = url.netloc.rstrip("/")
24
+ path = url.path.lstrip("/")
25
+ key = f"{netloc}/{path}".lstrip("/")
26
+ return _call_unix_pass(key, lines, format)
19
27
 
20
28
  if pass_key.startswith("env://"):
21
29
  env_var = pass_key.removeprefix("env://").replace("/", "__")
@@ -47,26 +55,25 @@ def get_pass(*pass_keys: str):
47
55
  raise KeyError(f"Could not acquire password from one of {pass_keys}")
48
56
 
49
57
 
50
- def _call_unix_pass(key, lnum=1):
58
+ def _call_unix_pass(key: str, idcs: list[int] | None = None, format: str = "list") -> str | list[str] | None:
51
59
  proc = sp.Popen([PASS_BIN, "show", key], stdout=sp.PIPE, stderr=sp.PIPE, encoding="utf-8")
52
60
  value, stderr = proc.communicate()
53
61
 
54
62
  if proc.returncode != 0:
55
63
  raise KeyError(f"pass failed for '{key}': {stderr.strip()}")
56
64
 
57
- if lnum is None or lnum == 0:
58
- return value.strip()
59
- lines = value.splitlines()
65
+ if idcs is None or idcs == [-1]:
66
+ return value.rstrip()
60
67
 
68
+ lines = value.splitlines()
61
69
  try:
62
- if isinstance(lnum, list):
63
- pw = [lines[ln - 1].strip() for ln in lnum]
64
- else:
65
- pw = lines[lnum - 1].strip()
70
+ lines = [lines[idx] for idx in idcs]
66
71
  except IndexError:
67
- raise KeyError(f"could not retrieve lines {lnum} for {key}")
72
+ raise KeyError(f"could not retrieve line idcs {idcs} for {key}")
68
73
 
69
- return pw
74
+ if format == "list":
75
+ return lines
76
+ return "\n".join(lines)
70
77
 
71
78
 
72
79
  def _keeper_password(record_uid: str, field_path: str | None = None) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jwbmisc
3
- Version: 0.0.6
3
+ Version: 0.0.7
4
4
  Summary: Misc util functions of jwb
5
5
  Author-email: Joachim Bargsten <jw@bargsten.org>
6
6
  License: Apache License
@@ -1,15 +1,15 @@
1
1
  jwbmisc/__init__.py,sha256=5VXxKCMejjLWaiECh64309WJ2LpHHSULxaGOvCAOzyU,581
2
- jwbmisc/_version.py,sha256=7MyqQ3iPP2mJruPfRYGCNCq1z7_Nk7c-eyYecYITxsY,704
2
+ jwbmisc/_version.py,sha256=AV58KqMkBGaCvmPdbd3g9huyNXfIVxjw8QbCMdaeivU,704
3
3
  jwbmisc/collection.py,sha256=mICHxBFfk2XY8ajdWkLvmQF1R6oo6d0torpRAeDvd1c,663
4
4
  jwbmisc/exec.py,sha256=_3Xf0D342VDoVwtCZLjnyJ8N-WuHJfeIrBGFsL2qUW4,1260
5
5
  jwbmisc/fs.py,sha256=Vf28qbOnBeHEbXNMUZjOQXtMWBurjkzD2KmfV2gJQXM,599
6
6
  jwbmisc/interactive.py,sha256=qMgpQNHvUg4AYw-aAAy2qdxri1aKr-mffoLfUgh8TWE,423
7
7
  jwbmisc/json.py,sha256=h3CBDNNZjcTDxydViyydPsQufXQLuxqP24wBBAT2nDs,1198
8
8
  jwbmisc/keeper.py,sha256=mKhrUjNvlePxDv89tMcDs4dEgHWTVbtzMPH1jMRuylU,5201
9
- jwbmisc/passwd.py,sha256=UKQk9sDJFYQSqBvTjPjtYLC1arAol82GlUdlc_PK4Eo,2433
9
+ jwbmisc/passwd.py,sha256=VfE3P6B_DpRS7htzKTdvtxlxQj9OkFMVGeGZxNZ9B5w,2856
10
10
  jwbmisc/string.py,sha256=0_AvtAyXUlyVL6yw1iMjs3vMunubTTTWS0PSu_qKgi8,1232
11
- jwbmisc-0.0.6.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
- jwbmisc-0.0.6.dist-info/METADATA,sha256=7ixSPZaGjryN7NKhu88Q9AAoMaAkU1E_Q25_48eXfT0,14507
13
- jwbmisc-0.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- jwbmisc-0.0.6.dist-info/top_level.txt,sha256=FqEYs8zdG3iGOJmC6cutDXfGQUNptzfYeKsaG43y1HE,8
15
- jwbmisc-0.0.6.dist-info/RECORD,,
11
+ jwbmisc-0.0.7.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
+ jwbmisc-0.0.7.dist-info/METADATA,sha256=LuXHFOVggPnK2nA1w9Hg9_LBchkGHtVumeH7bUwqzuY,14507
13
+ jwbmisc-0.0.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
14
+ jwbmisc-0.0.7.dist-info/top_level.txt,sha256=FqEYs8zdG3iGOJmC6cutDXfGQUNptzfYeKsaG43y1HE,8
15
+ jwbmisc-0.0.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5