Exemplo n.º 1
0
    def __init__(
            self,
            type,
            history_length,
            reactor=the_reactor,  # default because most uses will be from GR
            info_getter=lambda: None,
            **kwargs):
        type = to_value_type(type)
        if not (type == to_value_type(six.text_type)
                or isinstance(type, BulkDataT)):
            raise ValueError('Unsupported type for GRSinkCell {}'.format(type))
        ValueCell.__init__(self,
                           type=type,
                           writable=False,
                           persists=False,
                           **kwargs)

        self.__buffer = type.create_buffer(history_length)
        if not self.__buffer:
            raise ValueError(
                'Type {} does not support patch buffers'.format(type))

        self.__subscriptions = set()
        self.__info_getter = info_getter
        self.__reactor = reactor
Exemplo n.º 2
0
 def test_coerce_unicode(self):
     """Coercion behavior is inherited from the Python type's __call__."""
     if six.PY2:
         _test_coerce_cases(
             self,
             to_value_type(six.text_type),
             good=[
                 '',
                 'hello world',
                 '↑',
                 (None, 'None'),
                 (b'x', 'x'),
                 (1, '1'),
                 ([], '[]'),
             ],
             bad=[
                 b'\xFF',  # encoding failure
             ])
     else:
         _test_coerce_cases(self,
                            to_value_type(six.text_type),
                            good=[
                                '',
                                'hello world',
                                '↑',
                                (None, 'None'),
                                (b'x', "b'x'"),
                                (b'\xFF', "b'\\xff'"),
                                (1, '1'),
                                ([], '[]'),
                            ],
                            bad=[])
Exemplo n.º 3
0
 def test_coerce_unicode(self):
     """Coercion behavior is inherited from the Python type's __call__."""
     if six.PY2:
         _test_coerce_cases(self,
             to_value_type(six.text_type),
             good=[
                 '', 
                 'hello world',
                 '↑',
                 (None, 'None'),
                 (b'x', 'x'),
                 (1, '1'),
                 ([], '[]'),
             ],
             bad=[
                 b'\xFF',  # encoding failure
             ])
     else:
         _test_coerce_cases(self,
             to_value_type(six.text_type),
             good=[
                 '', 
                 'hello world',
                 '↑',
                 (None, 'None'),
                 (b'x', "b'x'"),
                 (b'\xFF', "b'\\xff'"),
                 (1, '1'),
                 ([], '[]'),
             ],
             bad=[])
Exemplo n.º 4
0
 def __init__(self, target, key, changes, type=object, writable=False, persists=None, **kwargs):
     assert changes in _cell_value_change_schedules
     type = to_value_type(type)
     if persists is None:
         persists = writable or type.is_reference()
     
     if changes == u'continuous' and persists:
         raise ValueError('persists=True changes={!r} is not allowed'.format(changes))
     if changes == u'never' and writable:
         raise ValueError('writable=True changes={!r} doesn\'t make sense'.format(changes))
     
     TargetingMixin.__init__(self, target, key)
     ValueCell.__init__(self,
         type=type,
         persists=persists,
         writable=writable,
         associated_key=key,
         **kwargs)
     
     self.__changes = changes
     if changes == u'explicit' or changes == u'this_setter':
         self.__explicit_subscriptions = set()
         self.__last_polled_value = object()
     
     self.__getter = getattr(self._target, 'get_' + key)
     if writable:
         self.__setter = getattr(self._target, 'set_' + key)
Exemplo n.º 5
0
 def __init__(self, target, key, changes, type=object, writable=False, persists=None, **kwargs):
     assert changes in _cell_value_change_schedules  # TODO actually use value
     type = to_value_type(type)
     if persists is None:
         persists = writable or type.is_reference()
     
     if changes == u'continuous' and persists:
         raise ValueError('persists=True changes={!r} is not allowed'.format(changes))
     if changes == u'never' and writable:
         raise ValueError('writable=True changes={!r} doesn\'t make sense'.format(changes))
     
     ValueCell.__init__(self,
         target,
         key,
         type=type,
         persists=persists,
         writable=writable,
         **kwargs)
     
     self.__changes = changes
     if changes == u'explicit' or changes == u'this_setter':
         self.__explicit_subscriptions = set()
         self.__last_polled_value = object()
     
     self._getter = getattr(self._target, 'get_' + key)
     if writable:
         self._setter = getattr(self._target, 'set_' + key)
     else:
         self._setter = None
Exemplo n.º 6
0
 def test_string_buffer_append_and_truncate(self):
     # TODO: add more tests
     buf = to_value_type(six.text_type).create_buffer(history_length=5)
     buf.append('aa')
     buf.append('bb')
     self.assertEqual(buf.get(), 'aabb')
     buf.append('cc')
     self.assertEqual(buf.get(), 'abbcc')
Exemplo n.º 7
0
 def test_string_buffer_append_and_truncate(self):
     # TODO: add more tests
     buf = to_value_type(unicode).create_buffer(history_length=5)
     buf.append('aa')
     buf.append('bb')
     self.assertEqual(buf.get(), 'aabb')
     buf.append('cc')
     self.assertEqual(buf.get(), 'abbcc')
Exemplo n.º 8
0
 def __init__(self, target, key, type=to_value_type(object), writable=False, persists=None):
     if persists is None: persists = writable
     ValueCell.__init__(self, target, key, writable=writable, persists=persists, type=type)
     self._getter = getattr(self._target, 'get_' + key)
     if writable:
         self._setter = getattr(self._target, 'set_' + key)
     else:
         self._setter = None
Exemplo n.º 9
0
 def __init__(self, target, key, type=to_value_type(object), writable=False, persists=None):
     if persists is None: persists = writable
     ValueCell.__init__(self, target, key, writable=writable, persists=persists, type=type)
     self._getter = getattr(self._target, 'get_' + key)
     if writable:
         self._setter = getattr(self._target, 'set_' + key)
     else:
         self._setter = None
Exemplo n.º 10
0
 def test_specify_all_metadata(self):
     # using LooseCell as an arbitrary concrete subclass
     cell = LooseCell(
         value=0,
         type=int,
         persists=False,  # the non-default value
         label='mylabel',
         description='mydescription',
         sort_key='mysortkey')
     self.assertEqual(cell.metadata().value_type, to_value_type(int))
     self.assertEqual(cell.metadata().persists, False)
     self.assertEqual(cell.metadata().naming, EnumRow(
         label='mylabel',
         description='mydescription',
         sort_key='mysortkey'))
Exemplo n.º 11
0
 def test_specify_all_metadata(self):
     # using LooseCell as an arbitrary concrete subclass
     cell = LooseCell(
         value=0,
         type=int,
         persists=False,  # the non-default value
         label='mylabel',
         description='mydescription',
         sort_key='mysortkey')
     self.assertEqual(cell.metadata().value_type, to_value_type(int))
     self.assertEqual(cell.metadata().persists, False)
     self.assertEqual(cell.metadata().naming, EnumRow(
         label='mylabel',
         description='mydescription',
         sort_key='mysortkey'))
Exemplo n.º 12
0
 def __init__(self,
              type,
              persists=True,
              writable=False,
              label=None,
              description=None,
              sort_key=None,
              associated_key=None):
     self._writable = writable
     # TODO: Also allow specifying metadata object directly.
     self.__metadata = CellMetadata(value_type=to_value_type(type),
                                    persists=bool(persists),
                                    naming=EnumRow(
                                        label=label,
                                        description=description,
                                        sort_key=sort_key,
                                        associated_key=associated_key))
Exemplo n.º 13
0
 def __init__(self,
         type,
         persists=True,
         writable=False,
         label=None,
         description=None,
         sort_key=None,
         associated_key=None):
     self._writable = writable
     # TODO: Also allow specifying metadata object directly.
     self.__metadata = CellMetadata(
         value_type=to_value_type(type),
         persists=bool(persists),
         naming=EnumRow(
             label=label,
             description=description,
             sort_key=sort_key,
             associated_key=associated_key))
Exemplo n.º 14
0
    def __init__(self,
                 target,
                 key,
                 changes,
                 type=object,
                 writable=False,
                 persists=None,
                 interest_tracker=nullInterestTracker,
                 **kwargs):
        assert changes in _cell_value_change_schedules
        type = to_value_type(type)
        if persists is None:
            persists = writable or type.is_reference()
        if changes == u'never':
            # no need to track
            interest_tracker = nullInterestTracker

        if changes == u'continuous' and persists:
            raise ValueError(
                'persists=True changes={!r} is not allowed'.format(changes))
        if changes == u'never' and writable:
            raise ValueError(
                'writable=True changes={!r} doesn\'t make sense'.format(
                    changes))

        TargetingMixin.__init__(self, target, key)
        ValueCell.__init__(self,
                           type=type,
                           persists=persists,
                           writable=writable,
                           associated_key=key,
                           interest_tracker=interest_tracker,
                           **kwargs)

        self.__changes = changes
        if changes == u'explicit' or changes == u'this_setter':
            self.__explicit_subscriptions = set()
            self.__last_polled_value = object()

        self.__getter = getattr(self._target, 'get_' + key)
        if writable:
            self.__setter = getattr(self._target, 'set_' + key)
Exemplo n.º 15
0
 def __init__(self,
              target,
              key,
              type,
              persists=True,
              writable=False,
              label=None,
              description=None,
              sort_key=None):
     # The exact relationship of target and key depends on the subtype
     self._target = target
     self._key = key
     self._writable = writable
     # TODO: Also allow specifying metadata object directly.
     self.__metadata = CellMetadata(value_type=to_value_type(type),
                                    persists=bool(persists),
                                    naming=EnumRow(associated_key=key,
                                                   label=label,
                                                   description=description,
                                                   sort_key=sort_key))
Exemplo n.º 16
0
 def __init__(self,
         target,
         key,
         type,
         persists=True,
         writable=False,
         label=None,
         description=None,
         sort_key=None):
     # The exact relationship of target and key depends on the subtype
     self._target = target
     self._key = key
     self._writable = writable
     # TODO: Also allow specifying metadata object directly.
     self.__metadata = CellMetadata(
         value_type=to_value_type(type),
         persists=bool(persists),
         naming=EnumRow(
             associated_key=key,
             label=label,
             description=description,
             sort_key=sort_key))
Exemplo n.º 17
0
 def default_type(self):
     return to_value_type(bool)
Exemplo n.º 18
0
 def default_type(self):
     return to_value_type(self.__type_obj)
Exemplo n.º 19
0
 def default_type(self):
     return to_value_type(object)
Exemplo n.º 20
0
import json
import os
import os.path
import urllib

from twisted.python import log
from twisted.web import http
from twisted.web import resource

from shinysdr.types import Enum, to_value_type


_NO_DEFAULT = object()
_json_columns = {
    u'type': (Enum({'channel': 'channel', 'band': 'band'}), 'channel'),
    u'lowerFreq': (to_value_type(float), _NO_DEFAULT),
    u'upperFreq': (to_value_type(float), _NO_DEFAULT),
    u'mode': (to_value_type(unicode), u''),
    u'label': (to_value_type(unicode), u''),
    u'notes': (to_value_type(unicode), u''),
    u'location': (lambda x: x, None),  # TODO missing constraint
}

_LOWEST_RKEY = 1


class DatabaseModel(object):
    __dirty = False
    
    def __init__(self, reactor, records, pathname=None, writable=False):
        assert isinstance(records, dict)
Exemplo n.º 21
0
 def default_type(self):
     return to_value_type(object)
Exemplo n.º 22
0
 def __init__(self, name, type):
     # pylint: disable=redefined-builtin
     self.__name = name
     self.__type = to_value_type(type)
Exemplo n.º 23
0
import json
import os
import os.path
import urllib

from twisted.python import log
from twisted.web import http
from twisted.web import resource

from shinysdr.types import Enum, to_value_type


_NO_DEFAULT = object()
_json_columns = {
    u'type': (Enum({'channel': 'channel', 'band': 'band'}), 'channel'),
    u'lowerFreq': (to_value_type(float), _NO_DEFAULT),
    u'upperFreq': (to_value_type(float), _NO_DEFAULT),
    u'mode': (to_value_type(unicode), u''),
    u'label': (to_value_type(unicode), u''),
    u'notes': (to_value_type(unicode), u''),
    u'location': (lambda x: x, None),  # TODO missing constraint
}

_LOWEST_RKEY = 1


class DatabaseModel(object):
    __dirty = False
    
    def __init__(self, reactor, records, pathname=None, writable=False):
        assert isinstance(records, dict)
Exemplo n.º 24
0
 def default_type(self):
     return to_value_type(self.__type_obj)
Exemplo n.º 25
0
 def default_type(self):
     return to_value_type(bool)
Exemplo n.º 26
0
 def type(self):
     """implements BaseCell"""
     return to_value_type(type(None))
Exemplo n.º 27
0
 def __init__(self, name, type):
     # pylint: disable=redefined-builtin
     self.__name = name
     self.__type = to_value_type(type)
Exemplo n.º 28
0
 def __init__(self, target, key, type, **kwargs):
     BaseCell.__init__(self, target, key, **kwargs)
     self._value_type = to_value_type(type)
Exemplo n.º 29
0
import json
import os
import os.path
import urllib

from twisted.python import log
from twisted.web import http
from twisted.web import resource

from shinysdr.types import EnumT, to_value_type


_NO_DEFAULT = object()
_json_columns = {
    u"type": (EnumT({"channel": "channel", "band": "band"}), "channel"),
    u"lowerFreq": (to_value_type(float), _NO_DEFAULT),
    u"upperFreq": (to_value_type(float), _NO_DEFAULT),
    u"mode": (to_value_type(unicode), u""),
    u"label": (to_value_type(unicode), u""),
    u"notes": (to_value_type(unicode), u""),
    u"location": (lambda x: x, None),  # TODO missing constraint
}

_LOWEST_RKEY = 1


class DatabaseModel(object):
    __dirty = False

    def __init__(self, reactor, records, pathname=None, writable=False):
        assert isinstance(records, dict)
Exemplo n.º 30
0
 def __init__(self, target, key, type, **kwargs):
     BaseCell.__init__(self, target, key, **kwargs)
     self._value_type = to_value_type(type)