/usr/share/pyshared/pycocumalib/Set.py is in pycocuma 0.4.5-6-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | """
Simple Set Class
Note that we cannot use the sets.Set class of Python2.3 here,
because we want items() as sorted list
"""
# Copyright (C) 2004 Henning Jacobs <henning@srcco.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# $Id: Set.py 82 2004-07-11 13:01:44Z henning $
def union(s1, s2):
import copy
result = copy.copy(s1)
for item in s2:
result.add(item)
return result
class Set:
def __init__(self, *args):
self._dict = {}
for arg in args:
self.add(arg)
def __repr__(self):
import string
elems = map(repr, self._dict.keys())
elems.sort()
return "%s(%s)" % (self.__class__.__name__, string.join(elems, ", "))
def assign(self, other):
import copy
self._dict = copy.copy(other._dict)
def extend(self, args):
"Add several items at once."
for arg in args:
self.add(arg)
def add(self, item):
"Add one item to the set."
self._dict[item] = item
def remove(self, item):
"Remove an item from the set."
del self._dict[item]
def contains(self, item):
"Check whether the set contains a certain item."
return self._dict.has_key(item)
# High-Performance membership test for Python 2.0+
__contains__ = contains
def __getitem__(self, index):
"Support the 'for item in set:' proto."
return self._dict.keys()[index]
def __iter__(self):
"Better support 'for item in set:' via Py2.2 iterators"
return iter(self._dict.copy())
def __len__(self):
"Return the number of items in the set."
return len(self._dict)
def items(self):
"Return a list containing all items in sorted order, if possible."
result = self._dict.keys()
try: result.sort()
except: pass
return result
|