]> kaliko git repositories - python-musicpdaio.git/commitdiff
Renaming module and coding style changes
authorkaliko <kaliko@azylum.org>
Sun, 26 Apr 2015 15:52:21 +0000 (17:52 +0200)
committerkaliko <kaliko@azylum.org>
Sun, 26 Apr 2015 15:52:21 +0000 (17:52 +0200)
musicpdaio.py [moved from musicpdasio.py with 87% similarity]

similarity index 87%
rename from musicpdasio.py
rename to musicpdaio.py
index 8bd1ba447ed96c2ed6dee96d1603437a9fec9c1b..1663b2727183235a74b65c9fe447b4ca414a0e5b 100644 (file)
@@ -69,7 +69,8 @@ class Response:
                 self.version)
 
 class MPDProto(asyncio.Protocol):
-    def __init__(self, future, payload, cred):
+    def __init__(self, future, payload, pwd):
+        self.pwd = pwd
         self.transport = None
         self.future = future
         self.payload = payload
@@ -94,6 +95,8 @@ class MPDProto(asyncio.Protocol):
 
         self.sess.resp += rcv
         if rcv.endswith(SUCCESS+'\n'):
+            # Strip final SUCCESS
+            self.sess.resp = self.sess.resp[:len(SUCCESS+'\n')*-1]
             logging.debug('set future result')
             self.transport.close()
             self.future.set_result(self.sess)
@@ -108,13 +111,13 @@ class MPDProto(asyncio.Protocol):
 
 class MPDClient:
 
-    def __init__(self, host='localhost', port=6600, cred=None):
-        self.eloop = asyncio.get_event_loop()
+    def __init__(self, host='localhost', port=6600, passwd=None):
+        self._evloop = asyncio.get_event_loop()
         self.asio = False
         self.futures = []
         self._host = host
         self._port = port
-        self._cred = cred
+        self._pwd = passwd
         self._commands = {
                 'currentsong',
                 'stats',
@@ -137,7 +140,7 @@ class MPDClient:
         # coroutine allowing Exception handling
         # src: http://comments.gmane.org/gmane.comp.python.tulip/1401
         try:
-            yield from self.eloop.create_connection(lambda: proto,
+            yield from self._evloop.create_connection(lambda: proto,
                     host=self._host,
                     port=self._port)
         except Exception as err:
@@ -147,22 +150,24 @@ class MPDClient:
         payload = '{} {}'.format(command, ''.join(args))
         future = asyncio.Future()
         # kick off a task to create the connection to MPD
-        coro = self._connect(MPDProto(future, payload, self._cred))
+        coro = self._connect(MPDProto(future, payload, self._pwd))
         asyncio.async(coro)
         self.futures.append(future)
         if not self.asio:
             # return once completed.
-            self.eloop.run_until_complete(future)
+            self._evloop.run_until_complete(future)
         return future
         # alternative w/ callback
         #if not self.asio:
         #    future.add_done_callback(lambda ftr: MPDClient.loop.stop())
-        #    self.eloop.run_forever()
+        #    self._evloop.run_forever()
         #return future
 
     def run(self):
+        """Run event loop gathering tasks from self.futures
+        """
         if self.futures:
-           self.eloop.run_until_complete(asyncio.gather(*self.futures))
+           self._evloop.run_until_complete(asyncio.gather(*self.futures))
            self.futures = []
         else:
             logging.info('No task found in queue, need to set self.asio?')