Browse Source

More python 3 compatibilities

opensearch
Roi Rav-Hon 8 years ago
parent
commit
7f6031f7f9
3 changed files with 17 additions and 8 deletions
  1. +5
    -2
      .travis.yml
  2. +1
    -1
      logzio/sender.py
  3. +11
    -5
      tests/mockLogzioListener/listener.py

+ 5
- 2
.travis.yml View File

@ -1,12 +1,15 @@
language: python
python:
- "2.6"
- "2.7"
- "3.0"
- "3.1"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
install:
- pip install requests future
script: py.test
script: py.test3

+ 1
- 1
logzio/sender.py View File

@ -92,7 +92,7 @@ class LogzioSender:
break
except Exception as e:
print("Got exception while sending logs to Logz.io, Try ({}/{}). Message: {}".format(current_try + 1, number_of_retries, e.message))
print("Got exception while sending logs to Logz.io, Try ({}/{}). Message: {}".format(current_try + 1, number_of_retries, e))
should_retry = True
if should_retry:


+ 11
- 5
tests/mockLogzioListener/listener.py View File

@ -12,26 +12,32 @@ class ListenerHandler(BaseHTTPRequestHandler):
def do_POST(self):
try:
content_length = int(self.headers.get("Content-Length"))
all_logs = self.rfile.read(content_length).split('\n')
all_logs = self.rfile.read(content_length).decode("utf-8").split('\n')
if len(all_logs) == 0:
self.send_response(400, "Bad Request")
self._set_response(400, "Bad Request", b"Bad request you got there, pal")
return
for log in all_logs:
if log != "":
if persistent_flags.get_server_error():
self.send_response(500, "Issue!!!!!!!")
self._set_response(500, "Issue!!!!!!!", b"Not good, not good at all.")
return
logs_list.list.append(log)
self.send_response(200, "Ok")
self._set_response(200, "OK", b"Shabam! got logs.")
return
except IndexError:
self.send_response(400, "Bad Request")
self._set_response(400, "Bad Request", b"Bad request you got there, pal")
return
def _set_response(self, http_code, http_description, byte_body):
self.send_response(http_code, http_description)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(byte_body)
class MockLogzioListener:
def __init__(self):


Loading…
Cancel
Save