Browse Source

make things plural and refactor pool into its own class

master
Brett Langdon 12 years ago
parent
commit
399e69ead4
7 changed files with 177 additions and 108 deletions
  1. +0
    -5
      docs/client.rst
  2. +5
    -0
      docs/clients.rst
  3. +2
    -1
      docs/index.rst
  4. +5
    -0
      docs/pools.rst
  5. +96
    -101
      riakcached/clients.py
  6. +68
    -0
      riakcached/pools.py
  7. +1
    -1
      riakcached/tests/test_riakclient.py

+ 0
- 5
docs/client.rst View File

@ -1,5 +0,0 @@
riakcached.client
=================
.. automodule:: riakcached.client
:members:

+ 5
- 0
docs/clients.rst View File

@ -0,0 +1,5 @@
riakcached.clients
=================
.. automodule:: riakcached.clients
:members:

+ 2
- 1
docs/index.rst View File

@ -6,8 +6,9 @@ Contents:
.. toctree::
:maxdepth: 2
client
clients
exceptions
pools
A Memcached like interface to the Riak HTTP API.


+ 5
- 0
docs/pools.rst View File

@ -0,0 +1,5 @@
riakcached.pools
================
.. automodule:: riakcached.pools
:members:

riakcached/client.py → riakcached/clients.py View File


+ 68
- 0
riakcached/pools.py View File

@ -0,0 +1,68 @@
import urllib3
from riakcached import exceptions
class Pool(object):
"""
"""
__slots__ = ["timeout", "url"]
def __init__(self, base_url="http://127.0.0.1:8098", timeout=2, auto_connect=True):
"""
"""
self.url = base_url
self.timeout = timeout
if auto_connect:
self.connect()
def connect(self):
"""
"""
raise NotImplementedError("You must not use %s directly" % self.__class__.__name__)
def close(self):
"""
"""
raise NotImplementedError("You must not use %s directly" % self.__class__.__name__)
def request(self, method, url, body=None, headers=None):
"""
"""
raise NotImplementedError("You must not use %s directly" % self.__class__.__name__)
class Urllib3Pool(Pool):
"""
"""
__slots__ = ["pool"]
def connect(self):
"""
"""
self.pool = urllib3.connection_from_url(self.url)
def close(self):
"""
"""
if self.pool:
self.pool.close()
def request(self, method, url, body=None, headers=None):
"""
"""
try:
response = self.pool.urlopen(
method=method,
url=url,
body=body,
headers=headers,
timeout=self.timeout,
redirect=False,
)
return response.status, response.data, response.getheaders()
except urllib3.exceptions.TimeoutError, e:
raise exceptions.RiakcachedTimeout(e.message)
except urllib3.exceptions.HTTPError, e:
raise exceptions.RiakcachedConnectionError(e.message)
return None, None, None

riakcached/tests/test_client.py → riakcached/tests/test_riakclient.py View File


Loading…
Cancel
Save