[tor-bugs] #5367 [BridgeDB]: python gotcha: mutable type in __init__()

Tor Bug Tracker & Wiki torproject-admin at torproject.org
Tue May 1 19:20:49 UTC 2012


#5367: python gotcha: mutable type in __init__()
----------------------+-----------------------------------------------------
 Reporter:  aagbsn    |          Owner:  aagbsn      
     Type:  defect    |         Status:  needs_review
 Priority:  normal    |      Milestone:              
Component:  BridgeDB  |        Version:              
 Keywords:            |         Parent:              
   Points:            |   Actualpoints:              
----------------------+-----------------------------------------------------
Changes (by aagbsn):

  * status:  new => needs_review


Comment:

 Simple fix:

 {{{
 diff --git a/lib/bridgedb/Server.py b/lib/bridgedb/Server.py
 index a1b837a..b67edf2 100644
 --- a/lib/bridgedb/Server.py
 +++ b/lib/bridgedb/Server.py
 @@ -50,7 +50,7 @@ class WebResource(twisted.web.resource.Resource):
      def __init__(self, distributor, schedule, N=1,
 useForwardedHeader=False,
                   includeFingerprints=True,
                   useRecaptcha=False,recaptchaPrivKey='',
 recaptchaPubKey='',
 -                 domains=[]):
 +                 domains=None):
          """Create a new WebResource.
               distributor -- an IPBasedDistributor object
               schedule -- an IntervalSchedule object
 @@ -63,6 +63,9 @@ class WebResource(twisted.web.resource.Resource):
          self.nBridgesToGive = N
          self.useForwardedHeader = useForwardedHeader
          self.includeFingerprints = includeFingerprints
 +
 +        # do not use mutable types as __init__ defaults!
 +        if not domains: domains = []
          self.domains = domains

          # recaptcha options
 }}}

 https://gitweb.torproject.org/user/aagbsn/bridgedb.git/commit/aba290f8e3a1eaa38bfd580d350e0721911b49da

-- 
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/5367#comment:1>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list