diff options
author | imarom <imarom@cisco.com> | 2016-03-20 11:49:17 +0200 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-03-20 11:50:17 +0200 |
commit | 94ec2f0c0a6fc30fb3a9a11243146e0d878c4c5b (patch) | |
tree | a63d4b1e4b22938a3506a55030a3866e0d5211ca /scripts/external_libs/pyzmq-14.5.0/cel59/python3/32bit/zmq/sugar/attrsettr.py | |
parent | 33c80d0f2c3af8b302e50ce3925869dfd37267ed (diff) |
ZMQ CEL5.9 / 32 bit / 64 bit with python 2 / python 3
Diffstat (limited to 'scripts/external_libs/pyzmq-14.5.0/cel59/python3/32bit/zmq/sugar/attrsettr.py')
-rw-r--r-- | scripts/external_libs/pyzmq-14.5.0/cel59/python3/32bit/zmq/sugar/attrsettr.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/external_libs/pyzmq-14.5.0/cel59/python3/32bit/zmq/sugar/attrsettr.py b/scripts/external_libs/pyzmq-14.5.0/cel59/python3/32bit/zmq/sugar/attrsettr.py new file mode 100644 index 00000000..4bbd36d6 --- /dev/null +++ b/scripts/external_libs/pyzmq-14.5.0/cel59/python3/32bit/zmq/sugar/attrsettr.py @@ -0,0 +1,52 @@ +# coding: utf-8 +"""Mixin for mapping set/getattr to self.set/get""" + +# Copyright (C) PyZMQ Developers +# Distributed under the terms of the Modified BSD License. + + +from . import constants + +class AttributeSetter(object): + + def __setattr__(self, key, value): + """set zmq options by attribute""" + + # regular setattr only allowed for class-defined attributes + for obj in [self] + self.__class__.mro(): + if key in obj.__dict__: + object.__setattr__(self, key, value) + return + + upper_key = key.upper() + try: + opt = getattr(constants, upper_key) + except AttributeError: + raise AttributeError("%s has no such option: %s" % ( + self.__class__.__name__, upper_key) + ) + else: + self._set_attr_opt(upper_key, opt, value) + + def _set_attr_opt(self, name, opt, value): + """override if setattr should do something other than call self.set""" + self.set(opt, value) + + def __getattr__(self, key): + """get zmq options by attribute""" + upper_key = key.upper() + try: + opt = getattr(constants, upper_key) + except AttributeError: + raise AttributeError("%s has no such option: %s" % ( + self.__class__.__name__, upper_key) + ) + else: + return self._get_attr_opt(upper_key, opt) + + def _get_attr_opt(self, name, opt): + """override if getattr should do something other than call self.get""" + return self.get(opt) + + +__all__ = ['AttributeSetter'] |