Skip to content

Commit

Permalink
remove python2 code
Browse files Browse the repository at this point in the history
  • Loading branch information
mnot committed Oct 13, 2016
1 parent 27a2f3d commit c72cea2
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 62 deletions.
10 changes: 2 additions & 8 deletions bin/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import locale
import os
import sys
try:
from urllib.parse import urlsplit
except ImportError: # python2
from urlparse import urlsplit
from urllib.parse import urlsplit

from redbot import __version__
from redbot.resource.robot_fetch import RobotFetcher
Expand Down Expand Up @@ -151,10 +148,7 @@ def cgi_main():
"""Run REDbot as a CGI Script."""
def out(inbytes):
try:
if hasattr(sys.stdout, 'buffer'):
sys.stdout.buffer.write(inbytes)
else: # python2
sys.stdout.write(inbytes)
sys.stdout.buffer.write(inbytes)
sys.stdout.flush()
except IOError:
pass
Expand Down
6 changes: 2 additions & 4 deletions redbot/formatter/har.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@


import datetime
try:
import json
except ImportError: # python2
import simplejson as json
import json


from thor.http import get_header
from redbot import __version__
Expand Down
6 changes: 1 addition & 5 deletions redbot/formatter/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
import os
import re
import textwrap
try:
from urllib.parse import urljoin, quote as urlquote
except ImportError: # python2
from urlparse import urljoin
from urllib import quote as urlquote
from urllib.parse import urljoin, quote as urlquote

from markdown import markdown

Expand Down
6 changes: 1 addition & 5 deletions redbot/formatter/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
HAR Formatter for REDbot.
"""


try:
from html.parser import HTMLParser
except ImportError: # python2
from HTMLParser import HTMLParser
from html.parser import HTMLParser
import operator
import re
import textwrap
Expand Down
6 changes: 1 addition & 5 deletions redbot/message/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
import hashlib
import re
import time
try:
from urllib.parse import urlsplit, urlunsplit, quote as urlquote
except ImportError: # python2
from urlparse import urlsplit, urlunsplit
from urllib import quote as urlquote
from urllib.parse import urlsplit, urlunsplit, quote as urlquote
import zlib

from redbot.message.headers import HeaderProcessor
Expand Down
7 changes: 1 addition & 6 deletions redbot/message/headers/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
import calendar
from email.utils import parsedate as lib_parsedate
import re
try:
from urllib.parse import unquote as urlunquote
except ImportError: # python2
from urllib import unquote as unquote_to_bytes
def urlunquote(instr):
return unquote_to_bytes(instr.encode('ascii', 'replace')).decode('utf-8', 'replace')
from urllib.parse import unquote as urlunquote

from redbot.syntax import rfc7231
from ._notes import *
Expand Down
5 changes: 1 addition & 4 deletions redbot/message/headers/location.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/usr/bin/env python

import re
try:
from urllib.parse import urljoin
except ImportError: # python2
from urlparse import urljoin
from urllib.parse import urljoin

from redbot.message import headers
from redbot.speak import Note, categories, levels
Expand Down
5 changes: 1 addition & 4 deletions redbot/message/headers/set_cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

from calendar import timegm
from re import match, split
try:
from urllib.parse import urlsplit
except ImportError: # python2
from urlparse import urlsplit
from urllib.parse import urlsplit

from redbot.message import headers
from redbot.speak import Note, categories, levels
Expand Down
8 changes: 2 additions & 6 deletions redbot/message/link_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
Parse links from a stream of HTML data.
"""

try:
from html.entities import entitydefs
from html.parser import HTMLParser
except ImportError: # python2
from htmlentitydefs import entitydefs
from HTMLParser import HTMLParser
from html.entities import entitydefs
from html.parser import HTMLParser

from redbot.message import headers
from redbot.syntax import rfc7231
Expand Down
5 changes: 1 addition & 4 deletions redbot/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
See webui.py for the Web front-end.
"""

try:
from urllib.parse import urljoin
except ImportError: # python2
from urlparse import urljoin
from urllib.parse import urljoin

import thor

Expand Down
8 changes: 2 additions & 6 deletions redbot/resource/robot_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@

import hashlib
from os import path
try:
from urllib.robotparser import RobotFileParser
from urllib.parse import urlsplit
except ImportError: # python2
from robotparser import RobotFileParser
from urlparse import urlsplit
from urllib.robotparser import RobotFileParser
from urllib.parse import urlsplit

import thor

Expand Down
6 changes: 1 addition & 5 deletions redbot/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
import sys
import tempfile
import time
try:
from urllib.parse import parse_qs, urlsplit
except ImportError: # python2
from cgi import parse_qs
from urlparse import urlsplit
from urllib.parse import parse_qs, urlsplit
import zlib

import thor
Expand Down

0 comments on commit c72cea2

Please sign in to comment.