Skip to content

Commit e7c89f6

Browse files
authored
pre-commit: Add isort --profile=black (webpy#742)
* pre-commit: Add isort --profile=black * codespell: Add asend * Remove Python 2 code from web/webapi.py * Remove Python 2 code from web/db.py * Remove Python 2 code from web/httpserver.py
1 parent c70a167 commit e7c89f6

File tree

10 files changed

+32
-59
lines changed

10 files changed

+32
-59
lines changed

.github/workflows/lint_python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
- run: pip install black codespell flake8 isort pytest
4343
- run: black --check .
44-
- run: codespell . --ignore-words-list=eith,gae --skip=./.*
44+
- run: codespell . --ignore-words-list=asend,gae --skip=./.*
4545
- run: flake8 --count --ignore=E203,E265,E722,E731,W503 --max-line-length=477 --show-source --statistics
4646
- run: isort --profile black .
4747

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ repos:
55
rev: 22.10.0
66
hooks:
77
- id: black
8+
9+
- repo: https://github.com/pycqa/isort
10+
rev: 5.10.1
11+
hooks:
12+
- id: isort
13+
args: [--profile, black]
14+
815
- repo: https://gitlab.com/pycqa/flake8
916
rev: '3.9.2' # pick a git hash / tag to point to
1017
hooks:

tests/test_session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
2-
import time
2+
import shutil
33
import tempfile
44
import threading
5+
import time
56
import unittest
6-
import shutil
77

88
import web
99

web/application.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import sys
99
import traceback
1010
import wsgiref.handlers
11+
from importlib import reload
1112
from inspect import isclass
1213
from io import BytesIO
14+
from urllib.parse import unquote, urlencode, urlparse
1315

1416
from . import browser, httpserver, utils
1517
from . import webapi as web
@@ -18,11 +20,6 @@
1820
from .py3helpers import iteritems
1921
from .utils import lstrips
2022

21-
from urllib.parse import urlparse, urlencode, unquote
22-
23-
from importlib import reload
24-
25-
2623
__all__ = [
2724
"application",
2825
"auto_application",

web/browser.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
"""
44
import os
55
import webbrowser
6+
from http.cookiejar import CookieJar
67
from io import BytesIO
7-
8-
from .net import htmlunquote
9-
from .utils import re_compile
10-
11-
from urllib.request import HTTPHandler, HTTPCookieProcessor, Request, HTTPError
12-
from urllib.request import build_opener as urllib_build_opener
138
from urllib.parse import urljoin
14-
from http.cookiejar import CookieJar
9+
from urllib.request import HTTPCookieProcessor, HTTPError, HTTPHandler, Request
10+
from urllib.request import build_opener as urllib_build_opener
1511
from urllib.response import addinfourl
1612

13+
from .net import htmlunquote
14+
from .utils import re_compile
1715

1816
DEBUG = False
1917

web/db.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@
77
import os
88
import re
99
import time
10+
from urllib import parse as urlparse
11+
from urllib.parse import unquote
1012

1113
from .py3helpers import iteritems
1214
from .utils import iters, safestr, safeunicode, storage, threadeddict
1315

14-
try:
15-
from urllib import parse as urlparse
16-
from urllib.parse import unquote
17-
except ImportError:
18-
import urlparse
19-
from urllib import unquote
20-
2116
try:
2217
# db module can work independent of web.py
23-
from .webapi import debug, config
18+
from .webapi import config, debug
2419
except ImportError:
2520
import sys
2621

web/httpserver.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
import os
22
import posixpath
33
import sys
4+
from http.server import BaseHTTPRequestHandler, HTTPServer, SimpleHTTPRequestHandler
5+
from io import BytesIO
6+
from urllib import parse as urlparse
7+
from urllib.parse import unquote
48

59
from . import utils
610
from . import webapi as web
711

8-
try:
9-
from io import BytesIO
10-
except ImportError:
11-
from StringIO import BytesIO
12-
13-
try:
14-
from http.server import HTTPServer, SimpleHTTPRequestHandler, BaseHTTPRequestHandler
15-
except ImportError:
16-
from SimpleHTTPServer import SimpleHTTPRequestHandler
17-
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
18-
19-
try:
20-
from urllib import parse as urlparse
21-
from urllib.parse import unquote
22-
except ImportError:
23-
import urlparse
24-
from urllib import unquote
25-
2612
__all__ = ["runsimple"]
2713

2814

@@ -41,11 +27,12 @@ def runbasic(func, server_address=("0.0.0.0", 8080)):
4127
# Used under the modified BSD license:
4228
# http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
4329

44-
import SocketServer
45-
import socket
4630
import errno
31+
import socket
4732
import traceback
4833

34+
import SocketServer
35+
4936
class WSGIHandler(SimpleHTTPRequestHandler):
5037
def run_wsgi_app(self):
5138
protocol, host, path, parameters, query, fragment = urlparse.urlparse(

web/session.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
except ImportError:
2222
import pickle
2323

24-
25-
from base64 import encodebytes, decodebytes
26-
24+
from base64 import decodebytes, encodebytes
2725

2826
__all__ = ["Session", "SessionExpired", "Store", "DiskStore", "DBStore", "MemoryStore"]
2927

web/utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
import traceback
1616
from threading import local as threadlocal
1717

18-
from .py3helpers import (
19-
iteritems,
20-
itervalues,
21-
)
18+
from .py3helpers import iteritems, itervalues
2219

2320
try:
2421
from StringIO import StringIO
@@ -1172,8 +1169,8 @@ def __init__(self, func):
11721169

11731170
def __call__(self, *args): # , **kw): kw unused
11741171
import cProfile
1175-
import pstats
11761172
import os
1173+
import pstats
11771174
import tempfile
11781175

11791176
f, filename = tempfile.mkstemp()

web/webapi.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77
import pprint
88
import sys
99
import tempfile
10+
from http.cookies import CookieError, Morsel, SimpleCookie
1011
from io import BytesIO
11-
from urllib.parse import urljoin
12+
from urllib.parse import quote, unquote, urljoin
1213

1314
from .utils import dictadd, intget, safestr, storage, storify, threadeddict
1415

15-
try:
16-
from urllib.parse import unquote, quote
17-
from http.cookies import CookieError, Morsel, SimpleCookie
18-
except ImportError:
19-
from urllib import unquote, quote
20-
from Cookie import CookieError, Morsel, SimpleCookie
21-
2216
__all__ = [
2317
"config",
2418
"header",

0 commit comments

Comments
 (0)