/usr/share/pyshared/mx/Queue/UserQueue.py is in python-egenix-mxqueue 3.2.1-1ubuntu1.
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 | """ A pure Python Queue implementation modelled after mxQueue.
Copyright (c) 2000, Marc-Andre Lemburg; mailto:mal@lemburg.com
Copyright (c) 2000-2010, eGenix.com Software GmbH; mailto:info@egenix.com
See the documentation for further information on copyrights,
or contact the author. All Rights Reserved.
"""
__version__ = '0.1'
class UserQueue:
def __init__(self):
self.queue = []
self.headindex = 0
def push(self,x):
self.queue.append(x)
def pop(self):
headindex = self.headindex
queue = self.queue
x = queue[headindex]
queue[headindex] = None # del. reference
headindex = headindex + 1
if headindex > 100 and headindex > len(queue) / 2:
# compactify
self.queue = self.queue[headindex:]
self.headindex = 0
else:
self.headindex = headindex
return x
def not_empty(self):
return self.headindex != len(self.queue)
def head(self):
return self.queue[self.headindex]
def tail(self):
return self.queue[-1]
def __len__(self):
return len(self.queue) - self.headindex
def __repr__(self):
l = self.queue[self.headindex:]
l.reverse()
return '<UserQueue [%s]>' % repr(l)[1:-1]
def __str__(self):
l = self.queue[self.headindex:]
l.reverse()
return 'q' + repr(l)
|