{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/151","labels_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/151/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/151/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/151/events","html_url":"https://github.com/elastic/elasticsearch-dsl-py/issues/151","id":73442316,"number":151,"title":"Suggestion for result.rget('@badpyname.thisotherthing.thatotherthing')","user":{"login":"kputland","id":1480163,"avatar_url":"https://avatars.githubusercontent.com/u/1480163?v=3","gravatar_id":"","url":"https://api.github.com/users/kputland","html_url":"https://github.com/kputland","followers_url":"https://api.github.com/users/kputland/followers","following_url":"https://api.github.com/users/kputland/following{/other_user}","gists_url":"https://api.github.com/users/kputland/gists{/gist_id}","starred_url":"https://api.github.com/users/kputland/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kputland/subscriptions","organizations_url":"https://api.github.com/users/kputland/orgs","repos_url":"https://api.github.com/users/kputland/repos","events_url":"https://api.github.com/users/kputland/events{/privacy}","received_events_url":"https://api.github.com/users/kputland/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-05-05T21:52:42Z","updated_at":"2015-06-17T00:23:15Z","closed_at":"2015-06-17T00:18:46Z","body":"```python\r\ndef rget(d, key, default=None):\r\n    if type(key) == type(''):\r\n        key = key.split('.')\r\n    a = key.pop(0)\r\n    v = d.get(a,None)\r\n    if not v:\r\n        keys = d.keys()\r\n        keys.sort()\r\n        k = [ x for x in keys if x.lower() == a.lower() ]\r\n        vl = [ d.get(x,None) for x in k ]\r\n        v = [ x for x in vl if x ]\r\n        v = v and v[0] or None\r\n    if v and type(v) == type(d) and key:\r\n        return rget(v, key, default)\r\n    elif v and key:\r\n        # Nothing exists deeper yet there are still names to find\r\n        # short curcuit the recursion and return None as there\r\n        # is nothing to find\r\n        return None\r\n    else:\r\n        return v\r\n\r\ndef test():\r\n    d={\r\n        'a': {\r\n            'c': {'d': 'D'},\r\n            'b': 'B'\r\n        },\r\n        'l': [\r\n            'a',\r\n            'b',\r\n            'c'\r\n        ],\r\n        'L': 'foo',\r\n        'ab':'ab',\r\n        'aB':'aB',\r\n    }\r\n    tests=[\r\n        ('a', 'a exists and is correct case', {'c':{'d':'D'},'b':'B'}),\r\n        ('A', 'A exists as a - match case insensitive', {'c':{'d':'D'},'b':'B'}),\r\n        ('b', 'b does not exist return None', None),\r\n        ('a.b', 'a.b exists and is correct case', 'B'),\r\n        ('a.B', 'a.B exists as a.b - match case insesitive', 'B'),\r\n        ('l', 'l exists as l', ['a','b','c']),\r\n        ('L', 'L exists as L', 'foo'),\r\n        ('L', 'L exists as l should FAIL', ['a','b','c']),\r\n        ('ab', 'ab exists and is correct', 'ab'),\r\n        ('aB', 'aB esists and is correct', 'aB'),\r\n        ('AB', 'AB does not exist return aB as caps sort before lower', 'aB'),\r\n        ('Ab', 'Ab does not exist return aB as caps sort before lower', 'aB'),\r\n        ('a.b.c.d.e.f', 'deep non existant name past a.b which exists', None),\r\n        ('b.c.d.e.f', 'deep non existant name with no existint parent', None),\r\n    ]\r\n    for a,t,r in tests:\r\n        v = rget(d,a)\r\n        sys.stderr.write('{:60s}: rget(d, \\'{}\\'): {}\\n'.format(t, a, v == r and 'PASS' or 'FAIL'))\r\n        if v != r:\r\n            sys.stderr.write('\\texpected: {}\\n\\treceived: {}\\n'.format(r,v))\r\n\r\ntest()\r\n```"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/comments/112609326","html_url":"https://github.com/elastic/elasticsearch-dsl-py/issues/151#issuecomment-112609326","issue_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/151","id":112609326,"user":{"login":"kputland","id":1480163,"avatar_url":"https://avatars.githubusercontent.com/u/1480163?v=3","gravatar_id":"","url":"https://api.github.com/users/kputland","html_url":"https://github.com/kputland","followers_url":"https://api.github.com/users/kputland/followers","following_url":"https://api.github.com/users/kputland/following{/other_user}","gists_url":"https://api.github.com/users/kputland/gists{/gist_id}","starred_url":"https://api.github.com/users/kputland/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kputland/subscriptions","organizations_url":"https://api.github.com/users/kputland/orgs","repos_url":"https://api.github.com/users/kputland/repos","events_url":"https://api.github.com/users/kputland/events{/privacy}","received_events_url":"https://api.github.com/users/kputland/received_events","type":"User","site_admin":false},"created_at":"2015-06-17T00:23:15Z","updated_at":"2015-06-17T00:23:15Z","body":"Ok. As long as the __getitem__ returns a wrapped value then that works. I\nhacked quite a bit on this for another project and it breaks down when you\nstart introducing digit indexes to lists in the string for a recursive\ngetitem\nOn Jun 16, 2015 6:18 PM, \"Honza Král\" <notifications@github.com> wrote:\n\n> I am sorry, the longer I look at this issue the more I doubt we should do\n> anything like that.\n>\n> Now you can do f['@this'].is.a.long.bad.name and that ought to be enough\n> - if we tried to implement more things would get very messy. I am closing\n> this issue.\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/elastic/elasticsearch-dsl-py/issues/151#issuecomment-112608905>\n> .\n>\n"}}