Browse Source

Cosmetics for #3079

Ask Solem 9 years ago
parent
commit
ec1ad9c2db

+ 4 - 4
celery/backends/cache.py

@@ -151,10 +151,10 @@ class CacheBackend(KeyValueStoreBackend):
         return super(CacheBackend, self).__reduce__(args, kwargs)
 
     def as_uri(self, *args, **kwargs):
-        """
-        Return the backend as an URI. It properly handles the
-        case of multiple servers. It doesn't try to sanitize
-        password because memcached URIs doesn't support them.
+        """Return the backend as an URI.
+
+        This properly handles the case of multiple servers.
+
         """
         servers = ';'.join(self.servers)
         return '{0}://{1}/'.format(self.backend, servers)

+ 13 - 12
celery/backends/mongodb.py

@@ -84,7 +84,7 @@ class MongoBackend(BaseBackend):
             uri_data = pymongo.uri_parser.parse_uri(self.url)
             # build the hosts list to create a mongo connection
             hostslist = [
-                "{0}:{1}".format(x[0], x[1]) for x in uri_data['nodelist']
+                '{0}:{1}'.format(x[0], x[1]) for x in uri_data['nodelist']
             ]
             self.user = uri_data['username']
             self.password = uri_data['password']
@@ -230,11 +230,11 @@ class MongoBackend(BaseBackend):
         self.group_collection.remove({'_id': group_id})
 
     def _forget(self, task_id):
-        """
-        Remove result from MongoDB.
+        """Remove result from MongoDB.
+
+        :raises celery.exceptions.OperationsError:
+            if the task_id could not be removed.
 
-        :raises celery.exceptions.OperationsError: if the task_id could not be
-                                                   removed.
         """
         # By using safe=True, this will wait until it receives a response from
         # the server.  Likewise, it will raise an OperationsError if the
@@ -296,15 +296,16 @@ class MongoBackend(BaseBackend):
         return timedelta(seconds=self.expires)
 
     def as_uri(self, include_password=False):
-        """
-        Return the backend as an URI, sanitizing the password or not.
-        It properly handles the case of a replica set.
+        """Return the backend as an URI.
+
+        :keyword include_password: Censor passwords.
+
         """
         if include_password:
             return self.url
 
-        if "," not in self.url:
-            return maybe_sanitize_url(self.url).rstrip("/")
+        if ',' not in self.url:
+            return maybe_sanitize_url(self.url).rstrip('/')
 
-        uri1, remainder = self.url.split(",", 1)
-        return ",".join([maybe_sanitize_url(uri1).rstrip("/"), remainder])
+        uri1, remainder = self.url.split(',', 1)
+        return ','.join([maybe_sanitize_url(uri1).rstrip('/'), remainder])

+ 3 - 3
celery/tests/backends/test_base.py

@@ -594,11 +594,11 @@ class test_as_uri(AppCase):
     def setup(self):
         self.b = BaseBackend(
             app=self.app,
-            url="sch://uuuu:pwpw@hostname.dom"
+            url='sch://uuuu:pwpw@hostname.dom'
         )
 
     def test_as_uri_include_password(self):
-        self.assertEqual(self.b.as_uri(True), "sch://uuuu:pwpw@hostname.dom")
+        self.assertEqual(self.b.as_uri(True), 'sch://uuuu:pwpw@hostname.dom')
 
     def test_as_uri_exclude_password(self):
-        self.assertEqual(self.b.as_uri(), "sch://uuuu:**@hostname.dom")
+        self.assertEqual(self.b.as_uri(), 'sch://uuuu:**@hostname.dom')

+ 1 - 1
celery/tests/backends/test_cache.py

@@ -139,7 +139,7 @@ class test_CacheBackend(AppCase):
     @disable_stdouts
     def test_regression_worker_startup_info(self):
         self.app.conf.result_backend = (
-            "cache+memcached://127.0.0.1:11211;127.0.0.2:11211;127.0.0.3/"
+            'cache+memcached://127.0.0.1:11211;127.0.0.2:11211;127.0.0.3/'
         )
         worker = self.app.Worker()
         worker.on_start()

+ 7 - 7
celery/tests/backends/test_mongodb.py

@@ -31,13 +31,13 @@ MONGODB_GROUP_COLLECTION = 'group_collection1'
 
 class test_MongoBackend(AppCase):
 
-    default_url = "mongodb://uuuu:pwpw@hostname.dom/database"
+    default_url = 'mongodb://uuuu:pwpw@hostname.dom/database'
     replica_set_url = (
-        "mongodb://uuuu:pwpw@hostname.dom,"
-        "hostname.dom/database?replicaSet=rs"
+        'mongodb://uuuu:pwpw@hostname.dom,'
+        'hostname.dom/database?replicaSet=rs'
     )
-    sanitized_default_url = default_url.replace("pwpw", "**")
-    sanitized_replica_set_url = replica_set_url.replace("pwpw", "**")
+    sanitized_default_url = default_url.replace('pwpw', '**')
+    sanitized_replica_set_url = replica_set_url.replace('pwpw', '**')
 
     def setup(self):
         if pymongo is None:
@@ -410,8 +410,8 @@ class test_MongoBackend(AppCase):
     @disable_stdouts
     def test_regression_worker_startup_info(self):
         self.app.conf.result_backend = (
-            "mongodb://user:password@host0.com:43437,host1.com:43437"
-            "/work4us?replicaSet=rs&ssl=true"
+            'mongodb://user:password@host0.com:43437,host1.com:43437'
+            '/work4us?replicaSet=rs&ssl=true'
         )
         worker = self.app.Worker()
         worker.on_start()