|
1 | | -import functools |
2 | 1 | import re |
3 | 2 |
|
4 | 3 | from datetime import datetime |
5 | | -from typing import List, Optional, Union |
6 | | - |
7 | | -from domaintools.constants import Endpoint, OutputFormat |
8 | | -from domaintools.docstring_patcher import DocstringPatcher |
| 4 | +from typing import Optional |
9 | 5 |
|
10 | 6 |
|
11 | 7 | def get_domain_age(create_date): |
@@ -187,55 +183,3 @@ def validate_feeds_parameters(params): |
187 | 183 | endpoint = params.get("endpoint") |
188 | 184 | if endpoint == Endpoint.DOWNLOAD.value and format == OutputFormat.CSV.value: |
189 | 185 | raise ValueError(f"{format} format is not available in {Endpoint.DOWNLOAD.value} API.") |
190 | | - |
191 | | - |
192 | | -def api_endpoint(spec_name: str, path: str, methods: Union[str, List[str]]): |
193 | | - """ |
194 | | - Decorator to tag a method as an API endpoint. |
195 | | -
|
196 | | - Args: |
197 | | - spec_name: The key for the spec in api_instance.specs |
198 | | - path: The API path (e.g., "/users") |
199 | | - methods: A single method ("get") or list of methods (["get", "post"]) |
200 | | - that this function handles. |
201 | | - """ |
202 | | - |
203 | | - def decorator(func): |
204 | | - func._api_spec_name = spec_name |
205 | | - func._api_path = path |
206 | | - |
207 | | - # Always store the methods as a list |
208 | | - if isinstance(methods, str): |
209 | | - func._api_methods = [methods] |
210 | | - else: |
211 | | - func._api_methods = methods |
212 | | - |
213 | | - @functools.wraps(func) |
214 | | - def wrapper(self, *args, **kwargs): |
215 | | - return func(*args, **kwargs) |
216 | | - |
217 | | - # Copy all tags to the wrapper |
218 | | - wrapper._api_spec_name = func._api_spec_name |
219 | | - wrapper._api_path = func._api_path |
220 | | - wrapper._api_methods = func._api_methods |
221 | | - return wrapper |
222 | | - |
223 | | - return decorator |
224 | | - |
225 | | - |
226 | | -def auto_patch_docstrings(cls): |
227 | | - original_init = cls.__init__ |
228 | | - |
229 | | - @functools.wraps(original_init) |
230 | | - def new_init(self, *args, **kwargs): |
231 | | - original_init(self, *args, **kwargs) |
232 | | - try: |
233 | | - # We instantiate our patcher and run it |
234 | | - patcher = DocstringPatcher() |
235 | | - patcher.patch(self) |
236 | | - except Exception as e: |
237 | | - print(f"Auto-patching failed: {e}") |
238 | | - |
239 | | - cls.__init__ = new_init |
240 | | - |
241 | | - return cls |
0 commit comments