{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/socorro/pulls/comments/41661002","id":41661002,"diff_hunk":"@@ -15,6 +17,49 @@ class SQLDidNotReturnSingleRow (Exception):\n     pass\n \n \n+#==============================================================================\n+class FetchAllSequence(Sequence):\n+    \"\"\"A sequence wrapper for results of a PG cursor's fetchall()\n+    that when supplied with the cursor description gives you an\n+    iterable that works the same as regular fetchall() but\n+    also offers the convenience method zipped().\n+\n+    You can use this like this::\n+\n+        >>> sql = \"select col1, col2 from some_table\"\n+        >>> cursor = connection.cursor()\n+        >>> cursor.excute(sql, ())\n+        >>> seq = FetchAllSequence(cursor.fetchall(), cursor.description)\n+        >>> seq.zipped()\n+        [{'col1': value1, 'col2': value2}, {'col1': valueA, 'col2': valueB}]\n+\n+    \"\"\"\n+\n+    def __init__(self, rows, description):\n+        self.rows = rows\n+        self.description = description\n+\n+    def __getitem__(self, index):\n+        return self.rows[index]\n+\n+    def __len__(self):\n+        return len(self.rows)\n+\n+    def __contains__(self, value):\n+        return value in self.rows\n+\n+    def __iter__(self):\n+        for x in self.rows:\n+            yield x\n+\n+    def __str__(self):\n+        return str(self.rows)\n+\n+    def zipped(self):","path":"socorro/external/postgresql/dbapi2_util.py","position":51,"original_position":51,"commit_id":"2ff4b29e5bd5aa2a10a184765f5cc616b1fa4111","original_commit_id":"2ff4b29e5bd5aa2a10a184765f5cc616b1fa4111","user":{"login":"twobraids","id":581227,"avatar_url":"https://avatars.githubusercontent.com/u/581227?v=3","gravatar_id":"","url":"https://api.github.com/users/twobraids","html_url":"https://github.com/twobraids","followers_url":"https://api.github.com/users/twobraids/followers","following_url":"https://api.github.com/users/twobraids/following{/other_user}","gists_url":"https://api.github.com/users/twobraids/gists{/gist_id}","starred_url":"https://api.github.com/users/twobraids/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twobraids/subscriptions","organizations_url":"https://api.github.com/users/twobraids/orgs","repos_url":"https://api.github.com/users/twobraids/repos","events_url":"https://api.github.com/users/twobraids/events{/privacy}","received_events_url":"https://api.github.com/users/twobraids/received_events","type":"User","site_admin":false},"body":"two wish list things here:\r\n* ```zipped``` is not a very descriptive name telling me what it does. ```iterable_with_column_names``` or something like that tells me what I'm getting.\r\n* let me optionally supply the mapping class that I want to use rather than just dict:\r\n```python\r\n   def zipped(self, mapping_class=dict):\r\n       names = [x.name for x in self.description]\r\n       return [mapping_class(zip(names, x)) for x in self.rows]\r\n```\r\nThis would allow me to do this:\r\n```python\r\nfrom socorro.lib.util import DotDict\r\nfor x in execute_query_fetch_all(some_connection, 'select a, b from sometable').zipped(DotDict):\r\n    print x.a, x.b\r\n```\r\n","created_at":"2015-10-09T18:13:14Z","updated_at":"2015-10-09T18:13:14Z","html_url":"https://github.com/mozilla/socorro/pull/3030#discussion_r41661002","pull_request_url":"https://api.github.com/repos/mozilla/socorro/pulls/3030","_links":{"self":{"href":"https://api.github.com/repos/mozilla/socorro/pulls/comments/41661002"},"html":{"href":"https://github.com/mozilla/socorro/pull/3030#discussion_r41661002"},"pull_request":{"href":"https://api.github.com/repos/mozilla/socorro/pulls/3030"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/socorro/pulls/3030","id":47293184,"html_url":"https://github.com/mozilla/socorro/pull/3030","diff_url":"https://github.com/mozilla/socorro/pull/3030.diff","patch_url":"https://github.com/mozilla/socorro/pull/3030.patch","issue_url":"https://api.github.com/repos/mozilla/socorro/issues/3030","number":3030,"state":"open","locked":false,"title":"fixes bug 1213334 - sequence for cursor.fetchall()","user":{"login":"peterbe","id":26739,"avatar_url":"https://avatars.githubusercontent.com/u/26739?v=3","gravatar_id":"","url":"https://api.github.com/users/peterbe","html_url":"https://github.com/peterbe","followers_url":"https://api.github.com/users/peterbe/followers","following_url":"https://api.github.com/users/peterbe/following{/other_user}","gists_url":"https://api.github.com/users/peterbe/gists{/gist_id}","starred_url":"https://api.github.com/users/peterbe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterbe/subscriptions","organizations_url":"https://api.github.com/users/peterbe/orgs","repos_url":"https://api.github.com/users/peterbe/repos","events_url":"https://api.github.com/users/peterbe/events{/privacy}","received_events_url":"https://api.github.com/users/peterbe/received_events","type":"User","site_admin":false},"body":"@twobraids r?\r\n\r\nThanks for the FetchAllSequence class. I really like the much shorter new code we can get out of this. ","created_at":"2015-10-09T16:37:11Z","updated_at":"2015-10-09T18:13:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"936b4d819ddf3ff914f34ad5d5d0c4d2524490dc","assignee":{"login":"twobraids","id":581227,"avatar_url":"https://avatars.githubusercontent.com/u/581227?v=3","gravatar_id":"","url":"https://api.github.com/users/twobraids","html_url":"https://github.com/twobraids","followers_url":"https://api.github.com/users/twobraids/followers","following_url":"https://api.github.com/users/twobraids/following{/other_user}","gists_url":"https://api.github.com/users/twobraids/gists{/gist_id}","starred_url":"https://api.github.com/users/twobraids/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twobraids/subscriptions","organizations_url":"https://api.github.com/users/twobraids/orgs","repos_url":"https://api.github.com/users/twobraids/repos","events_url":"https://api.github.com/users/twobraids/events{/privacy}","received_events_url":"https://api.github.com/users/twobraids/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/socorro/pulls/3030/commits","review_comments_url":"https://api.github.com/repos/mozilla/socorro/pulls/3030/comments","review_comment_url":"https://api.github.com/repos/mozilla/socorro/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/socorro/issues/3030/comments","statuses_url":"https://api.github.com/repos/mozilla/socorro/statuses/2ff4b29e5bd5aa2a10a184765f5cc616b1fa4111","head":{"label":"peterbe:bug-1213334-sequence-for-cursorfetchall","ref":"bug-1213334-sequence-for-cursorfetchall","sha":"2ff4b29e5bd5aa2a10a184765f5cc616b1fa4111","user":{"login":"peterbe","id":26739,"avatar_url":"https://avatars.githubusercontent.com/u/26739?v=3","gravatar_id":"","url":"https://api.github.com/users/peterbe","html_url":"https://github.com/peterbe","followers_url":"https://api.github.com/users/peterbe/followers","following_url":"https://api.github.com/users/peterbe/following{/other_user}","gists_url":"https://api.github.com/users/peterbe/gists{/gist_id}","starred_url":"https://api.github.com/users/peterbe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterbe/subscriptions","organizations_url":"https://api.github.com/users/peterbe/orgs","repos_url":"https://api.github.com/users/peterbe/repos","events_url":"https://api.github.com/users/peterbe/events{/privacy}","received_events_url":"https://api.github.com/users/peterbe/received_events","type":"User","site_admin":false},"repo":{"id":2920665,"name":"socorro","full_name":"peterbe/socorro","owner":{"login":"peterbe","id":26739,"avatar_url":"https://avatars.githubusercontent.com/u/26739?v=3","gravatar_id":"","url":"https://api.github.com/users/peterbe","html_url":"https://github.com/peterbe","followers_url":"https://api.github.com/users/peterbe/followers","following_url":"https://api.github.com/users/peterbe/following{/other_user}","gists_url":"https://api.github.com/users/peterbe/gists{/gist_id}","starred_url":"https://api.github.com/users/peterbe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterbe/subscriptions","organizations_url":"https://api.github.com/users/peterbe/orgs","repos_url":"https://api.github.com/users/peterbe/repos","events_url":"https://api.github.com/users/peterbe/events{/privacy}","received_events_url":"https://api.github.com/users/peterbe/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/peterbe/socorro","description":"Socorro is a server to accept and process Breakpad crash reports. ","fork":true,"url":"https://api.github.com/repos/peterbe/socorro","forks_url":"https://api.github.com/repos/peterbe/socorro/forks","keys_url":"https://api.github.com/repos/peterbe/socorro/keys{/key_id}","collaborators_url":"https://api.github.com/repos/peterbe/socorro/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/peterbe/socorro/teams","hooks_url":"https://api.github.com/repos/peterbe/socorro/hooks","issue_events_url":"https://api.github.com/repos/peterbe/socorro/issues/events{/number}","events_url":"https://api.github.com/repos/peterbe/socorro/events","assignees_url":"https://api.github.com/repos/peterbe/socorro/assignees{/user}","branches_url":"https://api.github.com/repos/peterbe/socorro/branches{/branch}","tags_url":"https://api.github.com/repos/peterbe/socorro/tags","blobs_url":"https://api.github.com/repos/peterbe/socorro/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/peterbe/socorro/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/peterbe/socorro/git/refs{/sha}","trees_url":"https://api.github.com/repos/peterbe/socorro/git/trees{/sha}","statuses_url":"https://api.github.com/repos/peterbe/socorro/statuses/{sha}","languages_url":"https://api.github.com/repos/peterbe/socorro/languages","stargazers_url":"https://api.github.com/repos/peterbe/socorro/stargazers","contributors_url":"https://api.github.com/repos/peterbe/socorro/contributors","subscribers_url":"https://api.github.com/repos/peterbe/socorro/subscribers","subscription_url":"https://api.github.com/repos/peterbe/socorro/subscription","commits_url":"https://api.github.com/repos/peterbe/socorro/commits{/sha}","git_commits_url":"https://api.github.com/repos/peterbe/socorro/git/commits{/sha}","comments_url":"https://api.github.com/repos/peterbe/socorro/comments{/number}","issue_comment_url":"https://api.github.com/repos/peterbe/socorro/issues/comments{/number}","contents_url":"https://api.github.com/repos/peterbe/socorro/contents/{+path}","compare_url":"https://api.github.com/repos/peterbe/socorro/compare/{base}...{head}","merges_url":"https://api.github.com/repos/peterbe/socorro/merges","archive_url":"https://api.github.com/repos/peterbe/socorro/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/peterbe/socorro/downloads","issues_url":"https://api.github.com/repos/peterbe/socorro/issues{/number}","pulls_url":"https://api.github.com/repos/peterbe/socorro/pulls{/number}","milestones_url":"https://api.github.com/repos/peterbe/socorro/milestones{/number}","notifications_url":"https://api.github.com/repos/peterbe/socorro/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/peterbe/socorro/labels{/name}","releases_url":"https://api.github.com/repos/peterbe/socorro/releases{/id}","created_at":"2011-12-05T23:07:30Z","updated_at":"2014-06-24T00:26:16Z","pushed_at":"2015-10-09T17:42:17Z","git_url":"git://github.com/peterbe/socorro.git","ssh_url":"git@github.com:peterbe/socorro.git","clone_url":"https://github.com/peterbe/socorro.git","svn_url":"https://github.com/peterbe/socorro","homepage":"https://wiki.mozilla.org/Socorro","size":163737,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"bd330ca536c41536b22d1f270130e62a8a72c68e","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":2263742,"name":"socorro","full_name":"mozilla/socorro","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/socorro","description":"Socorro is a server to accept and process Breakpad crash reports. ","fork":false,"url":"https://api.github.com/repos/mozilla/socorro","forks_url":"https://api.github.com/repos/mozilla/socorro/forks","keys_url":"https://api.github.com/repos/mozilla/socorro/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/socorro/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/socorro/teams","hooks_url":"https://api.github.com/repos/mozilla/socorro/hooks","issue_events_url":"https://api.github.com/repos/mozilla/socorro/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/socorro/events","assignees_url":"https://api.github.com/repos/mozilla/socorro/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/socorro/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/socorro/tags","blobs_url":"https://api.github.com/repos/mozilla/socorro/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/socorro/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/socorro/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/socorro/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/socorro/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/socorro/languages","stargazers_url":"https://api.github.com/repos/mozilla/socorro/stargazers","contributors_url":"https://api.github.com/repos/mozilla/socorro/contributors","subscribers_url":"https://api.github.com/repos/mozilla/socorro/subscribers","subscription_url":"https://api.github.com/repos/mozilla/socorro/subscription","commits_url":"https://api.github.com/repos/mozilla/socorro/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/socorro/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/socorro/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/socorro/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/socorro/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/socorro/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/socorro/merges","archive_url":"https://api.github.com/repos/mozilla/socorro/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/socorro/downloads","issues_url":"https://api.github.com/repos/mozilla/socorro/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/socorro/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/socorro/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/socorro/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/socorro/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/socorro/releases{/id}","created_at":"2011-08-24T19:21:49Z","updated_at":"2015-10-08T05:36:02Z","pushed_at":"2015-10-09T17:42:18Z","git_url":"git://github.com/mozilla/socorro.git","ssh_url":"git@github.com:mozilla/socorro.git","clone_url":"https://github.com/mozilla/socorro.git","svn_url":"https://github.com/mozilla/socorro","homepage":"https://wiki.mozilla.org/Socorro","size":192817,"stargazers_count":247,"watchers_count":247,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":130,"mirror_url":null,"open_issues_count":9,"forks":130,"open_issues":9,"watchers":247,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/socorro/pulls/3030"},"html":{"href":"https://github.com/mozilla/socorro/pull/3030"},"issue":{"href":"https://api.github.com/repos/mozilla/socorro/issues/3030"},"comments":{"href":"https://api.github.com/repos/mozilla/socorro/issues/3030/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/socorro/pulls/3030/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/socorro/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/socorro/pulls/3030/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/socorro/statuses/2ff4b29e5bd5aa2a10a184765f5cc616b1fa4111"}}}}