Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor edits to make code flake8 clean. #15

Merged
merged 1 commit into from
Mar 16, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/cyclone_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import collections
import functools
import os.path
import sys

import cyclone.web
Expand Down Expand Up @@ -62,7 +61,7 @@ def setup(self, host, port, dbid, poolsize):

def subscribe(self, channel):
if RedisMixin.psconn is None:
raise cyclone.web.HTTPError(503) # Service Unavailable
raise cyclone.web.HTTPError(503) # Service Unavailable

if channel not in RedisMixin.channels:
log.msg("Subscribing entire server to %s" % channel)
Expand Down Expand Up @@ -125,7 +124,8 @@ def post(self, key):
try:
yield self.dbconn.set(key, value)
except Exception, e:
log.err("Redis failed to set('%s', '%s'): %s" % (key, value, str(e)))
r = (key, value, str(e))
log.err("Redis failed to set('%s', '%s'): %s" % r)
raise cyclone.web.HTTPError(503)

self.set_header("Content-Type", "text/plain")
Expand Down
1 change: 1 addition & 0 deletions examples/sharding.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from twisted.internet import defer
from twisted.internet import reactor


@defer.inlineCallbacks
def main():
# run two redis servers, one at port 6379 and another in 6380
Expand Down
1 change: 0 additions & 1 deletion examples/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from twisted.application import internet
from twisted.application import service
from twisted.internet import reactor


class myProtocol(redis.SubscriberProtocol):
Expand Down
4 changes: 4 additions & 0 deletions examples/twistedweb_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@
from twisted.web import xmlrpc
from twisted.web.resource import Resource


class Root(Resource):
isLeaf = False


class BaseHandler(object):
isLeaf = True

def __init__(self, db):
self.db = db
Resource.__init__(self)


class IndexHandler(BaseHandler, Resource):
def _success(self, value, request, message):
request.write(message % repr(value))
Expand Down
11 changes: 6 additions & 5 deletions examples/wordfreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from twisted.internet import defer
from twisted.internet import reactor


def wordfreq(file):
try:
f = open(file, 'r')
Expand All @@ -16,14 +17,14 @@ def wordfreq(file):
print "Exception: %s" % e
return None

wf={}
wf = {}
wlist = words.split()
for b in wlist:
a=b.lower()
if wf.has_key(a):
wf[a]=wf[a]+1
a = b.lower()
if a in wf:
wf[a] = wf[a] + 1
else:
wf[a]=1
wf[a] = 1
return len(wf), wf


Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import setuptools

setuptools.setup(
Expand Down
10 changes: 5 additions & 5 deletions tests/chash_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

if __name__ == "__main__":
ch = HashRing(["server1", "server2", "server3"])
key_history={}
node_histogram=defaultdict(lambda: 0)
key_history = {}
node_histogram = defaultdict(lambda: 0)
for x in xrange(1000):
key_history[x]=ch.get_node("k:%d" % x)
s=key_history[x]
node_histogram[s]=node_histogram[s]+1
key_history[x] = ch.get_node("k:%d" % x)
s = key_history[x]
node_histogram[s] = node_histogram[s] + 1
print "server\t\tkeys:"
for a in node_histogram.keys():
print "%s:\t%d" % (a, node_histogram[a])
12 changes: 7 additions & 5 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

from twisted.internet import base
from twisted.internet import defer
from twisted.internet import reactor
from twisted.trial import unittest

base.DelayedCall.debug = False
redis_host="localhost"
redis_port=6379
redis_host = "localhost"
redis_port = 6379


class TestConnectionMethods(unittest.TestCase):
@defer.inlineCallbacks
Expand All @@ -33,13 +33,15 @@ def test_Connection(self):

@defer.inlineCallbacks
def test_ConnectionDB1(self):
db = yield redis.Connection(redis_host, redis_port, dbid=1, reconnect=False)
db = yield redis.Connection(redis_host, redis_port, dbid=1,
reconnect=False)
self.assertEqual(isinstance(db, redis.ConnectionHandler), True)
yield db.disconnect()

@defer.inlineCallbacks
def test_ConnectionPool(self):
db = yield redis.ConnectionPool(redis_host, redis_port, poolsize=2, reconnect=False)
db = yield redis.ConnectionPool(redis_host, redis_port, poolsize=2,
reconnect=False)
self.assertEqual(isinstance(db, redis.ConnectionHandler), True)
yield db.disconnect()

Expand Down
12 changes: 6 additions & 6 deletions tests/test_hash_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import txredisapi as redis

from twisted.internet import defer
from twisted.internet import reactor
from twisted.trial import unittest

redis_host="localhost"
redis_port=6379
redis_host = "localhost"
redis_port = 6379


class TestRedisHashOperations(unittest.TestCase):
@defer.inlineCallbacks
Expand All @@ -39,7 +39,7 @@ def testRedisHMSetHMGet(self):
t_dict = {}
t_dict['key1'] = 'uno'
t_dict['key2'] = 'dos'
s = yield db.hmset("txredisapi:HMSetHMGet", t_dict)
yield db.hmset("txredisapi:HMSetHMGet", t_dict)
ks = t_dict.keys()
ks.reverse()
vs = t_dict.values()
Expand All @@ -55,7 +55,7 @@ def testRedisHKeysHVals(self):
t_dict = {}
t_dict['key1'] = 'uno'
t_dict['key2'] = 'dos'
s = yield db.hmset("txredisapi:HKeysHVals", t_dict)
yield db.hmset("txredisapi:HKeysHVals", t_dict)

vs_u = [unicode(v) for v in t_dict.values()]
ks_u = [unicode(k) for k in t_dict.keys()]
Expand Down Expand Up @@ -106,7 +106,7 @@ def testRedisHLenHDelHExists(self):
def testRedisHGetAll(self):
db = yield redis.Connection(redis_host, redis_port, reconnect=False)

d = {u"key1":u"uno", u"key2":u"dos"}
d = {u"key1": u"uno", u"key2": u"dos"}
yield db.hmset("txredisapi:HGetAll", d)
s = yield db.hgetall("txredisapi:HGetAll")

Expand Down
11 changes: 6 additions & 5 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@

import txredisapi as redis
from twisted.internet import defer
from twisted.internet import reactor
from twisted.trial import unittest

redis_host="localhost"
redis_port=6379
redis_host = "localhost"
redis_port = 6379


class TestRedisConnections(unittest.TestCase):
@defer.inlineCallbacks
def testRedisOperations(self):
db = yield redis.Connection(redis_host, redis_port, reconnect=False)

# test set() operation
for key, value in (("txredisapi:test1", "foo"), ("txredisapi:test2", "bar")):
kvpairs = (("txredisapi:test1", "foo"), ("txredisapi:test2", "bar"))
for key, value in kvpairs:
yield db.set(key, value)
result = yield db.get(key)
self.assertEqual(result, value)

d = {"txredisapi:a":1, "txredisapi:b":2}
d = {"txredisapi:a": 1, "txredisapi:b": 2}
yield db.mset(d)
values = yield db.mget(d.keys())
self.assertEqual(values, d.values())
Expand Down
7 changes: 4 additions & 3 deletions tests/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
# limitations under the License.

import txredisapi as redis
from twisted.internet import defer, reactor
from twisted.internet import defer
from twisted.trial import unittest

redis_host="localhost"
redis_port=6379
redis_host = "localhost"
redis_port = 6379


class TestRedisConnections(unittest.TestCase):
@defer.inlineCallbacks
Expand Down
4 changes: 2 additions & 2 deletions tests/test_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from twisted.python.failure import Failure
from twisted.trial import unittest

redis_host="localhost"
redis_port=6379
redis_host = "localhost"
redis_port = 6379


class TestRedisConnections(unittest.TestCase):
Expand Down