Attachment 'moin15-384to386.diff'
Download 1 diff -urN moin--main--1.5--patch-384/MoinMoin/parser/rst.py moin--main--1.5--patch-386/MoinMoin/parser/rst.py
2 --- moin--main--1.5--patch-384/MoinMoin/parser/rst.py 2006-01-18 09:44:50.000000000 +0100
3 +++ moin--main--1.5--patch-386/MoinMoin/parser/rst.py 2006-01-18 09:50:15.000000000 +0100
4 @@ -14,7 +14,10 @@
5 import StringIO
6 import __builtin__
7 import sys
8 -import copy
9 +
10 +#import copy #broken, see comments at top of this file:
11 +from MoinMoin.support import copy
12 +
13 import types
14 import os
15
16 diff -urN moin--main--1.5--patch-384/MoinMoin/support/copy.py moin--main--1.5--patch-386/MoinMoin/support/copy.py
17 --- moin--main--1.5--patch-384/MoinMoin/support/copy.py 1970-01-01 01:00:00.000000000 +0100
18 +++ moin--main--1.5--patch-386/MoinMoin/support/copy.py 2006-01-18 09:50:15.000000000 +0100
19 @@ -0,0 +1,444 @@
20 +"""This is a (modified) copy of python 2.4.2 copy.py as it was broken in:
21 + Python 2.3.x, x < 5
22 + Python 2.4.x, x < 1
23 +
24 + Modifications done are minimal, so that same copy.py can work under 2.3
25 + and 2.4 python (try: ... except: ... around some set stuff).
26 +
27 +Generic (shallow and deep) copying operations.
28 +
29 +Interface summary:
30 +
31 + import copy
32 +
33 + x = copy.copy(y) # make a shallow copy of y
34 + x = copy.deepcopy(y) # make a deep copy of y
35 +
36 +For module specific errors, copy.Error is raised.
37 +
38 +The difference between shallow and deep copying is only relevant for
39 +compound objects (objects that contain other objects, like lists or
40 +class instances).
41 +
42 +- A shallow copy constructs a new compound object and then (to the
43 + extent possible) inserts *the same objects* into it that the
44 + original contains.
45 +
46 +- A deep copy constructs a new compound object and then, recursively,
47 + inserts *copies* into it of the objects found in the original.
48 +
49 +Two problems often exist with deep copy operations that don't exist
50 +with shallow copy operations:
51 +
52 + a) recursive objects (compound objects that, directly or indirectly,
53 + contain a reference to themselves) may cause a recursive loop
54 +
55 + b) because deep copy copies *everything* it may copy too much, e.g.
56 + administrative data structures that should be shared even between
57 + copies
58 +
59 +Python's deep copy operation avoids these problems by:
60 +
61 + a) keeping a table of objects already copied during the current
62 + copying pass
63 +
64 + b) letting user-defined classes override the copying operation or the
65 + set of components copied
66 +
67 +This version does not copy types like module, class, function, method,
68 +nor stack trace, stack frame, nor file, socket, window, nor array, nor
69 +any similar types.
70 +
71 +Classes can use the same interfaces to control copying that they use
72 +to control pickling: they can define methods called __getinitargs__(),
73 +__getstate__() and __setstate__(). See the documentation for module
74 +"pickle" for information on these methods.
75 +"""
76 +
77 +import types
78 +from copy_reg import dispatch_table
79 +
80 +class Error(Exception):
81 + pass
82 +error = Error # backward compatibility
83 +
84 +try:
85 + from org.python.core import PyStringMap
86 +except ImportError:
87 + PyStringMap = None
88 +
89 +__all__ = ["Error", "copy", "deepcopy"]
90 +
91 +import inspect
92 +def _getspecial(cls, name):
93 + for basecls in inspect.getmro(cls):
94 + try:
95 + return basecls.__dict__[name]
96 + except:
97 + pass
98 + else:
99 + return None
100 +
101 +def copy(x):
102 + """Shallow copy operation on arbitrary Python objects.
103 +
104 + See the module's __doc__ string for more info.
105 + """
106 +
107 + cls = type(x)
108 +
109 + copier = _copy_dispatch.get(cls)
110 + if copier:
111 + return copier(x)
112 +
113 + copier = _getspecial(cls, "__copy__")
114 + if copier:
115 + return copier(x)
116 +
117 + reductor = dispatch_table.get(cls)
118 + if reductor:
119 + rv = reductor(x)
120 + else:
121 + reductor = getattr(x, "__reduce_ex__", None)
122 + if reductor:
123 + rv = reductor(2)
124 + else:
125 + reductor = getattr(x, "__reduce__", None)
126 + if reductor:
127 + rv = reductor()
128 + else:
129 + copier = getattr(x, "__copy__", None)
130 + if copier:
131 + return copier()
132 + raise Error("un(shallow)copyable object of type %s" % cls)
133 +
134 + return _reconstruct(x, rv, 0)
135 +
136 +
137 +_copy_dispatch = d = {}
138 +
139 +def _copy_immutable(x):
140 + return x
141 +for t in (types.NoneType, int, long, float, bool, str, tuple,
142 + type, xrange, types.ClassType,
143 + types.BuiltinFunctionType):
144 + d[t] = _copy_immutable
145 +try:
146 + d[frozenset] = _copy_immutable
147 +except:
148 + pass
149 +
150 +for name in ("ComplexType", "UnicodeType", "CodeType"):
151 + t = getattr(types, name, None)
152 + if t is not None:
153 + d[t] = _copy_immutable
154 +
155 +def _copy_with_constructor(x):
156 + return type(x)(x)
157 +for t in (list, dict):
158 + d[t] = _copy_with_constructor
159 +try:
160 + d[set] = _copy_with_constructor
161 +except:
162 + pass
163 +
164 +def _copy_with_copy_method(x):
165 + return x.copy()
166 +if PyStringMap is not None:
167 + d[PyStringMap] = _copy_with_copy_method
168 +
169 +def _copy_inst(x):
170 + if hasattr(x, '__copy__'):
171 + return x.__copy__()
172 + if hasattr(x, '__getinitargs__'):
173 + args = x.__getinitargs__()
174 + y = x.__class__(*args)
175 + else:
176 + y = _EmptyClass()
177 + y.__class__ = x.__class__
178 + if hasattr(x, '__getstate__'):
179 + state = x.__getstate__()
180 + else:
181 + state = x.__dict__
182 + if hasattr(y, '__setstate__'):
183 + y.__setstate__(state)
184 + else:
185 + y.__dict__.update(state)
186 + return y
187 +d[types.InstanceType] = _copy_inst
188 +
189 +del d
190 +
191 +def deepcopy(x, memo=None, _nil=[]):
192 + """Deep copy operation on arbitrary Python objects.
193 +
194 + See the module's __doc__ string for more info.
195 + """
196 +
197 + if memo is None:
198 + memo = {}
199 +
200 + d = id(x)
201 + y = memo.get(d, _nil)
202 + if y is not _nil:
203 + return y
204 +
205 + cls = type(x)
206 +
207 + copier = _deepcopy_dispatch.get(cls)
208 + if copier:
209 + y = copier(x, memo)
210 + else:
211 + try:
212 + issc = issubclass(cls, type)
213 + except TypeError: # cls is not a class (old Boost; see SF #502085)
214 + issc = 0
215 + if issc:
216 + y = _deepcopy_atomic(x, memo)
217 + else:
218 + copier = _getspecial(cls, "__deepcopy__")
219 + if copier:
220 + y = copier(x, memo)
221 + else:
222 + reductor = dispatch_table.get(cls)
223 + if reductor:
224 + rv = reductor(x)
225 + else:
226 + reductor = getattr(x, "__reduce_ex__", None)
227 + if reductor:
228 + rv = reductor(2)
229 + else:
230 + reductor = getattr(x, "__reduce__", None)
231 + if reductor:
232 + rv = reductor()
233 + else:
234 + copier = getattr(x, "__deepcopy__", None)
235 + if copier:
236 + return copier(memo)
237 + raise Error(
238 + "un(deep)copyable object of type %s" % cls)
239 + y = _reconstruct(x, rv, 1, memo)
240 +
241 + memo[d] = y
242 + _keep_alive(x, memo) # Make sure x lives at least as long as d
243 + return y
244 +
245 +_deepcopy_dispatch = d = {}
246 +
247 +def _deepcopy_atomic(x, memo):
248 + return x
249 +d[types.NoneType] = _deepcopy_atomic
250 +d[types.IntType] = _deepcopy_atomic
251 +d[types.LongType] = _deepcopy_atomic
252 +d[types.FloatType] = _deepcopy_atomic
253 +d[types.BooleanType] = _deepcopy_atomic
254 +try:
255 + d[types.ComplexType] = _deepcopy_atomic
256 +except AttributeError:
257 + pass
258 +d[types.StringType] = _deepcopy_atomic
259 +try:
260 + d[types.UnicodeType] = _deepcopy_atomic
261 +except AttributeError:
262 + pass
263 +try:
264 + d[types.CodeType] = _deepcopy_atomic
265 +except AttributeError:
266 + pass
267 +d[types.TypeType] = _deepcopy_atomic
268 +d[types.XRangeType] = _deepcopy_atomic
269 +d[types.ClassType] = _deepcopy_atomic
270 +d[types.BuiltinFunctionType] = _deepcopy_atomic
271 +
272 +def _deepcopy_list(x, memo):
273 + y = []
274 + memo[id(x)] = y
275 + for a in x:
276 + y.append(deepcopy(a, memo))
277 + return y
278 +d[types.ListType] = _deepcopy_list
279 +
280 +def _deepcopy_tuple(x, memo):
281 + y = []
282 + for a in x:
283 + y.append(deepcopy(a, memo))
284 + d = id(x)
285 + try:
286 + return memo[d]
287 + except KeyError:
288 + pass
289 + for i in range(len(x)):
290 + if x[i] is not y[i]:
291 + y = tuple(y)
292 + break
293 + else:
294 + y = x
295 + memo[d] = y
296 + return y
297 +d[types.TupleType] = _deepcopy_tuple
298 +
299 +def _deepcopy_dict(x, memo):
300 + y = {}
301 + memo[id(x)] = y
302 + for key, value in x.iteritems():
303 + y[deepcopy(key, memo)] = deepcopy(value, memo)
304 + return y
305 +d[types.DictionaryType] = _deepcopy_dict
306 +if PyStringMap is not None:
307 + d[PyStringMap] = _deepcopy_dict
308 +
309 +def _keep_alive(x, memo):
310 + """Keeps a reference to the object x in the memo.
311 +
312 + Because we remember objects by their id, we have
313 + to assure that possibly temporary objects are kept
314 + alive by referencing them.
315 + We store a reference at the id of the memo, which should
316 + normally not be used unless someone tries to deepcopy
317 + the memo itself...
318 + """
319 + try:
320 + memo[id(memo)].append(x)
321 + except KeyError:
322 + # aha, this is the first one :-)
323 + memo[id(memo)]=[x]
324 +
325 +def _deepcopy_inst(x, memo):
326 + if hasattr(x, '__deepcopy__'):
327 + return x.__deepcopy__(memo)
328 + if hasattr(x, '__getinitargs__'):
329 + args = x.__getinitargs__()
330 + args = deepcopy(args, memo)
331 + y = x.__class__(*args)
332 + else:
333 + y = _EmptyClass()
334 + y.__class__ = x.__class__
335 + memo[id(x)] = y
336 + if hasattr(x, '__getstate__'):
337 + state = x.__getstate__()
338 + else:
339 + state = x.__dict__
340 + state = deepcopy(state, memo)
341 + if hasattr(y, '__setstate__'):
342 + y.__setstate__(state)
343 + else:
344 + y.__dict__.update(state)
345 + return y
346 +d[types.InstanceType] = _deepcopy_inst
347 +
348 +def _reconstruct(x, info, deep, memo=None):
349 + if isinstance(info, str):
350 + return x
351 + assert isinstance(info, tuple)
352 + if memo is None:
353 + memo = {}
354 + n = len(info)
355 + assert n in (2, 3, 4, 5)
356 + callable, args = info[:2]
357 + if n > 2:
358 + state = info[2]
359 + else:
360 + state = {}
361 + if n > 3:
362 + listiter = info[3]
363 + else:
364 + listiter = None
365 + if n > 4:
366 + dictiter = info[4]
367 + else:
368 + dictiter = None
369 + if deep:
370 + args = deepcopy(args, memo)
371 + y = callable(*args)
372 + memo[id(x)] = y
373 + if listiter is not None:
374 + for item in listiter:
375 + if deep:
376 + item = deepcopy(item, memo)
377 + y.append(item)
378 + if dictiter is not None:
379 + for key, value in dictiter:
380 + if deep:
381 + key = deepcopy(key, memo)
382 + value = deepcopy(value, memo)
383 + y[key] = value
384 + if state:
385 + if deep:
386 + state = deepcopy(state, memo)
387 + if hasattr(y, '__setstate__'):
388 + y.__setstate__(state)
389 + else:
390 + if isinstance(state, tuple) and len(state) == 2:
391 + state, slotstate = state
392 + else:
393 + slotstate = None
394 + if state is not None:
395 + y.__dict__.update(state)
396 + if slotstate is not None:
397 + for key, value in slotstate.iteritems():
398 + setattr(y, key, value)
399 + return y
400 +
401 +del d
402 +
403 +del types
404 +
405 +# Helper for instance creation without calling __init__
406 +class _EmptyClass:
407 + pass
408 +
409 +def _test():
410 + l = [None, 1, 2L, 3.14, 'xyzzy', (1, 2L), [3.14, 'abc'],
411 + {'abc': 'ABC'}, (), [], {}]
412 + l1 = copy(l)
413 + print l1==l
414 + l1 = map(copy, l)
415 + print l1==l
416 + l1 = deepcopy(l)
417 + print l1==l
418 + class C:
419 + def __init__(self, arg=None):
420 + self.a = 1
421 + self.arg = arg
422 + if __name__ == '__main__':
423 + import sys
424 + file = sys.argv[0]
425 + else:
426 + file = __file__
427 + self.fp = open(file)
428 + self.fp.close()
429 + def __getstate__(self):
430 + return {'a': self.a, 'arg': self.arg}
431 + def __setstate__(self, state):
432 + for key, value in state.iteritems():
433 + setattr(self, key, value)
434 + def __deepcopy__(self, memo=None):
435 + new = self.__class__(deepcopy(self.arg, memo))
436 + new.a = self.a
437 + return new
438 + c = C('argument sketch')
439 + l.append(c)
440 + l2 = copy(l)
441 + print l == l2
442 + print l
443 + print l2
444 + l2 = deepcopy(l)
445 + print l == l2
446 + print l
447 + print l2
448 + l.append({l[1]: l, 'xyz': l[2]})
449 + l3 = copy(l)
450 + import repr
451 + print map(repr.repr, l)
452 + print map(repr.repr, l1)
453 + print map(repr.repr, l2)
454 + print map(repr.repr, l3)
455 + l3 = deepcopy(l)
456 + import repr
457 + print map(repr.repr, l)
458 + print map(repr.repr, l1)
459 + print map(repr.repr, l2)
460 + print map(repr.repr, l3)
461 +
462 +if __name__ == '__main__':
463 + _test()
464 diff -urN moin--main--1.5--patch-384/MoinMoin/support/lupy/index/segment.py moin--main--1.5--patch-386/MoinMoin/support/lupy/index/segment.py
465 --- moin--main--1.5--patch-384/MoinMoin/support/lupy/index/segment.py 2006-01-18 09:44:50.000000000 +0100
466 +++ moin--main--1.5--patch-386/MoinMoin/support/lupy/index/segment.py 2006-01-18 09:50:15.000000000 +0100
467 @@ -5,7 +5,9 @@
468 # General Public License as published by the Free Software Foundation.
469
470 from MoinMoin.support.lupy.index import term
471 -import copy
472 +
473 +#import copy #broken, see comments at top of this file:
474 +from MoinMoin.support import copy
475
476 class SegmentTermEnum:
477
478 diff -urN moin--main--1.5--patch-384/MoinMoin/support/lupy/index/segmentmerger.py moin--main--1.5--patch-386/MoinMoin/support/lupy/index/segmentmerger.py
479 --- moin--main--1.5--patch-384/MoinMoin/support/lupy/index/segmentmerger.py 2006-01-18 09:44:50.000000000 +0100
480 +++ moin--main--1.5--patch-386/MoinMoin/support/lupy/index/segmentmerger.py 2006-01-18 09:50:15.000000000 +0100
481 @@ -11,7 +11,10 @@
482 from MoinMoin.support.lupy.util import BitVector
483
484 from MoinMoin.support.lupy.index import field, term, segment
485 -import copy
486 +
487 +#import copy #broken, see comments at top of this file:
488 +from MoinMoin.support import copy
489 +
490 from bisect import insort
491 import os
492
493 diff -urN moin--main--1.5--patch-384/MoinMoin/wikidicts.py moin--main--1.5--patch-386/MoinMoin/wikidicts.py
494 --- moin--main--1.5--patch-384/MoinMoin/wikidicts.py 2006-01-18 09:44:50.000000000 +0100
495 +++ moin--main--1.5--patch-386/MoinMoin/wikidicts.py 2006-01-18 09:50:15.000000000 +0100
496 @@ -6,7 +6,10 @@
497 @copyright: 2003 by Gustavo Niemeyer, http://moin.conectiva.com.br/GustavoNiemeyer
498 @license: GNU GPL, see COPYING for details.
499 """
500 -import re, time, os, copy
501 +import re, time, os
502 +
503 +#import copy #broken, see comments at top of this file:
504 +from MoinMoin.support import copy
505
506 # cPickle can encode normal and Unicode strings
507 # see http://docs.python.org/lib/node66.html
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.