Skip to content

Commit

Permalink
Fixed issue 786
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan Gorelik committed Jun 6, 2018
1 parent c2d2fe5 commit b257cdb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 29 deletions.
2 changes: 1 addition & 1 deletion sdk/python/core/tests/test_sanity_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def test_embedded_single_quote_list_key(self):
def test_embedded_double_quote_list_key(self):
r = Runner()
t = Runner.TwoKeyList()
t.first = "ab"c"
t.first = 'ab"c'
t.second = 1233
r.two_key_list.append(t)
self.crud.create(self.ncc, r)
Expand Down
6 changes: 4 additions & 2 deletions sdk/python/core/ydk/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ------------------------------------------------------------------

from .py_types import Entity, EntityCollection, Config, Filter, YList, YLeafList
from .py_types import Entity, EntityCollection, Config, Filter, YList, YLeafList, _add_key_token
from ydk.ext.types import Bits
from ydk.ext.types import ChildrenMap
from ydk.ext.types import ModelCachingOption
Expand Down Expand Up @@ -47,4 +47,6 @@
"LeafDataList",
"YLeaf",
"YLeafList",
"YType" ]
"YType",
"_add_key_token",
]
8 changes: 8 additions & 0 deletions sdk/python/core/ydk/types/py_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,11 @@ def __getitem__(self, item):

def __len__(self):
return self._entity_map.__len__() + self._cache_dict.__len__()

def _add_key_token(attr, attr_name):
attr_str = format(attr)
if "'" in attr_str:
token = '[{}="{}"]'.format(attr_name, attr_str)
else:
token = "[{}='{}']".format(attr_name, attr_str)
return token
33 changes: 8 additions & 25 deletions ydkgen/printer/python/class_get_entity_path_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,28 @@ def print_output(self, clazz):
self._print_get_ydk_segment_path_body(clazz)

def _print_get_ydk_segment_path_body(self, clazz):
path='"'
path="'"
if clazz.owner is not None:
if isinstance(clazz.owner, Package):
path+= clazz.owner.stmt.arg + ':'
elif clazz.owner.stmt.i_module.arg != clazz.stmt.i_module.arg:
path+=clazz.stmt.i_module.arg + ':'

path+= clazz.stmt.arg
path+='"'
predicates = ''
path+="'"
insert_token = ' + '

key_props = clazz.get_key_props()
for key_prop in key_props:
predicates += insert_token

predicates += '"['
key_name = ''
if key_prop.stmt.i_module.arg != clazz.stmt.i_module.arg:
predicates += key_prop.stmt.i_module.arg
predicates += ':'
key_name += key_prop.stmt.i_module.arg
key_name += ':'
key_name += key_prop.stmt.arg

predicates += key_prop.stmt.arg + '='

predicates += "'"

predicates +='"'

predicates += insert_token

predicates += ('str(self.%s)') % key_prop.name + insert_token

predicates += '"'

predicates += "'"

predicates += ']"'

path = '%s%s' % (path, predicates)

path += insert_token
path += "_add_key_token(self.%s, '%s')" % (key_prop.name, key_name)

self.ctx.writeln("self._segment_path = lambda: %s" % path)

Expand Down
2 changes: 1 addition & 1 deletion ydkgen/printer/python/module_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def print_header(self, package):

self.ctx.writeln("from collections import OrderedDict")
self.ctx.bline()
self.ctx.writeln("from ydk.types import Entity, EntityPath, Identity, Enum, YType, YLeaf, YLeafList, YList, LeafDataList, Bits, Empty, Decimal64")
self.ctx.writeln("from ydk.types import Entity, EntityPath, Identity, Enum, YType, YLeaf, YLeafList, YList, LeafDataList, Bits, Empty, Decimal64, _add_key_token")
self.ctx.writeln("from ydk.filters import YFilter")
self.ctx.writeln("from ydk.errors import YError, YModelError")
self.ctx.writeln("from ydk.errors.error_handler import handle_type_error as _handle_type_error")
Expand Down

0 comments on commit b257cdb

Please sign in to comment.