Skip to content

Commit

Permalink
Revert 7f9b38f... [kombu3] No longer supports Python 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Nov 13, 2012
1 parent c738658 commit f42e559
Show file tree
Hide file tree
Showing 47 changed files with 254 additions and 85 deletions.
3 changes: 3 additions & 0 deletions examples/complete_receive.py
Expand Up @@ -2,6 +2,9 @@
Example of simple consumer that waits for a single message, acknowledges it
and exits.
"""

from __future__ import with_statement

from kombu import Connection, Exchange, Queue, Consumer, eventloop
from pprint import pformat

Expand Down
2 changes: 2 additions & 0 deletions examples/complete_send.py
Expand Up @@ -5,6 +5,8 @@
You can use `complete_receive.py` to receive the message sent.
"""
from __future__ import with_statement

from kombu import Connection, Producer, Exchange, Queue

#: By default messages sent to exchanges are persistent (delivery_mode=2),
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_eventlet_receive.py
Expand Up @@ -6,6 +6,8 @@
message sent.
"""
from __future__ import with_statement

import eventlet

from Queue import Empty
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_eventlet_send.py
Expand Up @@ -6,6 +6,8 @@
message sent.
"""
from __future__ import with_statement

import eventlet

from kombu import Connection
Expand Down
3 changes: 3 additions & 0 deletions examples/simple_receive.py
@@ -1,6 +1,9 @@
"""
Example receiving a message using the SimpleQueue interface.
"""

from __future__ import with_statement

from kombu import Connection

#: Create connection
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_send.py
Expand Up @@ -6,6 +6,8 @@
message sent.
"""
from __future__ import with_statement

from kombu import Connection

#: Create connection
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_task_queue/client.py
@@ -1,3 +1,5 @@
from __future__ import with_statement

from kombu.common import maybe_declare
from kombu.pools import producers

Expand Down
4 changes: 3 additions & 1 deletion examples/simple_task_queue/worker.py
@@ -1,3 +1,5 @@
from __future__ import with_statement

from kombu.mixins import ConsumerMixin
from kombu.log import get_logger
from kombu.utils import kwdict, reprcall
Expand All @@ -23,7 +25,7 @@ def process_task(self, body, message):
logger.info('Got task: %s', reprcall(fun.__name__, args, kwargs))
try:
fun(*args, **kwdict(kwargs))
except Exception as exc:
except Exception, exc:
logger.error('task raised exception: %r', exc)
message.ack()

Expand Down
3 changes: 2 additions & 1 deletion extra/release/bump_version.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python

from __future__ import absolute_import
from __future__ import with_statement

import errno
import os
Expand All @@ -22,7 +23,7 @@ def cmd(*args):
def no_enoent():
try:
yield
except OSError as exc:
except OSError, exc:
if exc.errno != errno.ENOENT:
raise

Expand Down
126 changes: 126 additions & 0 deletions extra/release/flakeplus.py
@@ -0,0 +1,126 @@
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import with_statement

import os
import re
import sys

from collections import defaultdict
from unipath import Path

RE_COMMENT = r'^\s*\#'
RE_NOQA = r'.+?\#\s+noqa+'
RE_MULTILINE_COMMENT_O = r'^\s*(?:\'\'\'|""").+?(?:\'\'\'|""")'
RE_MULTILINE_COMMENT_S = r'^\s*(?:\'\'\'|""")'
RE_MULTILINE_COMMENT_E = r'(?:^|.+?)(?:\'\'\'|""")'
RE_WITH = r'(?:^|\s+)with\s+'
RE_WITH_IMPORT = r'''from\s+ __future__\s+ import\s+ with_statement'''
RE_PRINT = r'''(?:^|\s+)print\((?:"|')(?:\W+?)?[A-Z0-9:]{2,}'''
RE_ABS_IMPORT = r'''from\s+ __future__\s+ import\s+ absolute_import'''

acc = defaultdict(lambda: {"abs": False, "print": False})


def compile(regex):
return re.compile(regex, re.VERBOSE)


class FlakePP(object):
re_comment = compile(RE_COMMENT)
re_ml_comment_o = compile(RE_MULTILINE_COMMENT_O)
re_ml_comment_s = compile(RE_MULTILINE_COMMENT_S)
re_ml_comment_e = compile(RE_MULTILINE_COMMENT_E)
re_abs_import = compile(RE_ABS_IMPORT)
re_print = compile(RE_PRINT)
re_with_import = compile(RE_WITH_IMPORT)
re_with = compile(RE_WITH)
re_noqa = compile(RE_NOQA)
map = {"abs": True, "print": False,
"with": False, "with-used": False}

def __init__(self, verbose=False):
self.verbose = verbose
self.steps = (("abs", self.re_abs_import),
("with", self.re_with_import),
("with-used", self.re_with),
("print", self.re_print))

def analyze_fh(self, fh):
steps = self.steps
filename = fh.name
acc = dict(self.map)
index = 0
errors = [0]

def error(fmt, **kwargs):
errors[0] += 1
self.announce(fmt, **dict(kwargs, filename=filename))

for index, line in enumerate(self.strip_comments(fh)):
for key, pattern in steps:
if pattern.match(line):
acc[key] = True
if index:
if not acc["abs"]:
error("%(filename)s: missing abs import")
if acc["with-used"] and not acc["with"]:
error("%(filename)s: missing with import")
if acc["print"]:
error("%(filename)s: left over print statement")

return filename, errors[0], acc

def analyze_file(self, filename):
with open(filename) as fh:
return self.analyze_fh(fh)

def analyze_tree(self, dir):
for dirpath, _, filenames in os.walk(dir):
for path in (Path(dirpath, f) for f in filenames):
if path.endswith(".py"):
yield self.analyze_file(path)

def analyze(self, *paths):
for path in map(Path, paths):
if path.isdir():
for res in self.analyze_tree(path):
yield res
else:
yield self.analyze_file(path)

def strip_comments(self, fh):
re_comment = self.re_comment
re_ml_comment_o = self.re_ml_comment_o
re_ml_comment_s = self.re_ml_comment_s
re_ml_comment_e = self.re_ml_comment_e
re_noqa = self.re_noqa
in_ml = False

for line in fh.readlines():
if in_ml:
if re_ml_comment_e.match(line):
in_ml = False
else:
if re_noqa.match(line) or re_ml_comment_o.match(line):
pass
elif re_ml_comment_s.match(line):
in_ml = True
elif re_comment.match(line):
pass
else:
yield line

def announce(self, fmt, **kwargs):
sys.stderr.write((fmt + "\n") % kwargs)


def main(argv=sys.argv, exitcode=0):
for _, errors, _ in FlakePP(verbose=True).analyze(*argv[1:]):
if errors:
exitcode = 1
return exitcode


if __name__ == "__main__":
sys.exit(main())
2 changes: 1 addition & 1 deletion funtests/transport.py
Expand Up @@ -79,7 +79,7 @@ def setUp(self):
if self.transport:
try:
self.before_connect()
except SkipTest as exc:
except SkipTest, exc:
self.skip_test_reason = str(exc)
else:
self.do_connect()
Expand Down
1 change: 1 addition & 0 deletions kombu/clocks.py
Expand Up @@ -9,6 +9,7 @@
"""
from __future__ import absolute_import
from __future__ import with_statement

import threading

Expand Down
1 change: 1 addition & 0 deletions kombu/common.py
Expand Up @@ -9,6 +9,7 @@
"""
from __future__ import absolute_import
from __future__ import with_statement

import os
import socket
Expand Down
7 changes: 4 additions & 3 deletions kombu/connection.py
Expand Up @@ -9,6 +9,7 @@
"""
from __future__ import absolute_import
from __future__ import with_statement

import errno
import os
Expand Down Expand Up @@ -286,7 +287,7 @@ def drain_nowait(self, *args, **kwargs):
except socket.timeout:
self.more_to_read = False
return False
except socket.error as exc:
except socket.error, exc:
if exc.errno in (errno.EAGAIN, errno.EINTR):
self.more_to_read = False
return False
Expand Down Expand Up @@ -420,7 +421,7 @@ def _ensured(*args, **kwargs):
for retries in count(0): # for infinity
try:
return fun(*args, **kwargs)
except self.recoverable_connection_errors as exc:
except self.recoverable_connection_errors, exc:
if got_connection:
raise
if max_retries is not None and retries > max_retries:
Expand All @@ -443,7 +444,7 @@ def _ensured(*args, **kwargs):
if on_revive:
on_revive(new_channel)
got_connection += 1
except self.recoverable_channel_errors as exc:
except self.recoverable_channel_errors, exc:
if max_retries is not None and retries > max_retries:
raise
self._debug('ensure channel error: %r', exc, exc_info=1)
Expand Down
2 changes: 1 addition & 1 deletion kombu/messaging.py
Expand Up @@ -499,7 +499,7 @@ def _receive_callback(self, message):
if m2p:
message = m2p(message)
decoded = None if on_m else message.decode()
except Exception as exc:
except Exception, exc:
if not self.on_decode_error:
raise
self.on_decode_error(message, exc)
Expand Down
1 change: 1 addition & 0 deletions kombu/mixins.py
Expand Up @@ -9,6 +9,7 @@
"""
from __future__ import absolute_import
from __future__ import with_statement

import socket

Expand Down
3 changes: 2 additions & 1 deletion kombu/pidbox.py
Expand Up @@ -9,6 +9,7 @@
"""
from __future__ import absolute_import
from __future__ import with_statement

import socket

Expand Down Expand Up @@ -82,7 +83,7 @@ def dispatch(self, method, arguments=None, reply_to=None, ticket=None,
reply = handle(method, kwdict(arguments))
except SystemExit:
raise
except Exception as exc:
except Exception, exc:
reply = {'error': repr(exc)}

if reply_to:
Expand Down
1 change: 1 addition & 0 deletions kombu/tests/test_common.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import with_statement

import socket

Expand Down
1 change: 1 addition & 0 deletions kombu/tests/test_compat.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import with_statement

from mock import patch

Expand Down
1 change: 1 addition & 0 deletions kombu/tests/test_connection.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import with_statement

import pickle

Expand Down
1 change: 1 addition & 0 deletions kombu/tests/test_entities.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import with_statement

from kombu import Connection
from kombu.entity import Exchange, Queue
Expand Down
1 change: 1 addition & 0 deletions kombu/tests/test_messaging.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import with_statement

import anyjson

Expand Down
1 change: 1 addition & 0 deletions kombu/tests/test_pidbox.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import with_statement

import socket

Expand Down
2 changes: 1 addition & 1 deletion kombu/tests/test_pools.py
@@ -1,4 +1,4 @@
from __future__ import absolute_import
from __future__ import with_statement

from kombu import Connection
from kombu import pools
Expand Down
1 change: 1 addition & 0 deletions kombu/tests/test_serialization.py
@@ -1,6 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import with_statement

import sys

Expand Down
1 change: 1 addition & 0 deletions kombu/tests/test_simple.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import with_statement

from Queue import Empty

Expand Down
1 change: 1 addition & 0 deletions kombu/tests/transport/test_base.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import with_statement

from kombu import Connection, Consumer, Producer, Queue
from kombu.transport.base import Message, StdChannel, Transport
Expand Down
1 change: 1 addition & 0 deletions kombu/tests/transport/test_filesystem.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import with_statement

import tempfile

Expand Down
1 change: 1 addition & 0 deletions kombu/tests/transport/test_memory.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import with_statement

import socket

Expand Down
1 change: 1 addition & 0 deletions kombu/tests/transport/test_redis.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import with_statement

import socket
import types
Expand Down

0 comments on commit f42e559

Please sign in to comment.