nc-py-api 0.19.2__py3-none-any.whl → 0.20.0__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.
nc_py_api/_session.py CHANGED
@@ -307,7 +307,7 @@ class NcSessionBasic(NcSessionBase, ABC):
307
307
  adapter = self.adapter_dav if dav else self.adapter
308
308
  with adapter.stream("GET", url_path, params=params, headers=kwargs.get("headers")) as response:
309
309
  check_error(response)
310
- for data_chunk in response.iter_raw(chunk_size=kwargs.get("chunk_size", 5 * 1024 * 1024)):
310
+ for data_chunk in response.iter_bytes(chunk_size=kwargs.get("chunk_size", 5 * 1024 * 1024)):
311
311
  fp.write(data_chunk)
312
312
 
313
313
 
@@ -434,7 +434,7 @@ class AsyncNcSessionBasic(NcSessionBase, ABC):
434
434
  adapter = self.adapter_dav if dav else self.adapter
435
435
  async with adapter.stream("GET", url_path, params=params, headers=kwargs.get("headers")) as response:
436
436
  check_error(response)
437
- async for data_chunk in response.aiter_raw(chunk_size=kwargs.get("chunk_size", 5 * 1024 * 1024)):
437
+ async for data_chunk in response.aiter_bytes(chunk_size=kwargs.get("chunk_size", 5 * 1024 * 1024)):
438
438
  fp.write(data_chunk)
439
439
 
440
440
 
nc_py_api/_version.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """Version of nc_py_api."""
2
2
 
3
- __version__ = "0.19.2"
3
+ __version__ = "0.20.0"
nc_py_api/nextcloud.py CHANGED
@@ -31,7 +31,6 @@ from .activity import _ActivityAPI, _AsyncActivityAPI
31
31
  from .apps import _AppsAPI, _AsyncAppsAPI
32
32
  from .calendar_api import _CalendarAPI
33
33
  from .ex_app.defs import LogLvl
34
- from .ex_app.events_listener import AsyncEventsListenerAPI, EventsListenerAPI
35
34
  from .ex_app.occ_commands import AsyncOccCommandsAPI, OccCommandsAPI
36
35
  from .ex_app.providers.providers import AsyncProvidersApi, ProvidersApi
37
36
  from .ex_app.ui.ui import AsyncUiApi, UiApi
@@ -327,8 +326,6 @@ class NextcloudApp(_NextcloudBasic):
327
326
  ui: UiApi
328
327
  """Nextcloud UI API for ExApps"""
329
328
  providers: ProvidersApi
330
- """API for registering providers for Nextcloud"""
331
- events_listener: EventsListenerAPI
332
329
  """API for registering Events listeners for ExApps"""
333
330
  occ_commands: OccCommandsAPI
334
331
  """API for registering OCC command for ExApps"""
@@ -344,7 +341,6 @@ class NextcloudApp(_NextcloudBasic):
344
341
  self.preferences_ex = PreferencesExAPI(self._session)
345
342
  self.ui = UiApi(self._session)
346
343
  self.providers = ProvidersApi(self._session)
347
- self.events_listener = EventsListenerAPI(self._session)
348
344
  self.occ_commands = OccCommandsAPI(self._session)
349
345
 
350
346
  @property
@@ -462,8 +458,6 @@ class AsyncNextcloudApp(_AsyncNextcloudBasic):
462
458
  ui: AsyncUiApi
463
459
  """Nextcloud UI API for ExApps"""
464
460
  providers: AsyncProvidersApi
465
- """API for registering providers for Nextcloud"""
466
- events_listener: AsyncEventsListenerAPI
467
461
  """API for registering Events listeners for ExApps"""
468
462
  occ_commands: AsyncOccCommandsAPI
469
463
  """API for registering OCC command for ExApps"""
@@ -479,7 +473,6 @@ class AsyncNextcloudApp(_AsyncNextcloudBasic):
479
473
  self.preferences_ex = AsyncPreferencesExAPI(self._session)
480
474
  self.ui = AsyncUiApi(self._session)
481
475
  self.providers = AsyncProvidersApi(self._session)
482
- self.events_listener = AsyncEventsListenerAPI(self._session)
483
476
  self.occ_commands = AsyncOccCommandsAPI(self._session)
484
477
 
485
478
  @property
nc_py_api/webhooks.py CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import dataclasses
4
4
 
5
+ from ._exceptions import NextcloudExceptionNotFound
5
6
  from ._misc import clear_from_params_empty # , require_capabilities
6
7
  from ._session import AppConfig, AsyncNcSessionBasic, NcSessionBasic
7
8
 
@@ -51,7 +52,7 @@ class WebhookInfo:
51
52
  @property
52
53
  def user_id_filter(self) -> str:
53
54
  """Currently unknown."""
54
- return self._raw_data["userIdFilter"]
55
+ return "" if self._raw_data["userIdFilter"] is None else self._raw_data["userIdFilter"]
55
56
 
56
57
  @property
57
58
  def headers(self) -> dict:
@@ -84,8 +85,11 @@ class _WebhooksAPI:
84
85
  params = {"uri": uri_filter} if uri_filter else {}
85
86
  return [WebhookInfo(i) for i in self._session.ocs("GET", f"{self._ep_base}", params=params)]
86
87
 
87
- def get_entry(self, webhook_id: int) -> WebhookInfo:
88
- return WebhookInfo(self._session.ocs("GET", f"{self._ep_base}/{webhook_id}"))
88
+ def get_entry(self, webhook_id: int) -> WebhookInfo | None:
89
+ try:
90
+ return WebhookInfo(self._session.ocs("GET", f"{self._ep_base}/{webhook_id}"))
91
+ except NextcloudExceptionNotFound:
92
+ return None
89
93
 
90
94
  def register(
91
95
  self,
@@ -151,7 +155,7 @@ class _WebhooksAPI:
151
155
  class _AsyncWebhooksAPI:
152
156
  """The class provides the async application management API on the Nextcloud server."""
153
157
 
154
- _ep_base: str = "/ocs/v1.php/webhooks"
158
+ _ep_base: str = "/ocs/v1.php/apps/webhook_listeners/api/v1/webhooks"
155
159
 
156
160
  def __init__(self, session: AsyncNcSessionBasic):
157
161
  self._session = session
@@ -160,8 +164,11 @@ class _AsyncWebhooksAPI:
160
164
  params = {"uri": uri_filter} if uri_filter else {}
161
165
  return [WebhookInfo(i) for i in await self._session.ocs("GET", f"{self._ep_base}", params=params)]
162
166
 
163
- async def get_entry(self, webhook_id: int) -> WebhookInfo:
164
- return WebhookInfo(await self._session.ocs("GET", f"{self._ep_base}/{webhook_id}"))
167
+ async def get_entry(self, webhook_id: int) -> WebhookInfo | None:
168
+ try:
169
+ return WebhookInfo(await self._session.ocs("GET", f"{self._ep_base}/{webhook_id}"))
170
+ except NextcloudExceptionNotFound:
171
+ return None
165
172
 
166
173
  async def register(
167
174
  self,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nc-py-api
3
- Version: 0.19.2
3
+ Version: 0.20.0
4
4
  Summary: Nextcloud Python Framework
5
5
  Project-URL: Changelog, https://github.com/cloud-py-api/nc_py_api/blob/main/CHANGELOG.md
6
6
  Project-URL: Documentation, https://cloud-py-api.github.io/nc_py_api/
@@ -4,15 +4,15 @@ nc_py_api/_exceptions.py,sha256=7vbUECaLmD7RJBCU27t4fuP6NmQK6r4508u_gS4szhI,2298
4
4
  nc_py_api/_misc.py,sha256=dUzCP9VmyhtICTsn1aexlFAYUioBm40k6Zh-YE5WwCY,3333
5
5
  nc_py_api/_preferences.py,sha256=OtovFZuGHnHYKjdDjSnUappO795tW8Oxj7qVaejHWpQ,2479
6
6
  nc_py_api/_preferences_ex.py,sha256=tThj6U0ZZMaBZ-jUkjrbaI0xDnafWsBowQKsC6gjOQs,7179
7
- nc_py_api/_session.py,sha256=jqvZ-HJOV7f1PJr1tWPGcYGLKqhxLhfr0zMzNYtSGnU,20660
7
+ nc_py_api/_session.py,sha256=8CjrT0ZDTg8cugRkukxUHGA_O7UsiwleawZ_KyEI6n0,20664
8
8
  nc_py_api/_talk_api.py,sha256=0Uo7OduYniuuX3UQPb468RyGJJ-PWBCgJ5HoPuz5Qa0,51068
9
9
  nc_py_api/_theming.py,sha256=hTr3nuOemSuRFZaPy9iXNmBM7rDgQHECH43tHMWGqEY,1870
10
- nc_py_api/_version.py,sha256=IfQ3_oR_eCaAPVpP4i7ZXXZ5f_ghVyuoae34M2rFTW8,52
10
+ nc_py_api/_version.py,sha256=ffWaRZShROhs5-fFhItPP3NQvF3fj57SDMn-qKh0UEo,52
11
11
  nc_py_api/activity.py,sha256=t9VDSnnaXRNOvALqOSGCeXSQZ-426pCOMSfQ96JHys4,9574
12
12
  nc_py_api/apps.py,sha256=Us2y2lszdxXlD8t6kxwd5_Nrrmazc0EvZXIH9O-ol80,9315
13
13
  nc_py_api/calendar_api.py,sha256=-T6CJ8cRbJZTLtxSEDWuuYpD29DMJGCTfLONmtxZV9w,1445
14
14
  nc_py_api/loginflow_v2.py,sha256=UjkK3gMouzNrIS7BFhjbmB_9m4fP2UY5sfpmvJ2EXWk,5760
15
- nc_py_api/nextcloud.py,sha256=4Z_2wKkvyNxbrFkEUi-EABzxG31jW4YsszwT9Xdz0hI,23195
15
+ nc_py_api/nextcloud.py,sha256=C3lnns8Dx34wXsOoN4vwOc0Sm5rA8CgH4UtxNNKFyKc,22793
16
16
  nc_py_api/notes.py,sha256=ljO3TOe-Qg0bJ0mlFQwjg--Pxmj-XFknoLbcbJmII0A,15106
17
17
  nc_py_api/notifications.py,sha256=WgzV21TuLOhLk-UEjhBSbMsIi2isa5MmAx6cbe0pc2Y,9187
18
18
  nc_py_api/options.py,sha256=ZKJqVLhWVwJ6YxAKzGWlPXJhd1vg9GluyFzr-jX4Jp0,2038
@@ -22,10 +22,9 @@ nc_py_api/user_status.py,sha256=I101nwYS8X1WvC8AnLa2f3qJUCPDPHrbq-ke0h1VT4E,1328
22
22
  nc_py_api/users.py,sha256=SQG8Agplaxy7XJgguK-rxV-azpc-QdktbDmLmQtJkXo,15476
23
23
  nc_py_api/users_groups.py,sha256=IPxw-Ks5NjCm6r8_HC9xmf3IYptH00ulITbp5iazhAo,6289
24
24
  nc_py_api/weather_status.py,sha256=wAkjuJPjxc0Rxe4za0BzfwB0XeUmkCXoisJtTH3-qdQ,7582
25
- nc_py_api/webhooks.py,sha256=14nAMy-tnOvmRnJbo42zUHyjX-z6kc9OMDUVKzNmplY,7769
25
+ nc_py_api/webhooks.py,sha256=BGHRtankgbUkcqBRJTFShjRLpaVoFNcjLsrVitoNziM,8083
26
26
  nc_py_api/ex_app/__init__.py,sha256=6Lwid4bBXOSrZf_ocf5m8qkkO1OgYxG0GTs4q6Nw72o,691
27
27
  nc_py_api/ex_app/defs.py,sha256=FaQInH3jLugKxDUqpwrXdkMT-lBxmoqWmXJXc11fa6A,727
28
- nc_py_api/ex_app/events_listener.py,sha256=pgQ4hSQV39NuP9F9IDWxo0Qle6oG15-Ol2FlItnIBGY,4682
29
28
  nc_py_api/ex_app/integration_fastapi.py,sha256=a3mhbBFrv_IaRqaYfKa26duiufZL-hSDFqcPDr59Vts,11041
30
29
  nc_py_api/ex_app/logger.py,sha256=nAHLObuPvl3UBLrlqZulgoxxVaAJ661iP4F6bTW-V-Y,1475
31
30
  nc_py_api/ex_app/misc.py,sha256=c7B0uE8isaIi4SQbxURGUuWjZaaXiLg3Ov6cqvRYplE,2298
@@ -46,8 +45,8 @@ nc_py_api/files/_files.py,sha256=l1oGcXIKmuhlNthXkwL8qbINQgiMJ9wmFega9IP-wNk,138
46
45
  nc_py_api/files/files.py,sha256=7x4hfnVa2y1R5bxK9f8cdggi1gPnpUYnsBj0e4p-4qc,24926
47
46
  nc_py_api/files/files_async.py,sha256=nyDeWiGx_8CHuVrNThSgfZy0l-WlC4El-TzJONo0TsM,25773
48
47
  nc_py_api/files/sharing.py,sha256=VRZCl-TYK6dbu9rUHPs3_jcVozu1EO8bLGZwoRpiLsU,14439
49
- nc_py_api-0.19.2.dist-info/METADATA,sha256=Kh7LhFby1VbKb5JouSSHVJfw9LL4PZDyV6z42k01hic,8055
50
- nc_py_api-0.19.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
51
- nc_py_api-0.19.2.dist-info/licenses/AUTHORS,sha256=B2Q9q9XH3PAxJp0V3GiKQc1l0z7vtGDpDHqda-ISWKM,616
52
- nc_py_api-0.19.2.dist-info/licenses/LICENSE.txt,sha256=OLEMh401fAumGHfRSna365MLIfnjdTcdOHZ6QOzMjkg,1551
53
- nc_py_api-0.19.2.dist-info/RECORD,,
48
+ nc_py_api-0.20.0.dist-info/METADATA,sha256=80t-MmU4I6iXrIIpzf4ruf4PXZwns2WY7hCfpB6yy80,8055
49
+ nc_py_api-0.20.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
50
+ nc_py_api-0.20.0.dist-info/licenses/AUTHORS,sha256=B2Q9q9XH3PAxJp0V3GiKQc1l0z7vtGDpDHqda-ISWKM,616
51
+ nc_py_api-0.20.0.dist-info/licenses/LICENSE.txt,sha256=OLEMh401fAumGHfRSna365MLIfnjdTcdOHZ6QOzMjkg,1551
52
+ nc_py_api-0.20.0.dist-info/RECORD,,
@@ -1,137 +0,0 @@
1
- """Nextcloud API for registering Events listeners for ExApps."""
2
-
3
- import dataclasses
4
-
5
- from .._exceptions import NextcloudExceptionNotFound
6
- from .._misc import require_capabilities
7
- from .._session import AsyncNcSessionApp, NcSessionApp
8
-
9
- _EP_SUFFIX: str = "events_listener"
10
-
11
-
12
- @dataclasses.dataclass
13
- class EventsListener:
14
- """EventsListener description."""
15
-
16
- def __init__(self, raw_data: dict):
17
- self._raw_data = raw_data
18
-
19
- @property
20
- def event_type(self) -> str:
21
- """Main type of event, e.g. ``node_event``."""
22
- return self._raw_data["event_type"]
23
-
24
- @property
25
- def event_subtypes(self) -> str:
26
- """Subtypes for which fire event, e.g. ``NodeCreatedEvent``, ``NodeDeletedEvent``."""
27
- return self._raw_data["event_subtypes"]
28
-
29
- @property
30
- def action_handler(self) -> str:
31
- """Relative ExApp url which will be called by Nextcloud."""
32
- return self._raw_data["action_handler"]
33
-
34
- def __repr__(self):
35
- return f"<{self.__class__.__name__} event_type={self.event_type}, handler={self.action_handler}>"
36
-
37
-
38
- class EventsListenerAPI:
39
- """API for registering Events listeners, avalaible as **nc.events_handler.<method>**."""
40
-
41
- def __init__(self, session: NcSessionApp):
42
- self._session = session
43
-
44
- def register(
45
- self,
46
- event_type: str,
47
- callback_url: str,
48
- event_subtypes: list[str] | None = None,
49
- ) -> None:
50
- """Registers or edits the events listener."""
51
- if event_subtypes is None:
52
- event_subtypes = []
53
- require_capabilities("app_api", self._session.capabilities)
54
- params = {
55
- "eventType": event_type,
56
- "actionHandler": callback_url,
57
- "eventSubtypes": event_subtypes,
58
- }
59
- self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params)
60
-
61
- def unregister(self, event_type: str, not_fail=True) -> None:
62
- """Removes the events listener."""
63
- require_capabilities("app_api", self._session.capabilities)
64
- try:
65
- self._session.ocs(
66
- "DELETE",
67
- f"{self._session.ae_url}/{_EP_SUFFIX}",
68
- params={"eventType": event_type},
69
- )
70
- except NextcloudExceptionNotFound as e:
71
- if not not_fail:
72
- raise e from None
73
-
74
- def get_entry(self, event_type: str) -> EventsListener | None:
75
- """Get information about the event listener."""
76
- require_capabilities("app_api", self._session.capabilities)
77
- try:
78
- return EventsListener(
79
- self._session.ocs(
80
- "GET",
81
- f"{self._session.ae_url}/{_EP_SUFFIX}",
82
- params={"eventType": event_type},
83
- )
84
- )
85
- except NextcloudExceptionNotFound:
86
- return None
87
-
88
-
89
- class AsyncEventsListenerAPI:
90
- """API for registering Events listeners, avalaible as **nc.events_handler.<method>**."""
91
-
92
- def __init__(self, session: AsyncNcSessionApp):
93
- self._session = session
94
-
95
- async def register(
96
- self,
97
- event_type: str,
98
- callback_url: str,
99
- event_subtypes: list[str] | None = None,
100
- ) -> None:
101
- """Registers or edits the events listener."""
102
- if event_subtypes is None:
103
- event_subtypes = []
104
- require_capabilities("app_api", await self._session.capabilities)
105
- params = {
106
- "eventType": event_type,
107
- "actionHandler": callback_url,
108
- "eventSubtypes": event_subtypes,
109
- }
110
- await self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params)
111
-
112
- async def unregister(self, event_type: str, not_fail=True) -> None:
113
- """Removes the events listener."""
114
- require_capabilities("app_api", await self._session.capabilities)
115
- try:
116
- await self._session.ocs(
117
- "DELETE",
118
- f"{self._session.ae_url}/{_EP_SUFFIX}",
119
- params={"eventType": event_type},
120
- )
121
- except NextcloudExceptionNotFound as e:
122
- if not not_fail:
123
- raise e from None
124
-
125
- async def get_entry(self, event_type: str) -> EventsListener | None:
126
- """Get information about the event listener."""
127
- require_capabilities("app_api", await self._session.capabilities)
128
- try:
129
- return EventsListener(
130
- await self._session.ocs(
131
- "GET",
132
- f"{self._session.ae_url}/{_EP_SUFFIX}",
133
- params={"eventType": event_type},
134
- )
135
- )
136
- except NextcloudExceptionNotFound:
137
- return None