mirror of
https://github.com/ansible-collections/community.routeros.git
synced 2025-06-26 19:58:45 +02:00
Improve split handling. (#47)
This commit is contained in:
parent
a88f4c804b
commit
48c7920072
2 changed files with 12 additions and 7 deletions
3
changelogs/fragments/47-api-split.yml
Normal file
3
changelogs/fragments/47-api-split.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
bugfixes:
|
||||||
|
- "api - improve splitting of ``WHERE`` queries (https://github.com/ansible-collections/community.routeros/pull/47)."
|
||||||
|
- "api - when converting result lists to dictionaries, no longer removes second ``=`` and text following that if present (https://github.com/ansible-collections/community.routeros/pull/47)."
|
|
@ -321,12 +321,14 @@ class ROS_api_module:
|
||||||
self.where = None
|
self.where = None
|
||||||
self.query = self.module.params['query']
|
self.query = self.module.params['query']
|
||||||
if self.query:
|
if self.query:
|
||||||
if 'WHERE' in self.query:
|
self.query = self.list_remove_empty(self.query.split(' '))
|
||||||
split = self.query.split('WHERE')
|
try:
|
||||||
self.query = self.list_remove_empty(split[0].split(' '))
|
idx = self.query.index('WHERE')
|
||||||
self.where = self.list_remove_empty(split[1].split(' '))
|
self.where = self.query[idx + 1:]
|
||||||
else:
|
self.query = self.query[:idx]
|
||||||
self.query = self.list_remove_empty(self.module.params['query'].split(' '))
|
except ValueError:
|
||||||
|
# Raised when WHERE has not been found
|
||||||
|
pass
|
||||||
|
|
||||||
self.result = dict(
|
self.result = dict(
|
||||||
message=[])
|
message=[])
|
||||||
|
@ -358,7 +360,7 @@ class ROS_api_module:
|
||||||
for p in ldict:
|
for p in ldict:
|
||||||
if '=' not in p:
|
if '=' not in p:
|
||||||
self.errors("missing '=' after '%s'" % p)
|
self.errors("missing '=' after '%s'" % p)
|
||||||
p = p.split('=')
|
p = p.split('=', 1)
|
||||||
if p[1]:
|
if p[1]:
|
||||||
dict[p[0]] = p[1]
|
dict[p[0]] = p[1]
|
||||||
return dict
|
return dict
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue