1
1
"""Protocol for the specific methods of this class that have synchronous counterparts
2
2
generated at runtime."""
3
3
4
- from typing import TYPE_CHECKING , List , Optional , Protocol
4
+ from typing import TYPE_CHECKING , Any , Dict , List , Optional , Protocol , Union
5
5
6
6
from synapseclient import Synapse
7
+ from synapseclient .core .async_utils import async_to_sync
7
8
8
9
if TYPE_CHECKING :
9
10
from synapseclient .models import (
14
15
)
15
16
16
17
18
+ @async_to_sync
17
19
class WikiOrderHintSynchronousProtocol (Protocol ):
18
20
"""Protocol for the methods of the WikiOrderHint class that have synchronous counterparts
19
21
generated at runtime."""
@@ -22,7 +24,7 @@ def get(
22
24
self ,
23
25
* ,
24
26
synapse_client : Optional [Synapse ] = None ,
25
- ) -> WikiOrderHint :
27
+ ) -> " WikiOrderHint" :
26
28
"""
27
29
Get the order hint of a wiki page tree.
28
30
Arguments:
@@ -32,11 +34,11 @@ def get(
32
34
"""
33
35
return self
34
36
35
- def update (
37
+ def store (
36
38
self ,
37
39
* ,
38
40
synapse_client : Optional ["Synapse" ] = None ,
39
- ) -> WikiOrderHint :
41
+ ) -> " WikiOrderHint" :
40
42
"""
41
43
Update the order hint of a wiki page tree.
42
44
Arguments:
@@ -47,6 +49,7 @@ def update(
47
49
return self
48
50
49
51
52
+ @async_to_sync
50
53
class WikiHistorySnapshotSynchronousProtocol (Protocol ):
51
54
"""Protocol for the methods of the WikiHistorySnapshot class that have synchronous counterparts
52
55
generated at runtime."""
@@ -60,7 +63,7 @@ def get(
60
63
offset : int = 0 ,
61
64
limit : int = 20 ,
62
65
synapse_client : Optional ["Synapse" ] = None ,
63
- ) -> List [WikiHistorySnapshot ]:
66
+ ) -> List [" WikiHistorySnapshot" ]:
64
67
"""
65
68
Get the history of a wiki page as a list of WikiHistorySnapshot objects.
66
69
Arguments:
@@ -75,6 +78,7 @@ def get(
75
78
return list ({})
76
79
77
80
81
+ @async_to_sync
78
82
class WikiHeaderSynchronousProtocol (Protocol ):
79
83
"""Protocol for the methods of the WikiHeader class that have synchronous counterparts
80
84
generated at runtime."""
@@ -87,7 +91,7 @@ def get(
87
91
offset : int = 0 ,
88
92
limit : int = 20 ,
89
93
synapse_client : Optional ["Synapse" ] = None ,
90
- ) -> List [WikiHeader ]:
94
+ ) -> List [" WikiHeader" ]:
91
95
"""
92
96
Get the header tree (hierarchy) of wiki pages for an entity.
93
97
Arguments:
@@ -101,43 +105,39 @@ def get(
101
105
return list ({})
102
106
103
107
108
+ @async_to_sync
104
109
class WikiPageSynchronousProtocol (Protocol ):
105
110
"""Protocol for the methods of the WikiPage class that have synchronous counterparts
106
111
generated at runtime."""
107
112
108
- def create (
109
- self , * , synapse_client : Optional ["Synapse" ] = None , force_version : bool = False
110
- ) -> WikiPage :
113
+ def store (self , * , synapse_client : Optional ["Synapse" ] = None ) -> "WikiPage" :
111
114
"""
112
- Create a new wiki page.
115
+ Store the wiki page. If there is no wiki page, a new wiki page will be created.
116
+ If the wiki page already exists, it will be updated.
113
117
Arguments:
114
118
synapse_client: Optionally provide a Synapse client.
115
- force_version: If True, the wiki page will be created with a new version number.
116
119
Returns:
117
120
The created WikiPage object.
118
121
"""
119
122
return self
120
123
121
- def get (self , * , synapse_client : Optional ["Synapse" ] = None ) -> WikiPage :
124
+ def restore (self , * , synapse_client : Optional ["Synapse" ] = None ) -> " WikiPage" :
122
125
"""
123
- Get a wiki page from Synapse asynchronously .
126
+ Restore a specific version of the wiki page .
124
127
Arguments:
125
128
synapse_client: Optionally provide a Synapse client.
126
129
Returns:
127
- The WikiPage object.
130
+ The restored WikiPage object.
128
131
"""
129
132
return self
130
133
131
- def update (
132
- self , * , force_version : bool = False , synapse_client : Optional ["Synapse" ] = None
133
- ) -> WikiPage :
134
+ def get (self , * , synapse_client : Optional ["Synapse" ] = None ) -> "WikiPage" :
134
135
"""
135
- Update a wiki page asynchronously. If force_version is True, restore a specific version of the content .
136
+ Get a wiki page from Synapse .
136
137
Arguments:
137
- force_version: If True, update a specific version of the wiki page (restore).
138
138
synapse_client: Optionally provide a Synapse client.
139
139
Returns:
140
- The updated WikiPage object.
140
+ The WikiPage object.
141
141
"""
142
142
return self
143
143
@@ -153,66 +153,70 @@ def delete(self, *, synapse_client: Optional["Synapse"] = None) -> None:
153
153
154
154
def get_attachment_handles (
155
155
self , * , synapse_client : Optional ["Synapse" ] = None
156
- ) -> list :
156
+ ) -> List [ Dict [ str , Any ]] :
157
157
"""
158
158
Get the file handles of all attachments on this wiki page.
159
159
Arguments:
160
160
synapse_client: Optionally provide a Synapse client.
161
161
Returns:
162
162
The list of FileHandles for all file attachments of this WikiPage.
163
163
"""
164
- return list ([] )
164
+ return list ({} )
165
165
166
- def get_attachment_url (
166
+ def get_attachment (
167
167
self ,
168
168
file_name : str ,
169
169
* ,
170
+ download_file : bool = True ,
171
+ download_location : Optional [str ] = None ,
170
172
redirect : Optional [bool ] = False ,
171
173
synapse_client : Optional ["Synapse" ] = None ,
172
- ) -> dict :
174
+ ) -> Union [ str , None ] :
173
175
"""
174
- Get the URL of a wiki page attachment .
176
+ Download the wiki page attachment to a local file or return the URL .
175
177
Arguments:
176
178
file_name: The name of the file to get.
179
+ download_file: Whether to download the file. Default is True.
180
+ download_location: The location to download the file to. Required if download_file is True.
177
181
redirect: When set to false, the URL will be returned as text/plain instead of redirecting. Default is False.
178
182
synapse_client: Optionally provide a Synapse client.
179
183
Returns:
180
- The URL that can be used to download a file for a given WikiPage file attachment .
184
+ If download_file is True, the attachment file will be downloaded to the download_location. Otherwise, the URL will be returned .
181
185
"""
182
186
return ""
183
187
184
- def get_attachment_preview_url (
188
+ def get_attachment_preview (
185
189
self ,
186
190
file_name : str ,
187
191
* ,
188
192
wiki_version : Optional [int ] = None ,
189
193
redirect : Optional [bool ] = False ,
190
194
synapse_client : Optional ["Synapse" ] = None ,
191
- ) -> dict :
195
+ ) -> Union [ str , None ] :
192
196
"""
193
- Get the preview URL of a wiki page attachment asynchronously .
197
+ Download the wiki page attachment preview to a local file or return the URL .
194
198
Arguments:
195
199
file_name: The name of the file to get.
196
200
wiki_version: Optional version of the wiki page. If not provided, uses self.wiki_version.
197
201
redirect: When set to false, the URL will be returned as text/plain instead of redirecting. Default is False.
198
202
synapse_client: Optionally provide a Synapse client.
199
203
Returns:
200
- The URL that can be used to download a preview file for a given WikiPage file attachment .
204
+ If download_file is True, the attachment preview file will be downloaded to the download_location. Otherwise, the URL will be returned .
201
205
"""
202
206
return ""
203
207
204
- def get_markdown_url_async (
208
+ def get_markdown (
205
209
self ,
206
210
* ,
207
211
redirect : Optional [bool ] = False ,
208
212
synapse_client : Optional ["Synapse" ] = None ,
209
- ) -> dict :
213
+ ) -> Union [ str , None ] :
210
214
"""
211
- Get the markdown URL of this wiki page asynchronously .
215
+ Download the markdown file to a local file or return the URL .
212
216
Arguments:
213
217
redirect: When set to false, the URL will be returned as text/plain instead of redirecting. Default is False.
214
218
synapse_client: Optionally provide a Synapse client.
215
219
Returns:
216
- The URL that can be used to download the markdown file for this WikiPage .
220
+ If download_file is True, the markdown file will be downloaded to the download_location. Otherwise, the URL will be returned .
217
221
"""
218
222
return ""
0 commit comments