[Pkg-mpd-commits] [python-mpd] 252/262: make code pep8 compliant

Simon McVittie smcv at debian.org
Sun May 22 18:16:54 UTC 2016


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch upstream
in repository python-mpd.

commit d2d9868c5fbf4221d5d35f5d704307d084d6df8a
Author: Jörg Thalheim <joerg at higgsboson.tk>
Date:   Wed Oct 14 20:43:46 2015 +0200

    make code pep8 compliant
---
 mpd.py  | 42 ++++++++++++++++++++++++++++++++----------
 test.py | 49 ++++++++++++++++++++++++++++++-------------------
 2 files changed, 62 insertions(+), 29 deletions(-)

diff --git a/mpd.py b/mpd.py
index d9e7a81..0c6fc01 100644
--- a/mpd.py
+++ b/mpd.py
@@ -29,15 +29,23 @@ NEXT = "list_OK"
 
 IS_PYTHON2 = sys.version_info < (3, 0)
 if IS_PYTHON2:
-    decode_str = lambda s: s.decode("utf-8")
-    encode_str = lambda s: s if type(s) == str else (unicode(s)).encode("utf-8")
+    def decode_str(s):
+        return s.decode("utf-8")
+
+    def encode_str(s):
+        if type(s) == str:
+            return s
+        else:
+            return (unicode(s)).encode("utf-8")
 else:
-    decode_str = lambda s: s
-    encode_str = lambda s: str(s)
+
+    def decode_str(s):
+        return s
+    encode_str = str
 
 try:
     from logging import NullHandler
-except ImportError: # NullHandler was introduced in python2.7
+except ImportError:  # NullHandler was introduced in python2.7
     class NullHandler(logging.Handler):
         def emit(self, record):
             pass
@@ -45,24 +53,31 @@ except ImportError: # NullHandler was introduced in python2.7
 logger = logging.getLogger(__name__)
 logger.addHandler(NullHandler())
 
+
 class MPDError(Exception):
     pass
 
+
 class ConnectionError(MPDError):
     pass
 
+
 class ProtocolError(MPDError):
     pass
 
+
 class CommandError(MPDError):
     pass
 
+
 class CommandListError(MPDError):
     pass
 
+
 class PendingCommandError(MPDError):
     pass
 
+
 class IteratingError(MPDError):
     pass
 
@@ -188,6 +203,7 @@ _commands = {
     "sendmessage":        "_fetch_nothing",
 }
 
+
 class MPDClient(object):
     def __init__(self, use_unicode=False):
         self.iterate = False
@@ -229,7 +245,7 @@ class MPDClient(object):
         if self._command_list is not None:
             if not isinstance(retval, Callable):
                 raise CommandListError("'%s' not allowed in command list" %
-                                        command)
+                                       command)
             self._write_command(command, args)
             self._command_list.append(retval)
         else:
@@ -431,7 +447,8 @@ class MPDClient(object):
 
     def noidle(self):
         if not self._pending or self._pending[0] != 'idle':
-          raise CommandError('cannot send noidle if send_idle was not called')
+            msg = 'cannot send noidle if send_idle was not called'
+            raise CommandError(msg)
         del self._pending[0]
         self._write_command("noidle")
         return self._fetch_list()
@@ -492,20 +509,22 @@ class MPDClient(object):
 
     def _settimeout(self, timeout):
         self._timeout = timeout
-        if self._sock != None:
+        if self._sock is not None:
             self._sock.settimeout(timeout)
+
     def _gettimeout(self):
         return self._timeout
+
     timeout = property(_gettimeout, _settimeout)
     _timeout = None
     idletimeout = None
 
     def connect(self, host, port, timeout=None):
         logger.info("Calling MPD connect(%r, %r, timeout=%r)", host,
-                     port, timeout)
+                    port, timeout)
         if self._sock is not None:
             raise ConnectionError("Already connected")
-        if timeout != None:
+        if timeout is not None:
             warnings.warn("The timeout parameter in connect() is deprecated! "
                           "Use MPDClient.timeout = yourtimeout instead.",
                           DeprecationWarning)
@@ -588,6 +607,7 @@ class MPDClient(object):
         delattr(cls, str("send_" + name))
         delattr(cls, str("fetch_" + name))
 
+
 def bound_decorator(self, function):
     """ bind decorator to self """
     if not isinstance(function, Callable):
@@ -597,6 +617,7 @@ def bound_decorator(self, function):
         return function(self, *args, **kwargs)
     return decorator
 
+
 def newFunction(wrapper, name, returnValue):
     def decorator(self, *args):
         return wrapper(self, name, args, bound_decorator(self, returnValue))
@@ -606,6 +627,7 @@ for key, value in _commands.items():
     returnValue = None if value is None else MPDClient.__dict__[value]
     MPDClient.add_command(key, returnValue)
 
+
 def escape(text):
     return text.replace("\\", "\\\\").replace('"', '\\"')
 
diff --git a/test.py b/test.py
index 453dcba..59aa22a 100755
--- a/test.py
+++ b/test.py
@@ -2,8 +2,6 @@
 # -*- coding: utf-8 -*-
 
 import itertools
-import os
-from socket import error as SocketError
 import sys
 import types
 import warnings
@@ -124,7 +122,10 @@ class TestMPDClient(unittest.TestCase):
         self.assertIsInstance(stats, dict)
 
     def test_fetch_songs(self):
-        self.MPDWillReturn("file: my-song.ogg\n", "Pos: 0\n", "Id: 66\n", "OK\n")
+        self.MPDWillReturn("file: my-song.ogg\n",
+                           "Pos: 0\n",
+                           "Id: 66\n",
+                           "OK\n")
         playlist = self.client.playlistinfo()
 
         self.assertMPDReceived('playlistinfo\n')
@@ -147,7 +148,10 @@ class TestMPDClient(unittest.TestCase):
         self.assertEqual({'volume': '50'}, status)
 
     def test_readcomments(self):
-        self.MPDWillReturn("major_brand: M4V\n", "minor_version: 1\n", "lyrics: Lalala\n", "OK\n")
+        self.MPDWillReturn("major_brand: M4V\n",
+                           "minor_version: 1\n",
+                           "lyrics: Lalala\n",
+                           "OK\n")
         comments = self.client.readcomments()
         self.assertMPDReceived('readcomments\n')
         self.assertEqual(comments['major_brand'], "M4V")
@@ -155,7 +159,10 @@ class TestMPDClient(unittest.TestCase):
         self.assertEqual(comments['lyrics'], "Lalala")
 
     def test_iterating(self):
-        self.MPDWillReturn("file: my-song.ogg\n", "Pos: 0\n", "Id: 66\n", "OK\n")
+        self.MPDWillReturn("file: my-song.ogg\n",
+                           "Pos: 0\n",
+                           "Id: 66\n",
+                           "OK\n")
         self.client.iterate = True
         playlist = self.client.playlistinfo()
         self.assertMPDReceived('playlistinfo\n')
@@ -167,7 +174,7 @@ class TestMPDClient(unittest.TestCase):
             self.assertEqual('66', song['id'])
 
     def test_idle(self):
-        self.MPDWillReturn('OK\n') # nothing changed after idle-ing
+        self.MPDWillReturn('OK\n')  # nothing changed after idle-ing
         self.client.idletimeout = 456
         res = self.client.idle()
         self.assertMPDReceived('idle\n')
@@ -183,9 +190,9 @@ class TestMPDClient(unittest.TestCase):
         self.assertEqual(event, ['update'])
 
     def test_noidle(self):
-        self.MPDWillReturn('OK\n') # nothing changed after idle-ing
+        self.MPDWillReturn('OK\n')  # nothing changed after idle-ing
         self.client.send_idle()
-        self.MPDWillReturn('OK\n') # nothing changed after noidle
+        self.MPDWillReturn('OK\n')  # nothing changed after noidle
         self.assertEqual(self.client.noidle(), [])
         self.assertMPDReceived('noidle\n')
         self.MPDWillReturn("volume: 50\n", "OK\n")
@@ -193,9 +200,9 @@ class TestMPDClient(unittest.TestCase):
         self.assertMPDReceived('status\n')
 
     def test_noidle_while_idle_started_sending(self):
-        self.MPDWillReturn('OK\n') # nothing changed after idle-ing
+        self.MPDWillReturn('OK\n')  # nothing changed after idle-ing
         self.client.send_idle()
-        self.MPDWillReturn('changed: player\n', 'OK\n') # noidle response
+        self.MPDWillReturn('changed: player\n', 'OK\n')  # noidle response
         self.assertEqual(self.client.noidle(), ['player'])
         self.MPDWillReturn("volume: 50\n", "OK\n")
         status = self.client.status()
@@ -209,7 +216,8 @@ class TestMPDClient(unittest.TestCase):
     def test_add_and_remove_command(self):
         self.MPDWillReturn("ACK awesome command\n")
 
-        self.client.add_command("awesome command", mpd.MPDClient._fetch_nothing)
+        self.client.add_command("awesome command",
+                                mpd.MPDClient._fetch_nothing)
         self.assertTrue(hasattr(self.client, "awesome_command"))
         self.assertTrue(hasattr(self.client, "send_awesome_command"))
         self.assertTrue(hasattr(self.client, "fetch_awesome_command"))
@@ -244,7 +252,7 @@ class TestMPDClient(unittest.TestCase):
         self.MPDWillReturn('channel: monty\n', 'message: SPAM\n', 'OK\n')
         msg = self.client.readmessages()
         self.assertMPDReceived('readmessages\n')
-        self.assertEqual(msg, [{"channel":"monty", "message": "SPAM"}])
+        self.assertEqual(msg, [{"channel": "monty", "message": "SPAM"}])
 
         self.MPDWillReturn('OK\n')
         self.assertIsNone(self.client.unsubscribe("monty"))
@@ -268,7 +276,7 @@ class TestMPDClient(unittest.TestCase):
             self.assertMPDReceived('find "file" "☯☾☝♖✽"\n')
         else:
             self.MPDWillReturn("OK\n")
-            res = self.client.find("file","☯☾☝♖✽")
+            res = self.client.find("file", "☯☾☝♖✽")
             self.assertIsInstance(res, list)
             self.assertMPDReceived('find "file" "☯☾☝♖✽"\n')
 
@@ -342,7 +350,7 @@ class TestMPDClient(unittest.TestCase):
 
     def test_ranges_as_argument(self):
         self.MPDWillReturn('OK\n')
-        self.client.move((1,2), 2)
+        self.client.move((1, 2), 2)
         self.assertMPDReceived('move "1:2" "2"\n')
 
         self.MPDWillReturn('OK\n')
@@ -361,7 +369,7 @@ class TestMPDClient(unittest.TestCase):
 
         with self.assertRaises(ValueError):
             self.MPDWillReturn('OK\n')
-            self.client.move((1,"garbage"), 2)
+            self.client.move((1, "garbage"), 2)
             self.assertMPDReceived('move "1:" "2"\n')
 
     def test_read_stickers(self):
@@ -374,10 +382,13 @@ class TestMPDClient(unittest.TestCase):
         self.assertEqual([('foo', 'bar'), ('l', 'b')], list(res))
 
     def test_fetch_database(self):
-        self.MPDWillReturn('directory: foo\n', 'Last-Modified: 2014-01-23T16:42:46Z\n',
-            'file: bar.mp3\n', 'size: 59618802\n', 'Last-Modified: 2014-11-02T19:57:00Z\n',
-            'OK\n')
-        res = self.client.listfiles("/")
+        self.MPDWillReturn('directory: foo\n',
+                           'Last-Modified: 2014-01-23T16:42:46Z\n',
+                           'file: bar.mp3\n',
+                           'size: 59618802\n',
+                           'Last-Modified: 2014-11-02T19:57:00Z\n',
+                           'OK\n')
+        self.client.listfiles("/")
 
     def test_read_sticker_with_special_value(self):
         self.MPDWillReturn("sticker: foo==uv=vu\n", "OK\n")

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mpd/python-mpd.git



More information about the Pkg-mpd-commits mailing list