Author: tack
Date: Mon Mar 12 01:00:51 2007
New Revision: 2552
Modified:
trunk/epg/src/client.py
Log:
Raise an exception on methods that don't make sense when the client is
disconnected, and return an InProgress object when those methods are called
while the client is in the process of connecting.
Modified: trunk/epg/src/client.py
==============================================================================
--- trunk/epg/src/client.py (original)
+++ trunk/epg/src/client.py Mon Mar 12 01:00:51 2007
@@ -47,6 +47,27 @@
DISCONNECTED, CONNECTING, CONNECTED = range(3)
+def yield_execution_while_connecting():
+ """
+ Decorator that wraps kaa.notifier.yield_execution, raising an exception if
+ the client is disconnected, YieldContinue if the client is in the process
+ of connecting, or the actual return value of the decorated function if the
+ client is connected.
+ """
+ def decorator(func):
+ def newfunc(client, *args, **kwargs):
+ if client.status == DISCONNECTED:
+ raise SystemError('Client is disconnected')
+ while client.status == CONNECTING:
+ yield kaa.notifier.YieldContinue
+ yield func(client, *args, **kwargs)
+
+ newfunc.func_name = func.func_name
+ return kaa.notifier.yield_execution()(newfunc)
+ return decorator
+
+
+
class Client(object):
"""
EPG client class to access the epg on server side.
@@ -129,13 +150,17 @@
def search(self, channel=None, time=None, **kwargs):
"""
Search the db. This will call the search function on server side using
- kaa.ipc. This function will return an InProgress object.
+ kaa.ipc. This function will always return an InProgress object, even
when
+ the client is disconnected.
"""
if self.status == DISCONNECTED:
# make sure we always return InProgress
yield kaa.notifier.YieldContinue
yield []
+ while self.status == CONNECTING:
+ yield kaa.notifier.YieldContinue
+
if channel is not None:
if isinstance(channel, Channel):
kwargs["channel"] = channel.db_id
@@ -209,6 +234,7 @@
return Channel(tuner_id, name, long_name, epg=None)
+ @yield_execution_while_connecting()
def get_channel(self, name):
"""
Get channel by name.
@@ -218,6 +244,7 @@
return self._channels_by_name[name]
+ @yield_execution_while_connecting()
def get_channel_by_db_id(self, db_id):
"""
Get channel by database id.
@@ -227,6 +254,7 @@
return self._channels_by_db_id[db_id]
+ @yield_execution_while_connecting()
def get_channel_by_tuner_id(self, tuner_id):
"""
Get channel by tuner id.
@@ -236,6 +264,7 @@
return self._channels_by_tuner_id[tuner_id]
+ @yield_execution_while_connecting()
def get_channels(self):
"""
Get all channels
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog