def test_name(self): """ The C{name} attribute of a L{NamedConstant} refers to the value passed for the C{name} parameter to C{_realize}. """ name = NamedConstant() name._realize(self.container, "bar", None) self.assertEqual("bar", name.name)
def test_equality(self): """ A L{NamedConstant} instance compares equal to itself. """ name = NamedConstant() name._realize(self.container, "bar", None) self.assertTrue(name == name) self.assertFalse(name != name)
class Directions(Names): """ The four cardinal directions (north, east, south, west). """ NORTH = NamedConstant() EAST = NamedConstant() SOUTH = NamedConstant() WEST = NamedConstant()
class EventRedactBehaviour(Names): """ What to do when retrieving a redacted event from the database. """ AS_IS = NamedConstant() REDACT = NamedConstant() BLOCK = NamedConstant()
def test_representation(self): """ The string representation of an instance of L{NamedConstant} includes the container the instances belongs to as well as the instance's name. """ name = NamedConstant() name._realize(self.container, "bar", None) self.assertEqual("<foo=bar>", repr(name))
class LogLevel(Names): """ Constants describing log levels. @cvar debug: Debugging events: Information of use to a developer of the software, not generally of interest to someone running the software unless they are attempting to diagnose a software issue. @cvar info: Informational events: Routine information about the status of an application, such as incoming connections, startup of a subsystem, etc. @cvar warn: Warning events: Events that may require greater attention than informational events but are not a systemic failure condition, such as authorization failures, bad data from a network client, etc. Such events are of potential interest to system administrators, and should ideally be phrased in such a way, or documented, so as to indicate an action that an administrator might take to mitigate the warning. @cvar error: Error conditions: Events indicating a systemic failure, such as programming errors in the form of unhandled exceptions, loss of connectivity to an external system without which no useful work can proceed, such as a database or API endpoint, or resource exhaustion. Similarly to warnings, errors that are related to operational parameters may be actionable to system administrators and should provide references to resources which an administrator might use to resolve them. @cvar critical: Critical failures: Errors indicating systemic failure (ie. service outage), data corruption, imminent data loss, etc. which must be handled immediately. This includes errors unanticipated by the software, such as unhandled exceptions, wherein the cause and consequences are unknown. """ debug = NamedConstant() info = NamedConstant() warn = NamedConstant() error = NamedConstant() critical = NamedConstant() @classmethod def levelWithName(cls, name: str) -> NamedConstant: """ Get the log level with the given name. @param name: The name of a log level. @return: The L{LogLevel} with the specified C{name}. @raise InvalidLogLevelError: if the C{name} does not name a valid log level. """ try: return cls.lookupByName(name) except ValueError: raise InvalidLogLevelError(name)
class METHOD(Names): """ A container for some named constants to use in unit tests for L{Names}. """ GET = NamedConstant() PUT = NamedConstant() POST = NamedConstant() DELETE = NamedConstant() extra = object()
def test_hash(self): """ Because two different L{NamedConstant} instances do not compare as equal to each other, they also have different hashes to avoid collisions when added to a C{dict} or C{set}. """ first = NamedConstant() first._realize(self.container, "bar", None) second = NamedConstant() second._realize(self.container, "bar", None) self.assertNotEqual(hash(first), hash(second))
def test_nonequality(self): """ Two different L{NamedConstant} instances do not compare equal to each other. """ first = NamedConstant() first._realize(self.container, "bar", None) second = NamedConstant() second._realize(self.container, "bar", None) self.assertFalse(first == second) self.assertTrue(first != second)
class SessionMechanism(Names): """ Mechanisms which can be used to identify and authenticate a session. @cvar Cookie: The Cookie session mechanism involves looking up the session identifier via an HTTP cookie. Session objects retrieved via this mechanism may be vulnerable to U{CSRF attacks <https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)>} and therefore must have CSRF protections applied to them. @cvar Header: The Header mechanism retrieves the session identifier via a separate header such as C{"X-Auth-Token"}. Since a different-origin site in a browser can easily send a form submission including cookies, but I{can't} easily put stuff into other arbitrary headers, this does not require additional protections. """ Cookie = NamedConstant() Header = NamedConstant()
class RunnerOptions(Names): """ Names for options recognized by L{Runner}. These are meant to be used as keys in the options given to L{Runner}, with corresponding values as noted below. @cvar reactor: The reactor to start. Corresponding value: L{IReactorCore}. @type reactor: L{NamedConstant} @cvar pidFile: The PID file to use. Corresponding value: L{IPIDFile}. @type pidFile: L{NamedConstant} @cvar kill: Whether this runner should kill an existing running instance. Corresponding value: L{bool}. @type kill: L{NamedConstant} @cvar defaultLogLevel: The default log level to start the logging system with. Corresponding value: L{NamedConstant} from L{LogLevel}. @type defaultLogLevel: L{NamedConstant} @cvar logFile: A file stream to write logging output to. Corresponding value: writable file like object. @type logFile: L{NamedConstant} @cvar fileLogObserverFactory: What file log observer to use when starting the logging system. Corresponding value: callable that returns a L{twisted.logger.FileLogObserver} @type fileLogObserverFactory: L{NamedConstant} @cvar whenRunning: Hook to call when the reactor is running. This can be considered the Twisted equivalent to C{main()}. Corresponding value: callable that takes the options mapping given to the runner as an argument. @type whenRunning: L{NamedConstant} @cvar reactorExited: Hook to call when the reactor has exited. Corresponding value: callable that takes an empty arguments list @type reactorExited: L{NamedConstant} """ reactor = NamedConstant() pidFile = NamedConstant() kill = NamedConstant() defaultLogLevel = NamedConstant() logFile = NamedConstant() fileLogObserverFactory = NamedConstant() whenRunning = NamedConstant() reactorExited = NamedConstant()
class Angles(Names): """ The types of angles. @cvar LATITUDE: Angle representing a latitude of an object. @type LATITUDE: L{NamedConstant} @cvar LONGITUDE: Angle representing the longitude of an object. @type LONGITUDE: L{NamedConstant} @cvar HEADING: Angle representing the heading of an object. @type HEADING: L{NamedConstant} @cvar VARIATION: Angle representing a magnetic variation. @type VARIATION: L{NamedConstant} """ LATITUDE = NamedConstant() LONGITUDE = NamedConstant() HEADING = NamedConstant() VARIATION = NamedConstant()
class DrainType(Names): CONSOLE = NamedConstant() CONSOLE_JSON = NamedConstant() CONSOLE_JSON_TERSE = NamedConstant() FILE = NamedConstant() FILE_JSON = NamedConstant() NETWORK_JSON_TERSE = NamedConstant()
class PredicateResult(Names): """ Predicate results. @see: L{LogLevelFilterPredicate} @cvar yes: Log the specified event. When this value is used, L{FilteringLogObserver} will always log the message, without evaluating other predicates. @cvar no: Do not log the specified event. When this value is used, L{FilteringLogObserver} will I{not} log the message, without evaluating other predicates. @cvar maybe: Do not have an opinion on the event. When this value is used, L{FilteringLogObserver} will consider subsequent predicate results; if returned by the last predicate being considered, then the event will be logged. """ yes = NamedConstant() no = NamedConstant() maybe = NamedConstant()
class NETWORK(Names): """Modes for network behavior""" MODE_SERVER = NamedConstant() MODE_CLIENT = NamedConstant()
class RRSetType(Names): RESOURCE = NamedConstant() ALIAS = NamedConstant()
class NamedLetters(Names): """ Some letters, named. """ alpha = NamedConstant() beta = NamedConstant()
class MoreNamedLetters(Names): """ Some more letters, named. """ digamma = NamedConstant() zeta = NamedConstant()