File: symbols.py

package info (click to toggle)
python-peak.util 20160204-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 720 kB
  • ctags: 453
  • sloc: python: 2,478; makefile: 33
file content (34 lines) | stat: -rw-r--r-- 765 bytes parent folder | download | duplicates (3)
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
"""Symbolic global constants, like 'None', 'NOT_FOUND', etc."""

__all__ = [
    'Symbol','NOT_GIVEN','NOT_FOUND'
]


class Symbol(object):

    """Symbolic global constant"""

    __slots__ = ['_name', '_module']
    __name__   = property(lambda s: s._name)
    __module__ = property(lambda s: s._module)

    def __init__(self, symbol, moduleName):
        self.__class__._name.__set__(self,symbol)
        self.__class__._module.__set__(self,moduleName)

    def __reduce__(self):
        return self._name

    def __setattr__(self,attr,val):
        raise TypeError("Symbols are immutable")

    def __repr__(self):
        return self.__name__

    __str__ = __repr__


NOT_GIVEN   = Symbol("NOT_GIVEN", __name__)
NOT_FOUND   = Symbol("NOT_FOUND", __name__)