Explorar el Código

Merge branch 'jhao104/master' of https://github.com/1again/proxy_pool into 1again-jhao104/master

# Conflicts:
#	DB/DbClient.py
#	Util/GetConfig.py
jhao hace 7 años
padre
commit
6b0b95a311
Se han modificado 4 ficheros con 15 adiciones y 7 borrados
  1. 2 1
      Config.ini
  2. 2 2
      DB/MongodbClient.py
  3. 6 2
      DB/RedisClient.py
  4. 5 2
      DB/SsdbClient.py

+ 2 - 1
Config.ini

@@ -6,7 +6,8 @@ host = 127.0.0.1
 port = 6379
 ;port = 8888
 name = proxy
-#password = yourpassword
+;username = your_username (Only Mongodb)
+;password = your_password
 
 [ProxyGetter]
 ;register the proxy getter function

+ 2 - 2
DB/MongodbClient.py

@@ -17,9 +17,9 @@ from pymongo import MongoClient
 
 
 class MongodbClient(object):
-    def __init__(self, name, host, port):
+    def __init__(self, name, host, port, **kwargs):
         self.name = name
-        self.client = MongoClient(host, port)
+        self.client = MongoClient(host, port, **kwargs)
         self.db = self.client.proxy
 
     def changeTable(self, name):

+ 6 - 2
DB/RedisClient.py

@@ -22,7 +22,11 @@ class RedisClient(object):
     Reids client
     """
 
-    def __init__(self, name, host, port):
+    # 为了保持DbClient的标准
+    # 在RedisClient里面接受username参数, 但不进行使用.
+    # 因为不能将username通过kwargs传进redis.Redis里面, 会报错:
+    # TypeError: __init__() got an unexpected keyword argument 'username'
+    def __init__(self, name, host, port, username, **kwargs):
         """
         init
         :param name:
@@ -31,7 +35,7 @@ class RedisClient(object):
         :return:
         """
         self.name = name
-        self.__conn = redis.Redis(host=host, port=port, db=0)
+        self.__conn = redis.Redis(host=host, port=port, db=0, **kwargs)
 
     def get(self):
         """

+ 5 - 2
DB/SsdbClient.py

@@ -31,8 +31,11 @@ class SsdbClient(object):
         验证后的代理存放在name为useful_proxy的hash中,key为代理的ip:port,value为一个计数,初始为1,每校验失败一次减1;
 
     """
-
-    def __init__(self, name, **kwargs):
+    # 为了保持DbClient的标准
+    # 在SsdbClient里面接受username参数, 但不进行使用.
+    # 因为不能将username通过kwargs传进redis.Redis里面, 会报错:
+    # TypeError: __init__() got an unexpected keyword argument 'username'
+    def __init__(self, name, username, **kwargs):
         """
         init
         :param name: hash name