30
30
from centraldogma .exceptions import CentralDogmaException
31
31
from centraldogma .query import Query , QueryType
32
32
33
- T = TypeVar ('T' )
33
+ T = TypeVar ("T" )
34
34
35
35
36
36
class ContentService :
37
37
def __init__ (self , client : BaseClient ):
38
38
self .client = client
39
39
40
40
def get_files (
41
- self ,
42
- project_name : str ,
43
- repo_name : str ,
44
- path_pattern : Optional [str ],
45
- revision : Optional [int ],
46
- include_content : bool = False ,
41
+ self ,
42
+ project_name : str ,
43
+ repo_name : str ,
44
+ path_pattern : Optional [str ],
45
+ revision : Optional [int ],
46
+ include_content : bool = False ,
47
47
) -> List [Content ]:
48
48
params = {"revision" : revision } if revision else None
49
49
path = f"/projects/{ project_name } /repos/{ repo_name } /"
@@ -78,11 +78,11 @@ def get_file(
78
78
return Content .from_dict (resp .json ())
79
79
80
80
def push (
81
- self ,
82
- project_name : str ,
83
- repo_name : str ,
84
- commit : Commit ,
85
- changes : List [Change ],
81
+ self ,
82
+ project_name : str ,
83
+ repo_name : str ,
84
+ commit : Commit ,
85
+ changes : List [Change ],
86
86
) -> PushResult :
87
87
params = {
88
88
"commitMessage" : asdict (commit ),
@@ -95,13 +95,19 @@ def push(
95
95
json : object = resp .json ()
96
96
return PushResult .from_dict (json )
97
97
98
- def watch_repository (self , project_name : str , repo_name : str , last_known_revision : Revision , path_pattern : str ,
99
- timeout_millis : int ) -> Optional [Revision ]:
98
+ def watch_repository (
99
+ self ,
100
+ project_name : str ,
101
+ repo_name : str ,
102
+ last_known_revision : Revision ,
103
+ path_pattern : str ,
104
+ timeout_millis : int ,
105
+ ) -> Optional [Revision ]:
100
106
path = f"/projects/{ project_name } /repos/{ repo_name } /contents"
101
107
if path_pattern [0 ] != "/" :
102
108
path += "/**/"
103
109
104
- if path_pattern in ' ' :
110
+ if path_pattern in " " :
105
111
path_pattern = path_pattern .replace (" " , "%20" )
106
112
path += path_pattern
107
113
@@ -115,8 +121,14 @@ def watch_repository(self, project_name: str, repo_name: str, last_known_revisio
115
121
# TODO(ikhoon): Handle excepitons after https://github.com/line/centraldogma-python/pull/11/ is merged.
116
122
pass
117
123
118
- def watch_file (self , project_name : str , repo_name : str , last_known_revision : Revision , query : Query [T ],
119
- timeout_millis ) -> Optional [Entry [T ]]:
124
+ def watch_file (
125
+ self ,
126
+ project_name : str ,
127
+ repo_name : str ,
128
+ last_known_revision : Revision ,
129
+ query : Query [T ],
130
+ timeout_millis ,
131
+ ) -> Optional [Entry [T ]]:
120
132
path = f"/projects/{ project_name } /repos/{ repo_name } /contents/{ query .path } "
121
133
if query .query_type == QueryType .JSON_PATH :
122
134
queries = [f"jsonpath={ quote (expr )} " for expr in query .expressions ]
@@ -143,7 +155,8 @@ def _to_entry(revision: Revision, json: Any, query_type: QueryType) -> Entry:
143
155
elif query_type == QueryType .IDENTITY or query_type == QueryType .JSON_PATH :
144
156
if received_entry_type != EntryType .JSON :
145
157
raise CentralDogmaException (
146
- f"invalid entry type. entry type: { received_entry_type } (expected: { query_type } )" )
158
+ f"invalid entry type. entry type: { received_entry_type } (expected: { query_type } )"
159
+ )
147
160
148
161
return Entry .json (revision , entry_path , content )
149
162
else : # query_type == QueryType.IDENTITY
@@ -155,16 +168,16 @@ def _to_entry(revision: Revision, json: Any, query_type: QueryType) -> Entry:
155
168
return Entry .directory (revision , entry_path )
156
169
157
170
def _watch (
158
- self ,
159
- last_known_revision : Revision ,
160
- timeout_millis : int ,
161
- path : str ) -> Response :
171
+ self , last_known_revision : Revision , timeout_millis : int , path : str
172
+ ) -> Response :
162
173
normalized_timeout = (timeout_millis + 999 ) // 1000
163
174
headers = {
164
175
"if-none-match" : f"{ last_known_revision .major } " ,
165
- "prefer" : f"wait={ normalized_timeout } "
176
+ "prefer" : f"wait={ normalized_timeout } " ,
166
177
}
167
- return self .client .request ("get" , path , headers = headers , timeout = normalized_timeout )
178
+ return self .client .request (
179
+ "get" , path , headers = headers , timeout = normalized_timeout
180
+ )
168
181
169
182
def _change_dict (self , data ):
170
183
return {
0 commit comments