Merge lp:~abentley/launchpad/fix-groupby into lp:launchpad

Proposed by Aaron Bentley on 2010-09-22
Status: Merged
Merged at revision: 11628
Proposed branch: lp:~abentley/launchpad/fix-groupby
Merge into: lp:launchpad
Diff against target: 40 lines (+7/-6)
2 files modified
lib/lp/code/model/branchmergeproposal.py (+1/-6)
lib/lp_sitecustomize.py (+6/-0)
To merge this branch: bzr merge lp:~abentley/launchpad/fix-groupby
Reviewer Review Type Date Requested Status
Edwin Grubbs (community) code 2010-09-22 Approve on 2010-09-22
Review via email: mp+36360@code.launchpad.net

Commit message

Fix use of itertools.groupby through security proxies.

Description of the change

= Summary =
Prevent SecurityProxy from erroring when itertools.groupby is used.

== Proposed fix ==
Handle itertools.groupby like other built-in iterators.

== Pre-implementation notes ==
Pre-implementation was with gary

== Implementation details ==
_iteratorChecker is used for built-in python iterators. A shame it's got an
underscored name.

I guess I could phrase it this way:
checker.BasicTypes[itertools.groupby] = checker.BasicTypes[type(iter([]))]

But that only gets rid of the underscore, not the underlying problem that this
checker is not provided as a public interface.

== Tests ==
bin/test -t test_include_superseded_comments test_branchmergeproposal -v

== Demo and Q/A ==
None

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/code/model/branchmergeproposal.py
  lib/lp_sitecustomize.py

./lib/lp_sitecustomize.py
      22: E302 expected 2 blank lines, found 1
      27: E302 expected 2 blank lines, found 1
      37: E302 expected 2 blank lines, found 1

To post a comment you must log in.
Edwin Grubbs (edwin-grubbs) wrote :

Looks good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/model/branchmergeproposal.py'
2--- lib/lp/code/model/branchmergeproposal.py 2010-09-15 20:41:46 +0000
3+++ lib/lp/code/model/branchmergeproposal.py 2010-09-23 13:22:52 +0000
4@@ -809,12 +809,7 @@
5 branch_revision for branch_revision, revision, revision_author
6 in resultset)
7 # Now group by date created.
8- gby = groupby(branch_revisions, lambda r: r.revision.date_created)
9- # Use a generator expression to wrap the custom iterator so it doesn't
10- # get security-proxied.
11- return (
12- (date, (revision for revision in revisions))
13- for date, revisions in gby)
14+ return groupby(branch_revisions, lambda r: r.revision.date_created)
15
16
17 class BranchMergeProposalGetter:
18
19=== modified file 'lib/lp_sitecustomize.py'
20--- lib/lp_sitecustomize.py 2010-07-26 13:35:20 +0000
21+++ lib/lp_sitecustomize.py 2010-09-23 13:22:52 +0000
22@@ -4,6 +4,7 @@
23 # This file is imported by parts/scripts/sitecustomize.py, as set up in our
24 # buildout.cfg (see the "initialization" key in the "[scripts]" section).
25
26+import itertools
27 import os
28 import warnings
29 import logging
30@@ -45,6 +46,11 @@
31 os.environ['STORM_CEXTENSIONS'] = '1'
32 customizeMimetypes()
33 dont_wrap_class_and_subclasses(Branch)
34+ checker.BasicTypes[itertools.groupby] = checker._iteratorChecker
35+ # The itertools._grouper type is not exposed by name, so we must get it
36+ # through actually using itertools.groupby.
37+ grouper = type(list(itertools.groupby([0]))[0][1])
38+ checker.BasicTypes[grouper] = checker._iteratorChecker
39 silence_warnings()
40 silence_bzr_logger()
41