Пример #1
0
 def __init__(self):
     self.signals = kaa.Signals('locked', 'unlocked')
     self._clients = []
     self._in_progress = None
     # Precreate a finished InProgress object that we can return when
     # not locked.
     self._in_progress_finished = kaa.InProgress().finish(None)
Пример #2
0
 def __init__(self):
     self._data = ''
     self._seq = 0
     self._requests = {}
     self.channels = []
     self._programs = {}
     self.connected = kaa.InProgress()
Пример #3
0
 def _monitor(self, address, buffer_size, retry):
     while True:
         try:
             self.status = CONNECTING
             yield kaa.inprogress(self)
             # Python 2.4 code
             # TODO: remove all python 2.4 supporting code
             self._connect_inprogress.result
             self.status = CONNECTED
             # wait until the socket is closed
             yield self.signals.subset('closed').any()
         except Exception, e:
             # connection failed
             pass
         self._connect_inprogress = kaa.InProgress()
         self.status = DISCONNECTED
         # wait some time until we retry
         yield kaa.delay(retry)
         # reset variables
         self._authenticated = False
         self._pending_challenge = None
         self._read_buffer = []
         self.status = CONNECTING
         self._socket = kaa.Socket(buffer_size)
         self._socket.chunk_size = 1024
         self._socket.signals['read'].connect(self._handle_read)
         self._socket.signals['closed'].connect(self._handle_close)
         self._socket.connect(address).exception.connect(
             self._handle_refused)
Пример #4
0
 def __init__(self, config):
     self.signals = kaa.Signals('started', 'stopped', 'epg-update')
     self.config = config
     self.multiplexes = []
     self._schedule_id = 0
     self.__initialized = kaa.InProgress()
     self.schedules = {}
Пример #5
0
 def __inprogress__(self):
     if self._clients:
         # We are locked.  Create a new InProgress on-demand if necessary.
         if not self._in_progress:
             self._in_progress = kaa.InProgress()
         return self._in_progress
     else:
         return self._in_progress_finished
Пример #6
0
    def _emit_finished(self, exc):
        self.signals['finished'].emit(exc)
        if exc is None:
            self._finished_inprogress.finish(None)
        else:
            self._finished_inprogress.throw(type(exc), exc, None)

        # Create new InProgress for next stream.
        self._finished_inprogress = kaa.InProgress()
Пример #7
0
 def send(self, command, **args):
     async = args.pop('async', True)
     self._seq += 1
     args['method'] = command
     args['seq'] = self._seq
     value = ''.join([self._encode(*i) for i in args.items()])
     if async:
         self._requests[self._seq] = kaa.InProgress()
     self.socket.write(struct.pack('>I', len(value)) + value)
     if async:
         return self._requests[self._seq]
Пример #8
0
 def list(self):
     """
     Return a Query object with all subitems of this item. If the
     client is not connected to the server an empty list will be
     returned instead.
     """
     # This function is not used internally
     if not self._beacon_id:
         result = kaa.InProgress()
         result.finish([])
         # FIXME: return empty Query object
         return result
     return self._beacon_controller.query(parent=self)
Пример #9
0
    def rpc(self, cmd, *args, **kwargs):
        """
        Call the remote command and return InProgress.
        """
        if not CoreThreading.is_mainthread():
            # create InProgress object and return
            callback = kaa.InProgress()
            kwargs['_kaa_rpc_callback'] = callback
            kaa.MainThreadCallable(self.rpc)(cmd, *args, **kwargs)
            return callback

        if not self.connected:
            raise NotConnectedError()

        seq = self._next_seq
        self._next_seq += 1
        # create InProgress object
        callback = kwargs.pop('_kaa_rpc_callback', kaa.InProgress())
        payload = cPickle.dumps((cmd, args, kwargs), PICKLE_PROTOCOL)
        self._send_packet(seq, 'CALL', payload)
        # callback with error handler
        self._rpc_in_progress[seq] = (callback, cmd)
        return callback
Пример #10
0
 def query(self, **query):
     """
     Main query function. This function will call one of the specific
     query functions in this class depending on the query. This function
     returns an InProgress.
     """
     # Remove non-true recursive attribute from query (non-recursive is default).
     if not query.get('recursive', True):
         del query['recursive']
     # Passed by caller to collect list of deleted items for directory query.
     garbage = query.pop('garbage', None)
     # do query based on type
     if query.keys() == ['filename']:
         fname = os.path.realpath(query['filename'])
         return kaa.InProgress().execute(self.query_filename, fname)
     if query.keys() == ['id']:
         return kaa.InProgress().execute(self._db_query_id, query['id'])
     if sorted(query.keys()) == ['parent', 'recursive']:
         if not query['parent']._beacon_isdir:
             raise AttributeError('parent is no directory')
         return self._db_query_dir_recursive(query['parent'], garbage)
     if 'parent' in query:
         if len(query) == 1:
             if query['parent']._beacon_isdir:
                 return self._db_query_dir(query['parent'], garbage)
         query['parent'] = query['parent']._beacon_id
     if 'media' not in query and query.get('type') != 'media':
         # query only media we have right now
         query['media'] = db.QExpr('in', self.medialist.get_all_beacon_ids())
     elif query.get('media') == 'all':
         del query['media']
     if 'attr' in query:
         return kaa.InProgress().execute(self._db_query_attr, query)
     if query.get('type') == 'media':
         return kaa.InProgress().execute(self._db.query, **query)
     return self._db_query_raw(query)
Пример #11
0
 def _call(self, cmd):
     self._busy = True
     log.debug('cmd %s', cmd)
     if self.dvbstreamer.stopping:
         log.info('waiting for dvbstreamer to be stopped')
         yield kaa.inprogress(self.dvbstreamer)
     if not self.dvbstreamer.running:
         # FIXME: this only works up to dvb9 but that should be enough
         log.info('starting dvbstreamer')
         self.dvbstreamer.start(['-a', self.config.adapter[-1]])
     async = kaa.InProgress()
     if self._ready:
         self._ready = False
         self._callback = async
         self.dvbstreamer.write(cmd + '\n')
Пример #12
0
    def __init__(self):
        super(Player, self).__init__()
        # Backend instance currently in use.  This is assigned in open()
        self._backend = None
        # kaa.display.X11Window object; False means video disabled.
        self._window = None
        # The inner window that is created and managed by the backend.
        self._window_inner = None
        # kaa.metadata Media object for the currently opened mrl.
        self._media = None
        self._stream = StreamProperties(self)

        # If not None, is an InProgress object
        self._open_inprogress = None
        self._finished_inprogress = kaa.InProgress()

        # Either the globally default config, or a copy-on-write clone of the global
        # config if the user accessed the config property.
        self._config = config
Пример #13
0
 def __init__(self, client, **query):
     """
     Create a Query object and start the query on the client
     """
     # FIXME: progress and up-to-date seems not used
     self.signals = kaa.Signals('changed', 'progress', 'up-to-date')
     self.id = Query.NEXT_ID
     Query.NEXT_ID += 1
     # public variables
     self.result = []
     # internal variables
     self._query = query
     self._client = client
     self._beacon_monitoring = False
     # some shortcuts from the client
     self._rpc = self._client.rpc
     # InProgress object
     self._async = kaa.InProgress()
     # start inititial query
     self._beacon_start_query(query)
Пример #14
0
    def _reset(self):
        self._buf_plaintext = []
        self._buf_ciphertext = []

        # Delete wrapper objects so the BIO/SSL objects get freed.
        self._bio_ssl = None
        self._bio_network = None
        self._ssl = None

        # True while performing initial handshake, False once it completes.
        self._handshake = False
        # True once starttls_*() has been called.
        self._tls_started = False
        # True once the peer's certificate has been verified (or ignored if verify=False)
        self._validated = False
        # True if starttls_client() was called, False otherwise.
        self._is_client = False
        # kwargs passed to starttls_(client|server) for use by _check()
        self._starttls_kwargs = None
        # InProgress finished when starttls completes or fails.
        self._tls_ip = kaa.InProgress()
Пример #15
0
    def __init__(self,
                 surf1,
                 surf2,
                 mode=-1,
                 direction='vertical',
                 fps=25,
                 speed=1):
        """
        Initialise an instance of the Transition class
        @ivar surf1: Surface to blend with
        @ivar surf2: New surface
        @ivar mode: effect to use
        @ivar direction: vertical/horizontal
        """
        BaseAnimation.__init__(self, surf1.get_rect(), fps, bg_update=False)
        logger.log(
            9, '__init__(surf1=%r, surf2=%r, mode=%r, direction=%r, fps=%r)',
            surf1, surf2, mode, direction, fps)

        self.steps = fps
        self.mode = mode
        self.direction = direction

        self.speed = speed

        # WARNING: self.drawfuncs should not contain links to it's member
        # functions because this results in circular dependencies and the
        # Python garbage collector won't work
        self.drawfuncs = {
            0: 'draw_blend_alpha',
            1: 'draw_wipe',
            2: 'draw_wipe_alpha'
        }

        self.surf_blend1 = surf1.convert()
        self.surf_blend2 = surf2.convert()
        self.inprogress = kaa.InProgress()
        self.prepare()
Пример #16
0
    def __init__(self, sock, auth_secret):
        super(Channel, self).__init__()
        self._socket = sock
        self._authenticated = False
        self._connect_inprogress = kaa.InProgress()
        # We start off in an unauthenticated state; set chunk size to something
        # small to prevent untrusted remote from flooding read buffer.
        self._socket.chunk_size = 1024
        # Buffer containing packets deferred until after authentication.
        self._write_buffer_deferred = []
        self._read_buffer = []
        self._callbacks = {}
        self._next_seq = 1
        self._rpc_in_progress = {}
        self._auth_secret = py3_b(auth_secret)
        self._pending_challenge = None

        # Creates a circular reference so that RPC channels survive even when
        # there is no reference to them.  (Servers may not hold references to
        # clients channels.)  As long as the socket is connected, the channel
        # will survive.
        self._socket.signals['read'].connect(self._handle_read)
        self._socket.signals['closed'].connect(self._handle_close)
Пример #17
0
 def acquire_read_lock(self):
     """
     Stub on the client side: implemented in the server db
     """
     return kaa.InProgress().finish(None)