-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathservice.py.twig
More file actions
70 lines (61 loc) · 2.76 KB
/
service.py.twig
File metadata and controls
70 lines (61 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from ..service import Service
from typing import List, Dict, Any
from ..exception import AppwriteException
{% set added = [] %}
{% for method in service.methods %}
{% for parameter in method.parameters.all %}
{% if parameter.type == 'file' and parameter.type not in added %}
from ..input_file import InputFile
{% set added = added|merge(['InputFile']) %}
{% endif %}
{% if parameter.enumValues is not empty%}
{% if parameter.enumName is not empty %}
{% set name = parameter.enumName %}
{% else %}
{% set name = parameter.name %}
{% endif %}
{% if name not in added %}
from ..enums.{{ name | caseSnake }} import {{ name | caseUcfirst }};
{% set added = added|merge([name]) %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
class {{ service.name | caseUcfirst }}(Service):
def __init__(self, client) -> None:
super({{ service.name | caseUcfirst }}, self).__init__(client)
{% for method in service.methods %}
def {{ method.name | caseSnake }}(self{% if method.parameters.all|length > 0 %}, {% endif %}{% for parameter in method.parameters.all %}{{ parameter.name | escapeKeyword | caseSnake }}: {{ parameter | getPropertyType(method) | raw }}{% if not parameter.required %} = None{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, on_progress = None{% endif %}) -> {% if method.type == 'webAuth' %}str{% elseif method.type == 'location' %}bytes{% else %}Dict[str, Any]{% endif %}:
"""
{% autoescape false %}{{ method.description | replace({"\n": "\n "}) }}{% endautoescape %}
{% if method.parameters.all|length > 0 or 'multipart/form-data' in method.consumes %}
Parameters
----------
{% for parameter in method.parameters.all %}{{ parameter.name | escapeKeyword | caseSnake }} : {{ parameter | getPropertyType(method) | raw }}
{% autoescape false %}{{ parameter.description | replace({"\n": "\n "}) }}{% endautoescape %}
{% endfor %}{% if 'multipart/form-data' in method.consumes %}
on_progress : callable, optional
Optional callback for upload progress
{% endif %}{% endif %}
Returns
-------
{% if method.type == 'webAuth' %}str
Authentication response as a string
{% elseif method.type == 'location' %}bytes
Response as bytes
{% else %}Dict[str, Any]
API response as a dictionary
{% endif %}
Raises
------
AppwriteException
If API request fails
"""
api_path = '{{ method.path }}'
{{ include('python/base/params.twig') }}
{% if 'multipart/form-data' in method.consumes %}
{{ include('python/base/requests/file.twig') }}
{% else %}
{{ include('python/base/requests/api.twig') }}
{% endif %}
{% endfor %}