def _channel(self, channel, as_bytes=True): # Construct a channel name using any specified namespace. if self._namespace is not None: channel = build_id(self._namespace, channel) if as_bytes: return to_bytes(channel) return channel
def set_default(self, key, val): self._settings.setdefault(key, to_bytes(val))
def set(self, key, val): self._settings[key] = to_bytes(val)
def get(self, key): section, option = self._config_components(key) val = section.get(option, None) if val is not None: val = to_bytes(val) return val
def publish(self, channel, message): # Enumerate all the callbacks for the specified channel and invoke them. message = to_bytes(message) if channel in self._bus: for cb in self._bus[channel]: cb(to_bytes(channel), message)
def test_bytes(self): self.assertEqual(service_utils.to_bytes(b'bar'), b'bar')
def test_number(self): self.assertEqual(service_utils.to_bytes(123), b'123')
def test_string(self): self.assertEqual(service_utils.to_bytes('foo'), b'foo')