/usr/share/pyshared/insanity/generator.py is in python-insanity 0.0+git20110920.4750a8e8-2.
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | # GStreamer QA system
#
# generator.py
#
# Copyright (c) 2007, Edward Hervey <bilboed@bilboed.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
"""
Generator classes
Generators expand some arguments into a dictionnary of arguments.
"""
# TODO
# introspection
#
# We should be able to do something like:
# * chaining generators output
# i.e. pass the output of FileSystemGenerator to PlaylistGenerator
class Generator(object):
"""
Expands some arguments into a list of arguments.
Base class, should not be used directly.
"""
__args__ = {}
__produces__ = None
def __init__(self, *args, **kwargs):
"""
Subclasses should call their parent __init__ will ALL arguments
"""
self.args = args
self.kwargs = kwargs
self.generated = []
self._length = None
def copy(self):
return self.__class__(*self.args, **self.kwargs)
def generate(self):
"""
Returns the full combination of results
"""
if not self.generated:
self.generated = self._generate()
return self.generated
def _generate(self):
"""
Return the full list of results
to be implemented by subclasses
"""
raise NotImplementedError
def __iter__(self):
return iter(self.generate()[:])
def __len__(self):
if self._length == None:
self._length = len(self.generate())
return self._length
def __getitem__(self, idx):
return self.generate()[idx]
|