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

Proposed by Aaron Bentley
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 Approve
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.
Revision history for this message
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
=== modified file 'lib/lp/code/model/branchmergeproposal.py'
--- lib/lp/code/model/branchmergeproposal.py 2010-09-15 20:41:46 +0000
+++ lib/lp/code/model/branchmergeproposal.py 2010-09-23 13:22:52 +0000
@@ -809,12 +809,7 @@
809 branch_revision for branch_revision, revision, revision_author809 branch_revision for branch_revision, revision, revision_author
810 in resultset)810 in resultset)
811 # Now group by date created.811 # Now group by date created.
812 gby = groupby(branch_revisions, lambda r: r.revision.date_created)812 return groupby(branch_revisions, lambda r: r.revision.date_created)
813 # Use a generator expression to wrap the custom iterator so it doesn't
814 # get security-proxied.
815 return (
816 (date, (revision for revision in revisions))
817 for date, revisions in gby)
818813
819814
820class BranchMergeProposalGetter:815class BranchMergeProposalGetter:
821816
=== modified file 'lib/lp_sitecustomize.py'
--- lib/lp_sitecustomize.py 2010-07-26 13:35:20 +0000
+++ lib/lp_sitecustomize.py 2010-09-23 13:22:52 +0000
@@ -4,6 +4,7 @@
4# This file is imported by parts/scripts/sitecustomize.py, as set up in our4# This file is imported by parts/scripts/sitecustomize.py, as set up in our
5# buildout.cfg (see the "initialization" key in the "[scripts]" section).5# buildout.cfg (see the "initialization" key in the "[scripts]" section).
66
7import itertools
7import os8import os
8import warnings9import warnings
9import logging10import logging
@@ -45,6 +46,11 @@
45 os.environ['STORM_CEXTENSIONS'] = '1'46 os.environ['STORM_CEXTENSIONS'] = '1'
46 customizeMimetypes()47 customizeMimetypes()
47 dont_wrap_class_and_subclasses(Branch)48 dont_wrap_class_and_subclasses(Branch)
49 checker.BasicTypes[itertools.groupby] = checker._iteratorChecker
50 # The itertools._grouper type is not exposed by name, so we must get it
51 # through actually using itertools.groupby.
52 grouper = type(list(itertools.groupby([0]))[0][1])
53 checker.BasicTypes[grouper] = checker._iteratorChecker
48 silence_warnings()54 silence_warnings()
49 silence_bzr_logger()55 silence_bzr_logger()
5056