Ticket #99: patch.txt

File patch.txt, 1.4 KB (added by Zooko, 16 years ago)
Line 
1diff -r 286ad1fa42a0 foolscap/logging/log.py
2--- a/foolscap/logging/log.py   Sat Sep 20 10:40:38 2008 -0700
3+++ b/foolscap/logging/log.py   Mon Oct 13 10:22:53 2008 -0600
4@@ -1,6 +1,5 @@
5 
6 import os, sys, time, pickle, weakref
7-import itertools
8 import traceback
9 import collections
10 from twisted.python import log as twisted_log
11@@ -33,6 +32,21 @@ def format_message(e):
12         return e.get('message', "[no message]") + " [formatting failed]"
13 
14 
15+class Count:
16+    """
17+    This class counts up from zero, just like the Python docs claim that itertools.count() does, but this class does not overflow with an error like itertools.count() does:
18+
19+      File "/usr/lib/python2.5/site-packages/foolscap/logging/log.py", line 137, in msg
20+          num = self.seqnum.next()
21+      exceptions.OverflowError: cannot count beyond PY_SSIZE_T_MAX
22+    """
23+    def __init__(self):
24+        self.n = -1
25+
26+    def next(self):
27+        self.n += 1
28+        return self.n
29+
30 class FoolscapLogger:
31     DEFAULT_SIZELIMIT = 100
32     DEFAULT_THRESHOLD = NOISY
33@@ -40,7 +54,7 @@ class FoolscapLogger:
34 
35     def __init__(self):
36         self.incarnation = self.get_incarnation()
37-        self.seqnum = itertools.count(0)
38+        self.seqnum = Count()
39         self.facility_explanations = {}
40         self.buffer_sizes = {} # k: facility or None, v: dict(level->sizelimit)
41         self.buffer_sizes[None] = {}