summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2017-05-13 16:49:21 +0200
committerSimeon Simeonov2017-05-13 16:49:21 +0200
commit28592b4cbfda15f8594b2765d031c777d31cf767 (patch)
tree4e69269dd9882d4a2862fae17e3f44aac34aa8f8
parentdf917f55d6fbbe899942c5c4947444702b0b3fcd (diff)
Make beinc_server.py beinc_poller.py beinc_weechat.py both Python2 and Python>=3.4 compatible
-rwxr-xr-xbeinc_poller.py18
-rwxr-xr-xbeinc_server.py20
-rw-r--r--beinc_weechat.py10
3 files changed, 37 insertions, 11 deletions
diff --git a/beinc_poller.py b/beinc_poller.py
index e84ad71..b4e798f 100755
--- a/beinc_poller.py
+++ b/beinc_poller.py
@@ -1,4 +1,4 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python
2# -*- coding: utf-8 -*- 2# -*- coding: utf-8 -*-
3 3
4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v3.0 4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v3.0
@@ -29,11 +29,21 @@ import ssl
29import sys 29import sys
30import time 30import time
31 31
32from urllib.parse import urlencode 32PY2 = sys.version_info[0] == 2
33from urllib.request import urlopen 33PY3 = sys.version_info[0] == 3
34
35if PY3:
36 from urllib.parse import urlencode
37 from urllib.request import urlopen
38else:
39 from urllib import urlencode
40 from urllib2 import urlopen
34 41
35try: 42try:
36 import notify2 as pynotify 43 if PY3:
44 import notify2 as pynotify
45 else:
46 import pynotify
37except ImportError as e: 47except ImportError as e:
38 pynotify = None 48 pynotify = None
39 49
diff --git a/beinc_server.py b/beinc_server.py
index 113856f..3d9ff35 100755
--- a/beinc_server.py
+++ b/beinc_server.py
@@ -1,4 +1,4 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python
2# -*- coding: utf-8 -*- 2# -*- coding: utf-8 -*-
3 3
4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v3.0 4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v3.0
@@ -22,7 +22,6 @@ import argparse
22import cgi 22import cgi
23import errno 23import errno
24import getpass 24import getpass
25import http.server
26import json 25import json
27import logging 26import logging
28import os 27import os
@@ -32,8 +31,19 @@ import sys
32from functools import wraps 31from functools import wraps
33from logging.config import fileConfig 32from logging.config import fileConfig
34 33
34PY2 = sys.version_info[0] == 2
35PY3 = sys.version_info[0] == 3
36
37if PY3:
38 from http.server import BaseHTTPRequestHandler, HTTPServer
39else:
40 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
41
35try: 42try:
36 import notify2 as pynotify 43 if PY3:
44 import notify2 as pynotify
45 else:
46 import pynotify
37except ImportError as e: 47except ImportError as e:
38 pynotify = None 48 pynotify = None
39 49
@@ -182,7 +192,7 @@ class BEINCInstance(object):
182 self.__message_queue.append({'title': title, 'message': message}) 192 self.__message_queue.append({'title': title, 'message': message})
183 193
184 194
185class BEINCCustomHandler(http.server.BaseHTTPRequestHandler): 195class BEINCCustomHandler(BaseHTTPRequestHandler):
186 """ 196 """
187 """ 197 """
188 def do_POST(self): 198 def do_POST(self):
@@ -288,7 +298,7 @@ class BEINCCustomHandler(http.server.BaseHTTPRequestHandler):
288 indent=4).encode('utf-8')) 298 indent=4).encode('utf-8'))
289 299
290 300
291class BEINCNotifyServer(http.server.HTTPServer): 301class BEINCNotifyServer(HTTPServer):
292 """ 302 """
293 """ 303 """
294 def set_config(self, config): 304 def set_config(self, config):
diff --git a/beinc_weechat.py b/beinc_weechat.py
index 23d4db8..982e8f0 100644
--- a/beinc_weechat.py
+++ b/beinc_weechat.py
@@ -24,9 +24,15 @@ import socket
24import ssl 24import ssl
25import sys 25import sys
26 26
27from urllib import urlencode 27PY2 = sys.version_info[0] == 2
28from urllib2 import urlopen 28PY3 = sys.version_info[0] == 3
29 29
30if PY3:
31 from urllib.parse import urlencode
32 from urllib.request import urlopen
33else:
34 from urllib import urlencode
35 from urllib2 import urlopen
30 36
31import weechat 37import weechat
32 38