26
26
27
27
from .http import HTTPClient
28
28
from .paste import File , Paste
29
- from .utils import require_authentication
30
29
31
30
if TYPE_CHECKING :
32
31
import datetime
41
40
class Client :
42
41
__slots__ = ("http" ,)
43
42
44
- def __init__ (self , * , token : str | None = None , session : ClientSession | None = None ) -> None :
45
- self .http : HTTPClient = HTTPClient (token = token , session = session )
43
+ def __init__ (self , * , session : ClientSession | None = None ) -> None :
44
+ self .http : HTTPClient = HTTPClient (session = session )
46
45
47
46
async def __aenter__ (self ) -> Self :
48
47
return self
49
48
50
49
async def __aexit__ (
51
- self ,
52
- exc_cls : type [BaseException ] | None ,
53
- exc_value : BaseException | None ,
54
- traceback : TracebackType | None
50
+ self , exc_cls : type [BaseException ] | None , exc_value : BaseException | None , traceback : TracebackType | None
55
51
) -> None :
56
52
await self .close ()
57
53
@@ -62,52 +58,10 @@ async def close(self) -> None:
62
58
"""
63
59
await self .http .close ()
64
60
65
- @overload
66
- async def create_paste (
67
- self ,
68
- * ,
69
- filename : str ,
70
- content : str ,
71
- file : None = ...,
72
- files : None = ...,
73
- password : str | None = ...,
74
- expires : datetime .datetime | None = ...,
75
- ) -> Paste :
76
- ...
77
-
78
- @overload
79
61
async def create_paste (
80
62
self ,
81
63
* ,
82
- filename : None = ...,
83
- content : None = ...,
84
- file : File ,
85
- files : None = ...,
86
- password : str | None = ...,
87
- expires : datetime .datetime | None = ...,
88
- ) -> Paste :
89
- ...
90
-
91
- @overload
92
- async def create_paste (
93
- self ,
94
- * ,
95
- filename : None = ...,
96
- content : None = ...,
97
- file : None = ...,
98
64
files : Sequence [File ],
99
- password : str | None = ...,
100
- expires : datetime .datetime | None = ...,
101
- ) -> Paste :
102
- ...
103
-
104
- async def create_paste (
105
- self ,
106
- * ,
107
- filename : str | None = None ,
108
- content : str | None = None ,
109
- file : File | None = None ,
110
- files : Sequence [File ] | None = None ,
111
65
password : str | None = None ,
112
66
expires : datetime .datetime | None = None ,
113
67
) -> Paste :
@@ -117,84 +71,41 @@ async def create_paste(
117
71
118
72
Parameters
119
73
-----------
120
- filename: Optional[:class:`str`]
121
- The filename to create.
122
- content: Optional[:class:`str`]
123
- The content of the file you are creating.
124
- file: Optional[:class:`~mystbin.File`]
125
- The pre-created file you wish to upload.
126
- files: Optional[List[:class:`~mystbin.File`]]
74
+ files: List[:class:`~mystbin.File`]
127
75
The pre-creates list of files you wish to upload.
128
76
password: Optional[:class:`str`]
129
77
The password of the paste, if any.
130
78
expires: Optional[:class:`datetime.datetime`]
131
79
When the paste expires, if any.
132
80
133
- Raises
134
- -------
135
- :exc:`ValueError`
136
- A bad combinarion of singular and plural pastes were passed.
137
-
138
81
Returns
139
82
--------
140
83
:class:`mystbin.Paste`
141
84
The paste that was created.
142
-
143
-
144
- ..note::
145
- Passing combinations of both singular and plural files is not supports and will raise an exception.
146
- Internally the order of precesence is ``files`` > ``file`` > ``filename and content``.
147
85
"""
148
- if (filename and content ) and file :
149
- raise ValueError ("Cannot provide both `file` and `filename`/`content`" )
150
-
151
- resolved_files : Sequence [File ] = []
152
- if filename and content :
153
- resolved_files = [File (filename = filename , content = content , attachment_url = None )]
154
- elif file :
155
- resolved_files = [file ]
86
+ data = await self .http .create_paste (files = files , password = password , expires = expires )
87
+ return Paste .from_create (data , files = files )
156
88
157
- if resolved_files and files :
158
- raise ValueError ("Cannot provide both singular and plural files." )
159
-
160
- resolved_files = files or resolved_files
161
-
162
- data = await self .http .create_paste (files = resolved_files , password = password , expires = expires )
163
- return Paste .from_data (data )
164
-
165
- @require_authentication
166
- async def delete_paste (self , paste_id : str , / ) -> None :
89
+ async def delete_paste (self , security_token : str , / ) -> None :
167
90
"""|coro|
168
91
169
92
Delete a paste.
170
93
171
94
Parameters
172
95
-----------
173
- paste_id : :class:`str`
174
- The paste to delete.
96
+ security_token : :class:`str`
97
+ The security token relating to the paste to delete.
175
98
"""
176
- await self .http .delete_pastes (paste_ids = [paste_id ])
177
-
178
- @require_authentication
179
- async def delete_pastes (self , paste_ids : list [str ], / ) -> None :
180
- """|coro|
99
+ await self .http .delete_paste (security_token )
181
100
182
- Delete multiple pastes.
183
-
184
- Parameters
185
- -----------
186
- paste_ids: List[:class:`str`]
187
- The pastes to delete.
188
- """
189
- await self .http .delete_pastes (paste_ids = paste_ids )
101
+ @overload
102
+ async def get_paste (self , paste_id : str , * , password : str | None = ..., raw : Literal [False ]) -> Paste : ...
190
103
191
104
@overload
192
- async def get_paste (self , paste_id : str , * , password : str | None = ..., raw : Literal [False ]) -> Paste :
193
- ...
105
+ async def get_paste (self , paste_id : str , * , password : str | None = ..., raw : Literal [True ]) -> list [str ]: ...
194
106
195
107
@overload
196
- async def get_paste (self , paste_id : str , * , password : str | None = ..., raw : Literal [True ]) -> list [str ]:
197
- ...
108
+ async def get_paste (self , paste_id : str , * , password : str | None = ...) -> Paste : ...
198
109
199
110
async def get_paste (self , paste_id : str , * , password : str | None = None , raw : bool = False ) -> Paste | list [str ]:
200
111
"""|coro|
@@ -219,24 +130,4 @@ async def get_paste(self, paste_id: str, *, password: str | None = None, raw: bo
219
130
data = await self .http .get_paste (paste_id = paste_id , password = password )
220
131
if raw :
221
132
return [item ["content" ] for item in data ["files" ]]
222
- return Paste .from_data (data )
223
-
224
- @require_authentication
225
- async def get_user_pastes (self , * , limit : int = 100 ) -> list [Paste ]:
226
- """|coro|
227
-
228
- Get all pastes belonging to the current authenticated user.
229
-
230
- Parameters
231
- -----------
232
- limit: :class:`int`
233
- The amount of pastes to fetch. Defaults to ``100``.
234
-
235
- Returns
236
- --------
237
- List[:class:`Paste`]
238
- The pastes that were fetched.
239
- """
240
- data = await self .http .get_my_pastes (limit = limit )
241
-
242
- return [Paste .from_data (x ) for x in data ]
133
+ return Paste .from_get (data )
0 commit comments