Changeset 491:690563fa7a32

Show
Ignore:
Timestamp:
10/13/08 12:33:38 (3 months ago)
Author:
Brian Warner <warner@allmydata.com>
branch:
default
Message:

logging: replace itertools.count() with a non-overflowing version, closes #99

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ChangeLog

    r490 r491  
    112008-10-13  Brian Warner  <warner@allmydata.com> 
     2 
     3        * foolscap/logging/log.py (Count): replace itertools.count with a 
     4        version that doesn't overflow at 2**31-1 (thanks to Zooko for the 
     5        patch). Closes #99. 
     6        (FoolscapLogger.__init__): use it 
    27 
    38        * foolscap/pb.py (Listener.startFactory): add log facility 
  • foolscap/logging/log.py

    r471 r491  
    11 
    22import os, sys, time, pickle, weakref 
    3 import itertools 
    43import traceback 
    54import collections 
     
    3433 
    3534 
     35class Count: 
     36    """A fixed version of itertools.count . 
     37 
     38    This class counts up from zero, just like the Python 2.5.2 docs claim 
     39    that itertools.count() does, but this class does not overflow with an 
     40    error like itertools.count() does: 
     41 
     42      File 'foolscap/logging/log.py', line 137, in msg 
     43          num = self.seqnum.next() 
     44      exceptions.OverflowError: cannot count beyond PY_SSIZE_T_MAX 
     45    """ 
     46 
     47    def __init__(self, firstval=0): 
     48        self.n = firstval - 1 
     49 
     50    def next(self): 
     51        self.n += 1 
     52        return self.n 
     53 
    3654class FoolscapLogger: 
    3755    DEFAULT_SIZELIMIT = 100 
     
    4159    def __init__(self): 
    4260        self.incarnation = self.get_incarnation() 
    43         self.seqnum = itertools.count(0
     61        self.seqnum = Count(
    4462        self.facility_explanations = {} 
    4563        self.buffer_sizes = {} # k: facility or None, v: dict(level->sizelimit)