{"action":"created","comment":{"url":"https://api.github.com/repos/construct/construct/pulls/comments/83922076","pull_request_review_id":4733435,"id":83922076,"diff_hunk":"@@ -1,6 +1,7 @@\n # -*- coding: utf-8 -*-\n \n import struct as packer\n+from operator import attrgetter","path":"construct/core.py","position":4,"original_position":4,"commit_id":"9bd0927afe09c2126c3cd192e3357baad95710f3","original_commit_id":"9bd0927afe09c2126c3cd192e3357baad95710f3","user":{"login":"arekbulski","id":5385838,"avatar_url":"https://avatars.githubusercontent.com/u/5385838?v=3","gravatar_id":"","url":"https://api.github.com/users/arekbulski","html_url":"https://github.com/arekbulski","followers_url":"https://api.github.com/users/arekbulski/followers","following_url":"https://api.github.com/users/arekbulski/following{/other_user}","gists_url":"https://api.github.com/users/arekbulski/gists{/gist_id}","starred_url":"https://api.github.com/users/arekbulski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arekbulski/subscriptions","organizations_url":"https://api.github.com/users/arekbulski/orgs","repos_url":"https://api.github.com/users/arekbulski/repos","events_url":"https://api.github.com/users/arekbulski/events{/privacy}","received_events_url":"https://api.github.com/users/arekbulski/received_events","type":"User","site_admin":false},"body":"To be removed.","created_at":"2016-10-18T18:37:50Z","updated_at":"2016-10-18T18:37:50Z","html_url":"https://github.com/construct/construct/pull/253#discussion_r83922076","pull_request_url":"https://api.github.com/repos/construct/construct/pulls/253","_links":{"self":{"href":"https://api.github.com/repos/construct/construct/pulls/comments/83922076"},"html":{"href":"https://github.com/construct/construct/pull/253#discussion_r83922076"},"pull_request":{"href":"https://api.github.com/repos/construct/construct/pulls/253"}}},"pull_request":{"url":"https://api.github.com/repos/construct/construct/pulls/253","id":89800315,"html_url":"https://github.com/construct/construct/pull/253","diff_url":"https://github.com/construct/construct/pull/253.diff","patch_url":"https://github.com/construct/construct/pull/253.patch","issue_url":"https://api.github.com/repos/construct/construct/issues/253","number":253,"state":"open","locked":false,"title":"Allow a Union with an Embedded Struct to be parsed correctly","user":{"login":"beardypig","id":16033421,"avatar_url":"https://avatars.githubusercontent.com/u/16033421?v=3","gravatar_id":"","url":"https://api.github.com/users/beardypig","html_url":"https://github.com/beardypig","followers_url":"https://api.github.com/users/beardypig/followers","following_url":"https://api.github.com/users/beardypig/following{/other_user}","gists_url":"https://api.github.com/users/beardypig/gists{/gist_id}","starred_url":"https://api.github.com/users/beardypig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beardypig/subscriptions","organizations_url":"https://api.github.com/users/beardypig/orgs","repos_url":"https://api.github.com/users/beardypig/repos","events_url":"https://api.github.com/users/beardypig/events{/privacy}","received_events_url":"https://api.github.com/users/beardypig/received_events","type":"User","site_admin":false},"body":"There was a bug in `Union` where an `Embedded` field could not be used as part of a `Union`. \r\nThis PR fixes that bug, and adds some tests to that behaviour.\r\n\r\nThere is an issue with building a `Union` with an `Embedded` field, as `Embedded` fields do not have names, they cannot be looked up when using `buildfrom` - this is generally fine, but it would be possible to add support for `buildfrom` with an index. eg.\r\n```python\r\nUnion(\"a\" / Int16ub, Embedded(Struct(\"b\" / Int8ub, \"c\" / Int8ub), buildfrom=1).build(dict(a=1, b=2)) \r\n```\r\nby applying the following patch:\r\n\r\n```diff\r\ndiff --git a/construct/core.py b/construct/core.py\r\nindex 7720c50..87c0faf 100644\r\n--- a/construct/core.py\r\n+++ b/construct/core.py\r\n@@ -1398,7 +1399,14 @@ class Union(Construct):\r\n                 raise UnionError(\"none of subcons %s were found in the dictionary %s\" % (self.subcons, obj))\r\n         if isinstance(self.buildfrom, int):\r\n             sc = self.subcons[self.buildfrom]\r\n-            return sc.subcon._build(obj[sc.name], stream, context, path)\r\n+            if sc.flagembedded:\r\n+                try:\r\n+                    data = dict([(field.name, obj[field.name]) for field in sc.subcon.subcon.subcons])\r\n+                except KeyError as ke:\r\n+                    raise UnionError(\"unable to find key: %r when building Embedded Construct\" % ke)\r\n+            else:\r\n+                data = obj[sc.name]\r\n+            return sc.subcon._build(data, stream, context, path)\r\n```\r\n","created_at":"2016-10-18T11:58:02Z","updated_at":"2016-10-18T18:37:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"730909cd6d3c06e1ecc1f4cb129073fabbb8c6ea","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/construct/construct/pulls/253/commits","review_comments_url":"https://api.github.com/repos/construct/construct/pulls/253/comments","review_comment_url":"https://api.github.com/repos/construct/construct/pulls/comments{/number}","comments_url":"https://api.github.com/repos/construct/construct/issues/253/comments","statuses_url":"https://api.github.com/repos/construct/construct/statuses/9bd0927afe09c2126c3cd192e3357baad95710f3","head":{"label":"beardypig:union_embedded","ref":"union_embedded","sha":"9bd0927afe09c2126c3cd192e3357baad95710f3","user":{"login":"beardypig","id":16033421,"avatar_url":"https://avatars.githubusercontent.com/u/16033421?v=3","gravatar_id":"","url":"https://api.github.com/users/beardypig","html_url":"https://github.com/beardypig","followers_url":"https://api.github.com/users/beardypig/followers","following_url":"https://api.github.com/users/beardypig/following{/other_user}","gists_url":"https://api.github.com/users/beardypig/gists{/gist_id}","starred_url":"https://api.github.com/users/beardypig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beardypig/subscriptions","organizations_url":"https://api.github.com/users/beardypig/orgs","repos_url":"https://api.github.com/users/beardypig/repos","events_url":"https://api.github.com/users/beardypig/events{/privacy}","received_events_url":"https://api.github.com/users/beardypig/received_events","type":"User","site_admin":false},"repo":{"id":70804970,"name":"construct","full_name":"beardypig/construct","owner":{"login":"beardypig","id":16033421,"avatar_url":"https://avatars.githubusercontent.com/u/16033421?v=3","gravatar_id":"","url":"https://api.github.com/users/beardypig","html_url":"https://github.com/beardypig","followers_url":"https://api.github.com/users/beardypig/followers","following_url":"https://api.github.com/users/beardypig/following{/other_user}","gists_url":"https://api.github.com/users/beardypig/gists{/gist_id}","starred_url":"https://api.github.com/users/beardypig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beardypig/subscriptions","organizations_url":"https://api.github.com/users/beardypig/orgs","repos_url":"https://api.github.com/users/beardypig/repos","events_url":"https://api.github.com/users/beardypig/events{/privacy}","received_events_url":"https://api.github.com/users/beardypig/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/beardypig/construct","description":"Construct: Declarative data structures for python that allow symmetric parsing and building","fork":true,"url":"https://api.github.com/repos/beardypig/construct","forks_url":"https://api.github.com/repos/beardypig/construct/forks","keys_url":"https://api.github.com/repos/beardypig/construct/keys{/key_id}","collaborators_url":"https://api.github.com/repos/beardypig/construct/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/beardypig/construct/teams","hooks_url":"https://api.github.com/repos/beardypig/construct/hooks","issue_events_url":"https://api.github.com/repos/beardypig/construct/issues/events{/number}","events_url":"https://api.github.com/repos/beardypig/construct/events","assignees_url":"https://api.github.com/repos/beardypig/construct/assignees{/user}","branches_url":"https://api.github.com/repos/beardypig/construct/branches{/branch}","tags_url":"https://api.github.com/repos/beardypig/construct/tags","blobs_url":"https://api.github.com/repos/beardypig/construct/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/beardypig/construct/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/beardypig/construct/git/refs{/sha}","trees_url":"https://api.github.com/repos/beardypig/construct/git/trees{/sha}","statuses_url":"https://api.github.com/repos/beardypig/construct/statuses/{sha}","languages_url":"https://api.github.com/repos/beardypig/construct/languages","stargazers_url":"https://api.github.com/repos/beardypig/construct/stargazers","contributors_url":"https://api.github.com/repos/beardypig/construct/contributors","subscribers_url":"https://api.github.com/repos/beardypig/construct/subscribers","subscription_url":"https://api.github.com/repos/beardypig/construct/subscription","commits_url":"https://api.github.com/repos/beardypig/construct/commits{/sha}","git_commits_url":"https://api.github.com/repos/beardypig/construct/git/commits{/sha}","comments_url":"https://api.github.com/repos/beardypig/construct/comments{/number}","issue_comment_url":"https://api.github.com/repos/beardypig/construct/issues/comments{/number}","contents_url":"https://api.github.com/repos/beardypig/construct/contents/{+path}","compare_url":"https://api.github.com/repos/beardypig/construct/compare/{base}...{head}","merges_url":"https://api.github.com/repos/beardypig/construct/merges","archive_url":"https://api.github.com/repos/beardypig/construct/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/beardypig/construct/downloads","issues_url":"https://api.github.com/repos/beardypig/construct/issues{/number}","pulls_url":"https://api.github.com/repos/beardypig/construct/pulls{/number}","milestones_url":"https://api.github.com/repos/beardypig/construct/milestones{/number}","notifications_url":"https://api.github.com/repos/beardypig/construct/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/beardypig/construct/labels{/name}","releases_url":"https://api.github.com/repos/beardypig/construct/releases{/id}","deployments_url":"https://api.github.com/repos/beardypig/construct/deployments","created_at":"2016-10-13T12:38:43Z","updated_at":"2016-10-13T12:38:44Z","pushed_at":"2016-10-18T18:26:51Z","git_url":"git://github.com/beardypig/construct.git","ssh_url":"git@github.com:beardypig/construct.git","clone_url":"https://github.com/beardypig/construct.git","svn_url":"https://github.com/beardypig/construct","homepage":"http://construct.readthedocs.org","size":1902,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"construct:master","ref":"master","sha":"a5e76e247f23065596e321fd2dded8fe49e1b103","user":{"login":"construct","id":1703836,"avatar_url":"https://avatars.githubusercontent.com/u/1703836?v=3","gravatar_id":"","url":"https://api.github.com/users/construct","html_url":"https://github.com/construct","followers_url":"https://api.github.com/users/construct/followers","following_url":"https://api.github.com/users/construct/following{/other_user}","gists_url":"https://api.github.com/users/construct/gists{/gist_id}","starred_url":"https://api.github.com/users/construct/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/construct/subscriptions","organizations_url":"https://api.github.com/users/construct/orgs","repos_url":"https://api.github.com/users/construct/repos","events_url":"https://api.github.com/users/construct/events{/privacy}","received_events_url":"https://api.github.com/users/construct/received_events","type":"Organization","site_admin":false},"repo":{"id":4218694,"name":"construct","full_name":"construct/construct","owner":{"login":"construct","id":1703836,"avatar_url":"https://avatars.githubusercontent.com/u/1703836?v=3","gravatar_id":"","url":"https://api.github.com/users/construct","html_url":"https://github.com/construct","followers_url":"https://api.github.com/users/construct/followers","following_url":"https://api.github.com/users/construct/following{/other_user}","gists_url":"https://api.github.com/users/construct/gists{/gist_id}","starred_url":"https://api.github.com/users/construct/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/construct/subscriptions","organizations_url":"https://api.github.com/users/construct/orgs","repos_url":"https://api.github.com/users/construct/repos","events_url":"https://api.github.com/users/construct/events{/privacy}","received_events_url":"https://api.github.com/users/construct/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/construct/construct","description":"Construct: Declarative data structures for python that allow symmetric parsing and building","fork":true,"url":"https://api.github.com/repos/construct/construct","forks_url":"https://api.github.com/repos/construct/construct/forks","keys_url":"https://api.github.com/repos/construct/construct/keys{/key_id}","collaborators_url":"https://api.github.com/repos/construct/construct/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/construct/construct/teams","hooks_url":"https://api.github.com/repos/construct/construct/hooks","issue_events_url":"https://api.github.com/repos/construct/construct/issues/events{/number}","events_url":"https://api.github.com/repos/construct/construct/events","assignees_url":"https://api.github.com/repos/construct/construct/assignees{/user}","branches_url":"https://api.github.com/repos/construct/construct/branches{/branch}","tags_url":"https://api.github.com/repos/construct/construct/tags","blobs_url":"https://api.github.com/repos/construct/construct/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/construct/construct/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/construct/construct/git/refs{/sha}","trees_url":"https://api.github.com/repos/construct/construct/git/trees{/sha}","statuses_url":"https://api.github.com/repos/construct/construct/statuses/{sha}","languages_url":"https://api.github.com/repos/construct/construct/languages","stargazers_url":"https://api.github.com/repos/construct/construct/stargazers","contributors_url":"https://api.github.com/repos/construct/construct/contributors","subscribers_url":"https://api.github.com/repos/construct/construct/subscribers","subscription_url":"https://api.github.com/repos/construct/construct/subscription","commits_url":"https://api.github.com/repos/construct/construct/commits{/sha}","git_commits_url":"https://api.github.com/repos/construct/construct/git/commits{/sha}","comments_url":"https://api.github.com/repos/construct/construct/comments{/number}","issue_comment_url":"https://api.github.com/repos/construct/construct/issues/comments{/number}","contents_url":"https://api.github.com/repos/construct/construct/contents/{+path}","compare_url":"https://api.github.com/repos/construct/construct/compare/{base}...{head}","merges_url":"https://api.github.com/repos/construct/construct/merges","archive_url":"https://api.github.com/repos/construct/construct/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/construct/construct/downloads","issues_url":"https://api.github.com/repos/construct/construct/issues{/number}","pulls_url":"https://api.github.com/repos/construct/construct/pulls{/number}","milestones_url":"https://api.github.com/repos/construct/construct/milestones{/number}","notifications_url":"https://api.github.com/repos/construct/construct/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/construct/construct/labels{/name}","releases_url":"https://api.github.com/repos/construct/construct/releases{/id}","deployments_url":"https://api.github.com/repos/construct/construct/deployments","created_at":"2012-05-03T20:54:12Z","updated_at":"2016-10-16T09:07:38Z","pushed_at":"2016-10-18T18:26:52Z","git_url":"git://github.com/construct/construct.git","ssh_url":"git@github.com:construct/construct.git","clone_url":"https://github.com/construct/construct.git","svn_url":"https://github.com/construct/construct","homepage":"http://construct.readthedocs.org","size":2628,"stargazers_count":231,"watchers_count":231,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":50,"mirror_url":null,"open_issues_count":7,"forks":50,"open_issues":7,"watchers":231,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/construct/construct/pulls/253"},"html":{"href":"https://github.com/construct/construct/pull/253"},"issue":{"href":"https://api.github.com/repos/construct/construct/issues/253"},"comments":{"href":"https://api.github.com/repos/construct/construct/issues/253/comments"},"review_comments":{"href":"https://api.github.com/repos/construct/construct/pulls/253/comments"},"review_comment":{"href":"https://api.github.com/repos/construct/construct/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/construct/construct/pulls/253/commits"},"statuses":{"href":"https://api.github.com/repos/construct/construct/statuses/9bd0927afe09c2126c3cd192e3357baad95710f3"}}}}
{"actor":{"display_login":"arekbulski"}}