/usr/lib/python2.7/dist-packages/kid/options.py is in python-kid 0.9.6-3.
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 | # -*- coding: utf-8 -*-
"""Configuration API."""
import release
__revision__ = "$Rev: 492 $"
__date__ = "$Date: 2007-07-06 21:38:45 -0400 (Fri, 06 Jul 2007) $"
__author__ = "David Stanek <dstanek@dstanek.com>"
__copyright__ = "Copyright 2006, David Stanek"
__license__ = release.license
__all__ = ['Options']
_prefix = "kid:"
class Options(object):
def __init__(self, options={}, **extra):
self._options = {}
for name, value in options.items():
self.set(name, value)
for name, value in extra.items():
self.set(name, value)
def isset(self, name):
"""Returns True if a option exists or False if it doesn't.
name: the option to check
"""
return self._options.has_key(self.__prefix(name))
def get(self, name, default=None):
"""Get the value of an option.
name: the option to retrieve
default: returned for non-existing properties, defaults to None
"""
return self._options.get(self.__prefix(name), default)
def set(self, name, value):
"""Set the value of an option.
name: the option to set
value: the value to be set for the option
Returns the value passed in.
"""
self._options[self.__prefix(name)] = value
return value
def remove(self, name):
"""Remove an option."""
if self.isset(name):
del self._options[self.__prefix(name)]
def __getitem__(self, name):
if not self.isset(name):
raise KeyError, "no option %s" % name
return self.get(name)
def __setitem__(self, name, value):
self.set(name, value)
def __delitem__(self, name):
if not self.isset(name):
raise KeyError, "no option %s" % name
self.remove(name)
def __prefix(self, name):
"""Add the prefix if it does not already exist."""
if not name.startswith(_prefix):
name = _prefix + name
return name
|