Skip to content

Commit b595c93

Browse files
Require Python file handers to import helpers via root path (web-platform-tests#26328)
This changes handlers.py to no longer play with `sys.path` and `sys.modules`, and instead require python file handlers import helper functions with root-relative paths. `__init__.py` files are added as required. Changing this did require changing imports in multiple tests; this can be reverted once we get to Py3-only (and pep 420) and can remove the root `__init__.py`. Docs and tests are updated as appropriate. See web-platform-tests/rfcs#68
1 parent 2089a7c commit b595c93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+177
-69
lines changed

__init__.py

Whitespace-only changes.

common/__init__.py

Whitespace-only changes.

common/security-features/__init__.py

Whitespace-only changes.

common/security-features/scope/__init__.py

Whitespace-only changes.

common/security-features/scope/document.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from wptserve.utils import isomorphic_decode, isomorphic_encode
44

5-
sys.path.insert(0, os.path.dirname(os.path.abspath(isomorphic_decode(__file__))))
6-
import util
5+
import importlib
6+
util = importlib.import_module("common.security-features.scope.util")
77

88
def main(request, response):
99
policyDeliveries = json.loads(request.GET.first(b"policyDeliveries", b"[]"))

common/security-features/scope/worker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os, sys, json
22

33
from wptserve.utils import isomorphic_decode, isomorphic_encode
4-
sys.path.insert(0, os.path.dirname(os.path.abspath(isomorphic_decode(__file__))))
5-
import util
4+
import importlib
5+
util = importlib.import_module("common.security-features.scope.util")
66

77
def main(request, response):
88
policyDeliveries = json.loads(request.GET.first(b'policyDeliveries', b'[]'))

common/security-features/subresource/audio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os, sys
22
from wptserve.utils import isomorphic_decode
3-
sys.path.insert(0, os.path.dirname(os.path.abspath(isomorphic_decode(__file__))))
4-
import subresource
3+
import importlib
4+
subresource = importlib.import_module("common.security-features.subresource.subresource")
55

66
def generate_payload(request, server_data):
77
file = os.path.join(request.doc_root, u"webaudio", u"resources",

common/security-features/subresource/document.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os, sys
22
from wptserve.utils import isomorphic_decode
3-
sys.path.insert(0, os.path.dirname(os.path.abspath(isomorphic_decode(__file__))))
4-
import subresource
3+
import importlib
4+
subresource = importlib.import_module("common.security-features.subresource.subresource")
55

66
def generate_payload(server_data):
77
return subresource.get_template(u"document.html.template") % server_data

common/security-features/subresource/empty.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os, sys
22
from wptserve.utils import isomorphic_decode
3-
sys.path.insert(0, os.path.dirname(os.path.abspath(isomorphic_decode(__file__))))
4-
import subresource
3+
import importlib
4+
subresource = importlib.import_module("common.security-features.subresource.subresource")
55

66
def generate_payload(server_data):
77
return u''

common/security-features/subresource/font.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os, sys, base64
22
from wptserve.utils import isomorphic_decode
3-
sys.path.insert(0, os.path.dirname(os.path.abspath(isomorphic_decode(__file__))))
4-
import subresource
3+
import importlib
4+
subresource = importlib.import_module("common.security-features.subresource.subresource")
55

66
def generate_payload(request, server_data):
77
data = (u'{"headers": %(headers)s}') % server_data

0 commit comments

Comments
 (0)