8000 Merge pull request #6 from yyuu/python3 · upwlabs/fluent-logger-python@0b14cbc · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b14cbc

Browse files
committed
Merge pull request fluent#6 from yyuu/python3
support python 3.x, and not support python 2.5 anymore.
2 parents 8b3c948 + c2b7c6d commit 0b14cbc

File tree

8 files changed

+32
-24
lines changed

8 files changed

+32
-24
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ Many web/mobile applications generate huge amount of event logs (c,f. login, log
77

88
**fluent-logger-python** is a Python library, to record the events from Python application.
99

10+
## Requirements
11+
12+
* Python 2.6 or greater including 3.x
13+
< 10000 /div>
1014
## Installation
1115

1216
This library is distributed as 'fluent-logger' python package. Please execute the following command to install it.
1317

1418
$ pip install fluent-logger
1519

16-
On Python 2.5, you have to install 'simplejson' in addition.
17-
1820
## Configuration
1921

2022
Fluent daemon must be lauched with the following configuration:

fluent/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
import os
3-
import sys, urllib
3+
import sys
44
import msgpack
55
import socket
66
import threading

fluent/sender.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import msgpack
23
import socket
34
import threading
@@ -57,7 +58,7 @@ def _make_packet(self, label, timestamp, data):
5758
tag = self.tag
5859
packet = (tag, timestamp, data)
5960
if self.verbose:
60-
print packet
61+
print(packet)
6162
return self.packer.pack(packet)
6263

6364
def _send(self, bytes):

tests/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import sys
2-
sys.path = ['..'] + sys.path
3-
4-
from test_event import *
5-
from test_sender import *
6-
from test_handler import *
1+
from tests.test_event import *
2+
from tests.test_sender import *
3+
from tests.test_handler import *

tests/mockserver.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import socket
22
import threading
33
import time
4-
from cStringIO import StringIO
54
from msgpack import Unpacker
65

6+
try:
7+
from cStringIO import StringIO as BytesIO
8+
except ImportError:
9+
from io import BytesIO
10+
711
class MockRecvServer(threading.Thread):
812
"""
913
Single threaded server accepts one connection and recv until EOF.
1014
"""
1115
def __init__(self, port):
1216
self._sock = socket.socket()
1317
self._sock.bind(('localhost', port))
14-
self._buf = StringIO()
18+
self._buf = BytesIO()
1519

1620
threading.Thread.__init__(self)
1721
self.start()
@@ -36,4 +40,5 @@ def wait(self):
3640
def get_recieved(self):
3741
self.wait()
3842
self._buf.seek(0)
39-
return list(Unpacker(self._buf))
43+
# TODO: have to process string encoding properly. currently we assume that all encoding is utf-8.
44+
return list(Unpacker(self._buf, encoding='utf-8'))

tests/test_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import unittest
2-
import mockserver
2+
from tests import mockserver
33
import logging
44
import fluent.handler
55
import msgpack
66

77
class TestLogger(unittest.TestCase):
88
def setUp(self):
99
super(TestLogger, self).setUp()
10-
for port in xrange(10000, 20000):
10+
for port in range(10000, 20000):
1111
try:
1212
self._server = mockserver.MockRecvServer(port)
1313
self._port = port
1414
break
15-
except IOError, e:
15+
except IOError as e:
1616
pass
1717

1818
def get_data(self):

tests/test_sender.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
from __future__ import print_function
12
import unittest
2-
import mockserver
3+
from tests import mockserver
34
import fluent.sender
45
import msgpack
56

67
class TestSender(unittest.TestCase):
78
def setUp(self):
89
super(TestSender, self).setUp()
9-
for port in xrange(10000, 20000):
10+
for port in range(10000, 20000):
1011
try:
1112
self._server = mockserver.MockRecvServer(port)
1213
break
13-
except IOError, e:
14-
print e
14+
except IOError as e:
15+
print(e)
1516
pass
1617
self._sender = fluent.sender.FluentSender(
1718
tag='test',

tox.ini

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
[tox]
2-
envlist = py25, py26, py27
2+
envlist = py26, py27, py32
33

44
[testenv]
55
commands=python setup.py test
66

7-
[testenv:py25]
8-
deps = simplejson
9-
107
[testenv:py26]
8+
basepython = python2.6
119

1210
[testenv:py27]
11+
basepython = python2.7
12+
13+
[testenv:py32]
14+
basepython = python3.2

0 commit comments

Comments
 (0)
0