{"action":"opened","issue":{"url":"https://api.github.com/repos/robshakir/pyangbind/issues/73","repository_url":"https://api.github.com/repos/robshakir/pyangbind","labels_url":"https://api.github.com/repos/robshakir/pyangbind/issues/73/labels{/name}","comments_url":"https://api.github.com/repos/robshakir/pyangbind/issues/73/comments","events_url":"https://api.github.com/repos/robshakir/pyangbind/issues/73/events","html_url":"https://github.com/robshakir/pyangbind/issues/73","id":161926003,"number":73,"title":"Bug accessing elements using obj['key'] scheme","user":{"login":"lgifre","id":11629086,"avatar_url":"https://avatars.githubusercontent.com/u/11629086?v=3","gravatar_id":"","url":"https://api.github.com/users/lgifre","html_url":"https://github.com/lgifre","followers_url":"https://api.github.com/users/lgifre/followers","following_url":"https://api.github.com/users/lgifre/following{/other_user}","gists_url":"https://api.github.com/users/lgifre/gists{/gist_id}","starred_url":"https://api.github.com/users/lgifre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lgifre/subscriptions","organizations_url":"https://api.github.com/users/lgifre/orgs","repos_url":"https://api.github.com/users/lgifre/repos","events_url":"https://api.github.com/users/lgifre/events{/privacy}","received_events_url":"https://api.github.com/users/lgifre/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-06-23T13:42:33Z","updated_at":"2016-06-23T13:42:33Z","closed_at":null,"body":"Hi Rob,\r\n\r\nIn the application I'm developing, I need to navigate through a datastore using a path that is not known in advance. Then, when an object is found, I need to modify that object. To implement this functionality I considered using a scheme such as that proposed by you in the tutorial: obj[\"local-routes\"][\"static-routes\"][\"static\"][\"192.0.2.1/32\"]. However, this scheme reports an exception.\r\n\r\nLet me illustrate what I want to do with an example:\r\n\r\nAssume we have the next simple model:\r\n```\r\nmodule local-routing {\r\n  namespace \"urn:local-routing:local-routing\";\r\n  prefix \"t\";\r\n  container local-routes {\r\n    list static {\r\n      key prefix;\r\n      leaf prefix { type string; }\r\n      leaf next-hop { type string; }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nWe generate the Python bindings using:\r\n```\r\nexport PYBINDPLUGIN=`/usr/bin/env python -c 'import pyangbind; import os; print \"%s/plugin\" % os.path.dirname(pyangbind.__file__)'`\r\npyang -V --plugindir $PYBINDPLUGIN -f pybind -o local_routing.py local-routing.yang\r\n```\r\n\r\nAssume that we pre-loaded the datamodel using the next code:\r\n```\r\nfrom local_routing import local_routing\r\nimport pyangbind.lib.pybindJSON as pybindJSON\r\nlr = local_routing()\r\nrt1 = lr.local_routes.static.add(\"192.0.1.0\")\r\nrt1.next_hop = \"192.0.0.1\"\r\n```\r\n\r\nSo a dump with `print pybindJSON.dumps(lr, filter=False)` reports:\r\n```\r\n{\r\n    \"local-routes\": {\r\n        \"static\": {\r\n            \"192.0.1.0\": {\r\n                \"next-hop\": \"192.0.0.1\", \r\n                \"prefix\": \"192.0.1.0\"\r\n            }\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nThen, given an input path in a string variable, split the route into its parts and adapt the names to your internal representation:\r\n```\r\npath = \"/local-routes/static/192.0.1.0\"\r\npathHops = path.split('/')\r\npathHops = filter(lambda x: len(x) > 0, pathHops)\r\npathHops = map(lambda x: x.replace('-', '_'), pathHops)\r\nprint pathHops # reports: ['local_routes', 'static', '192.0.1.0']\r\n```\r\n\r\nThen starting from the root, we navigate to the desired element:\r\n```\r\nptr = lr # lr is the root object in the pre-loading code\r\nfor pathHop in pathHops:\r\n  ptr = ptr[pathHop]\r\n```\r\n\r\nThis code reports the next Exception:\r\n```\r\nTraceback (most recent call last):\r\n  File \"Main.py\", line 21, in <module>\r\n    ptr = ptr[pathHop]\r\n  File \"/usr/local/lib/python2.7/dist-packages/pyangbind/lib/base.py\", line 88, in __getitem__\r\n    return element()\r\nTypeError: 'YANGBaseClass' object is not callable\r\n```\r\n\r\nI think the problem is with that `()` in `return element()`. I tried removing such `()` and seems to work, but I do not know whether I'm breaking some other things.\r\n\r\nCould you confirm that it is a bug and that is the right way to navigate through the datastore?\r\n\r\nTIA.\r\nLluis\r\n"}}
{"actor":{"display_login":"lgifre"}}