Skip to content

Commit b0fb131

Browse files
authored
Merge pull request #43 from saying121/node
Python bindgen add *LoginGetter
2 parents 52851c2 + d266759 commit b0fb131

File tree

5 files changed

+222
-6
lines changed

5 files changed

+222
-6
lines changed

bindgen/python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async def get_cookies():
1919
print(c[0])
2020

2121

22-
asyncio.run(test_c())
22+
asyncio.run(get_cookies())
2323
```
2424

2525
## Status

bindgen/python/python/decrypt_cookies/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def to_cookiejar(
2929
is_secure=cookie.is_secure,
3030
name=cookie.name,
3131
path=cookie.path,
32-
value=cookie.value,
32+
value=cookie.decrypted_value
33+
if cookie.decrypted_value is not None
34+
else cookie.value,
3335
)
3436
)
3537
elif isinstance(cookie, MozCookie):

bindgen/python/python/decrypt_cookies/decrypt_cookies.pyi

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ class ArcGetter:
4444
Filter by host
4545
"""
4646

47+
class ArcLoginGetter:
48+
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[ArcLoginGetter]:
49+
r"""
50+
base: When browser start with `--user-data-dir=DIR` or special other channel
51+
"""
52+
def logins_all(self) -> typing.Awaitable[list[LoginData]]:
53+
r"""
54+
Return all login data
55+
"""
56+
def logins_by_host(self, host:builtins.str) -> typing.Awaitable[list[LoginData]]:
57+
r"""
58+
Filter by host
59+
"""
60+
4761
class BraveCookieGetter:
4862
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[BraveCookieGetter]:
4963
r"""
@@ -80,6 +94,20 @@ class BraveGetter:
8094
Filter by host
8195
"""
8296

97+
class BraveLoginGetter:
98+
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[BraveLoginGetter]:
99+
r"""
100+
base: When browser start with `--user-data-dir=DIR` or special other channel
101+
"""
102+
def logins_all(self) -> typing.Awaitable[list[LoginData]]:
103+
r"""
104+
Return all login data
105+
"""
106+
def logins_by_host(self, host:builtins.str) -> typing.Awaitable[list[LoginData]]:
107+
r"""
108+
Filter by host
109+
"""
110+
83111
class ChromeCookieGetter:
84112
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[ChromeCookieGetter]:
85113
r"""
@@ -116,6 +144,20 @@ class ChromeGetter:
116144
Filter by host
117145
"""
118146

147+
class ChromeLoginGetter:
148+
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[ChromeLoginGetter]:
149+
r"""
150+
base: When browser start with `--user-data-dir=DIR` or special other channel
151+
"""
152+
def logins_all(self) -> typing.Awaitable[list[LoginData]]:
153+
r"""
154+
Return all login data
155+
"""
156+
def logins_by_host(self, host:builtins.str) -> typing.Awaitable[list[LoginData]]:
157+
r"""
158+
Filter by host
159+
"""
160+
119161
class ChromiumCookie:
120162
@property
121163
def creation_utc(self) -> typing.Optional[datetime.datetime]: ...
@@ -226,6 +268,20 @@ class ChromiumGetter:
226268
Filter by host
227269
"""
228270

271+
class ChromiumLoginGetter:
272+
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[ChromiumLoginGetter]:
273+
r"""
274+
base: When browser start with `--user-data-dir=DIR` or special other channel
275+
"""
276+
def logins_all(self) -> typing.Awaitable[list[LoginData]]:
277+
r"""
278+
Return all login data
279+
"""
280+
def logins_by_host(self, host:builtins.str) -> typing.Awaitable[list[LoginData]]:
281+
r"""
282+
Filter by host
283+
"""
284+
229285
class CocCocCookieGetter:
230286
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[CocCocCookieGetter]:
231287
r"""
@@ -262,6 +318,20 @@ class CocCocGetter:
262318
Filter by host
263319
"""
264320

321+
class CocCocLoginGetter:
322+
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[CocCocLoginGetter]:
323+
r"""
324+
base: When browser start with `--user-data-dir=DIR` or special other channel
325+
"""
326+
def logins_all(self) -> typing.Awaitable[list[LoginData]]:
327+
r"""
328+
Return all login data
329+
"""
330+
def logins_by_host(self, host:builtins.str) -> typing.Awaitable[list[LoginData]]:
331+
r"""
332+
Filter by host
333+
"""
334+
265335
class EdgeCookieGetter:
266336
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[EdgeCookieGetter]:
267337
r"""
@@ -298,6 +368,20 @@ class EdgeGetter:
298368
Filter by host
299369
"""
300370

371+
class EdgeLoginGetter:
372+
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[EdgeLoginGetter]:
373+
r"""
374+
base: When browser start with `--user-data-dir=DIR` or special other channel
375+
"""
376+
def logins_all(self) -> typing.Awaitable[list[LoginData]]:
377+
r"""
378+
Return all login data
379+
"""
380+
def logins_by_host(self, host:builtins.str) -> typing.Awaitable[list[LoginData]]:
381+
r"""
382+
Filter by host
383+
"""
384+
301385
class FirefoxCookieGetter:
302386
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None, profile:typing.Optional[builtins.str]=None, profile_path:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[FirefoxCookieGetter]:
303387
r"""
@@ -608,6 +692,20 @@ class OperaGXGetter:
608692
Filter by host
609693
"""
610694

695+
class OperaGXLoginGetter:
696+
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[OperaGXLoginGetter]:
697+
r"""
698+
base: When browser start with `--user-data-dir=DIR` or special other channel
699+
"""
700+
def logins_all(self) -> typing.Awaitable[list[LoginData]]:
701+
r"""
702+
Return all login data
703+
"""
704+
def logins_by_host(self, host:builtins.str) -> typing.Awaitable[list[LoginData]]:
705+
r"""
706+
Filter by host
707+
"""
708+
611709
class OperaGetter:
612710
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[OperaGetter]:
613711
r"""
@@ -630,6 +728,20 @@ class OperaGetter:
630728
Filter by host
631729
"""
632730

731+
class OperaLoginGetter:
732+
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[OperaLoginGetter]:
733+
r"""
734+
base: When browser start with `--user-data-dir=DIR` or special other channel
735+
"""
736+
def logins_all(self) -> typing.Awaitable[list[LoginData]]:
737+
r"""
738+
Return all login data
739+
"""
740+
def logins_by_host(self, host:builtins.str) -> typing.Awaitable[list[LoginData]]:
741+
r"""
742+
Filter by host
743+
"""
744+
633745
class SafariCookie:
634746
@property
635747
def version(self) -> builtins.int: ...
@@ -725,6 +837,20 @@ class VivaldiGetter:
725837
Filter by host
726838
"""
727839

840+
class VivaldiLoginGetter:
841+
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[VivaldiLoginGetter]:
842+
r"""
843+
base: When browser start with `--user-data-dir=DIR` or special other channel
844+
"""
845+
def logins_all(self) -> typing.Awaitable[list[LoginData]]:
846+
r"""
847+
Return all login data
848+
"""
849+
def logins_by_host(self, host:builtins.str) -> typing.Awaitable[list[LoginData]]:
850+
r"""
851+
Filter by host
852+
"""
853+
728854
class YandexCookieGetter:
729855
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[YandexCookieGetter]:
730856
r"""
@@ -761,6 +887,20 @@ class YandexGetter:
761887
Filter by host
762888
"""
763889

890+
class YandexLoginGetter:
891+
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[YandexLoginGetter]:
892+
r"""
893+
base: When browser start with `--user-data-dir=DIR` or special other channel
894+
"""
895+
def logins_all(self) -> typing.Awaitable[list[LoginData]]:
896+
r"""
897+
Return all login data
898+
"""
899+
def logins_by_host(self, host:builtins.str) -> typing.Awaitable[list[LoginData]]:
900+
r"""
901+
Filter by host
902+
"""
903+
764904
class ZenCookieGetter:
765905
def __new__(cls, base:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None, profile:typing.Optional[builtins.str]=None, profile_path:typing.Optional[builtins.str | os.PathLike | pathlib.Path]=None) -> typing.Awaitable[ZenCookieGetter]:
766906
r"""

bindgen/python/src/chromium.rs

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use decrypt_cookies_rs::{
66
ChromiumCookie as ChromiumCookieRs, GetCookies, GetLogins, LoginData as LoginDataRs,
77
},
88
prelude::{
9-
ChromiumCookieGetter as ChromiumCookieGetterRs, ChromiumGetter as ChromiumGetterRs, *,
9+
ChromiumCookieGetter as ChromiumCookieGetterRs, ChromiumGetter as ChromiumGetterRs,
10+
ChromiumLoginGetter as ChromiumLoginGetterRs, *,
1011
},
1112
};
1213
use pyo3::{exceptions::PyValueError, prelude::*};
@@ -47,7 +48,7 @@ macro_rules! chromiums {
4748
future_into_py(py, async move {
4849
b.build()
4950
.await
50-
.map([<$browser Getter>])
51+
.map(Self)
5152
.map_err(|e| PyValueError::new_err(e.to_string()))
5253
})
5354
.map(|v| unsafe { v.downcast_into_unchecked() })
@@ -158,7 +159,7 @@ macro_rules! chromiums {
158159
future_into_py(py, async move {
159160
b.build_cookie()
160161
.await
161-
.map([<$browser CookieGetter>])
162+
.map(Self)
162163
.map_err(|e| PyValueError::new_err(e.to_string()))
163164
})
164165
.map(|v| unsafe { v.downcast_into_unchecked() })
@@ -202,6 +203,79 @@ macro_rules! chromiums {
202203
.map(|v| unsafe { v.downcast_into_unchecked() })
203204
}
204205
}
206+
207+
#[gen_stub_pyclass]
208+
#[pyclass(frozen, str)]
209+
#[derive(Clone)]
210+
#[derive(Debug)]
211+
#[derive(Default)]
212+
pub struct [<$browser LoginGetter>](ChromiumLoginGetterRs<$browser>);
213+
214+
impl Display for [<$browser LoginGetter>] {
215+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
216+
self.0.fmt(f)
217+
}
218+
}
219+
220+
#[gen_stub_pymethods]
221+
#[pymethods]
222+
impl [<$browser LoginGetter>] {
223+
/// base: When browser start with `--user-data-dir=DIR` or special other channel
224+
#[new]
225+
#[pyo3(signature = (base=None))]
226+
#[gen_stub(override_return_type(type_repr="typing.Awaitable[ChromiumGetter]", imports=("typing")))]
227+
pub fn new(py: Python<'_>, base: Option<PathBuf>) -> PyResult<Bound<'_, Self>> {
228+
let b = base.map_or_else(
229+
ChromiumBuilder::<$browser>::new,
230+
ChromiumBuilder::<$browser>::with_user_data_dir,
231+
);
232+
future_into_py(py, async move {
233+
b.build_login()
234+
.await
235+
.map(Self)
236+
.map_err(|e| PyValueError::new_err(e.to_string()))
237+
})
238+
.map(|v| unsafe { v.downcast_into_unchecked() })
239+
}
240+
241+
/// Return all login data
242+
#[gen_stub(override_return_type(type_repr="typing.Awaitable[list[LoginData]]", imports=("typing")))]
243+
pub fn logins_all<'a>(&'a self, py: Python<'a>) -> PyResult<Bound<'_, Vec<LoginData>>> {
244+
let self_ = self.clone();
245+
future_into_py(py, async move {
246+
let all = self_
247+
.0
248+
.logins_all()
249+
.await
250+
.map_err(|e| PyValueError::new_err(e.to_string()))?;
251+
#[expect(clippy::transmute_undefined_repr, reason = "already repr(C)")]
252+
let all = unsafe { mem::transmute::<Vec<LoginDataRs>, Vec<LoginData>>(all) };
253+
Ok(all)
254+
})
255+
.map(|v| unsafe { v.downcast_into_unchecked() })
256+
}
257+
258+
/// Filter by host
259+
#[gen_stub(override_return_type(type_repr="typing.Awaitable[list[LoginData]]", imports=("typing")))]
260+
pub fn logins_by_host<'a>(
261+
&'a self,
262+
py: Python<'a>,
263+
host: String,
264+
) -> PyResult<Bound<'_, Vec<LoginData>>> {
265+
let self_ = self.clone();
266+
future_into_py(py, async move {
267+
let all = self_
268+
.0
269+
.logins_by_host(host)
270+
.await
271+
.map_err(|e| PyValueError::new_err(e.to_string()))?;
272+
#[expect(clippy::transmute_undefined_repr, reason = "already repr(C)")]
273+
let all = unsafe { mem::transmute::<Vec<LoginDataRs>, Vec<LoginData>>(all) };
274+
Ok(all)
275+
})
276+
.map(|v| unsafe { v.downcast_into_unchecked() })
277+
}
278+
}
205279
)*
206280
}
207281
};

bindgen/python/src/safari.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl SafariGetter {
4040
}
4141
b.build()
4242
.await
43-
.map(SafariGetter)
43+
.map(Self)
4444
.map_err(|e| PyValueError::new_err(e.to_string()))
4545
})
4646
.map(|v| unsafe { v.downcast_into_unchecked() })

0 commit comments

Comments
 (0)