@@ -154,8 +154,7 @@ def get(
154
154
request = proto .gnmi_pb2 .GetRequest ()
155
155
if not isinstance (paths , (list , set )):
156
156
raise Exception ("paths must be an iterable containing Path(s)!" )
157
- for path in paths :
158
- request .path .append (path )
157
+ request .path .extend (paths )
159
158
request .type = data_type
160
159
request .encoding = encoding
161
160
if prefix :
@@ -201,17 +200,13 @@ def set(
201
200
if not isinstance (item , (list , set )):
202
201
raise Exception ("updates, replaces, and deletes must be iterables!" )
203
202
if updates :
204
- for update in updates :
205
- request .update .append (update )
203
+ request .update .extend (updates )
206
204
if replaces :
207
- for update in replaces :
208
- request .replace .append (update )
205
+ request .replaces .extend (replaces )
209
206
if deletes :
210
- for path in deletes :
211
- request .delete .append (path )
207
+ request .delete .extend (deletes )
212
208
if extensions :
213
- for extension in extensions :
214
- request .extension .append (extension )
209
+ request .extension .extend (extensions )
215
210
response = self .service .Set (request )
216
211
return response
217
212
@@ -248,8 +243,7 @@ def validate_request(request):
248
243
"request must be a SubscriptionList, Poll, or AliasList!"
249
244
)
250
245
if extensions :
251
- for extension in extensions :
252
- subscribe_request .extensions .append (extension )
246
+ subscribe_request .extensions .extend (extensions )
253
247
return subscribe_request
254
248
255
249
response_stream = self .service .Subscribe (
@@ -280,14 +274,15 @@ def parse_xpath_to_gnmi_path(self, xpath, origin=None):
280
274
# TODO: Lazy
281
275
xpath = xpath .strip ("/" )
282
276
xpath_elements = xpath_tokenizer_re .findall (xpath )
277
+ path_elems = []
283
278
for index , element in enumerate (xpath_elements ):
284
279
# stripped initial /, so this indicates a completed element
285
280
if element [0 ] == "/" :
286
281
if not curr_elem .name :
287
282
raise Exception (
288
283
"Current PathElem has no name yet is trying to be pushed to path! Invalid XPath?"
289
284
)
290
- path . elem .append (curr_elem )
285
+ path_elems .append (curr_elem )
291
286
curr_elem = proto .gnmi_pb2 .PathElem ()
292
287
continue
293
288
# We are entering a filter
@@ -333,8 +328,9 @@ def parse_xpath_to_gnmi_path(self, xpath, origin=None):
333
328
# If we have a dangling element that hasn't been completed due to no
334
329
# / element then let's just append the final element.
335
330
if curr_elem :
336
- path . elem .append (curr_elem )
331
+ path_elems .append (curr_elem )
337
332
curr_elem = None
338
333
if any ([curr_elem , curr_key , in_filter ]):
339
334
raise Exception ("Unfinished elements in XPath parsing!" )
335
+ path .elem .extend (path_elems )
340
336
return path
0 commit comments