Proxy CRUD operator
| 19 | |
| 20 | |
| 21 | class ProxyHandler(object): |
| 22 | """ Proxy CRUD operator""" |
| 23 | |
| 24 | def __init__(self): |
| 25 | self.conf = ConfigHandler() |
| 26 | self.db = DbClient(self.conf.dbConn) |
| 27 | self.db.changeTable(self.conf.tableName) |
| 28 | |
| 29 | def get(self, https=False): |
| 30 | """ |
| 31 | return a proxy |
| 32 | Args: |
| 33 | https: True/False |
| 34 | Returns: |
| 35 | """ |
| 36 | proxy = self.db.get(https) |
| 37 | return Proxy.createFromJson(proxy) if proxy else None |
| 38 | |
| 39 | def pop(self, https): |
| 40 | """ |
| 41 | return and delete a useful proxy |
| 42 | :return: |
| 43 | """ |
| 44 | proxy = self.db.pop(https) |
| 45 | if proxy: |
| 46 | return Proxy.createFromJson(proxy) |
| 47 | return None |
| 48 | |
| 49 | def put(self, proxy): |
| 50 | """ |
| 51 | put proxy into use proxy |
| 52 | :return: |
| 53 | """ |
| 54 | self.db.put(proxy) |
| 55 | |
| 56 | def delete(self, proxy): |
| 57 | """ |
| 58 | delete useful proxy |
| 59 | :param proxy: |
| 60 | :return: |
| 61 | """ |
| 62 | return self.db.delete(proxy.proxy) |
| 63 | |
| 64 | def getAll(self, https=False): |
| 65 | """ |
| 66 | get all proxy from pool as Proxy list |
| 67 | :return: |
| 68 | """ |
| 69 | proxies = self.db.getAll(https) |
| 70 | return [Proxy.createFromJson(_) for _ in proxies] |
| 71 | |
| 72 | def exists(self, proxy): |
| 73 | """ |
| 74 | check proxy exists |
| 75 | :param proxy: |
| 76 | :return: |
| 77 | """ |
| 78 | return self.db.exists(proxy.proxy) |
no outgoing calls
no test coverage detected