Skip to content

Commit

Permalink
Merge pull request tahoe-lafs#985 from tahoe-lafs/3615.web-python-3-p…
Browse files Browse the repository at this point in the history
…art-3

Port allmydata.web to Python 3, part 3.

Fixes ticket:3615
Fixes ticket:3598
  • Loading branch information
itamarst committed Feb 23, 2021
2 parents 16a4739 + 38da89a commit 9b4486a
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
- "master"
pull_request:

env:
# Tell Hypothesis which configuration we want it to use.
TAHOE_LAFS_HYPOTHESIS_PROFILE: "ci"

jobs:

coverage:
Expand Down
Empty file added newsfragments/3615.minor
Empty file.
4 changes: 4 additions & 0 deletions src/allmydata/util/_python3.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
"allmydata.util.statistics",
"allmydata.util.time_format",
"allmydata.web.common",
"allmydata.web.check_results",
"allmydata.web.filenode",
"allmydata.web.info",
"allmydata.web.introweb",
"allmydata.web.logs",
"allmydata.webish",
]
Expand Down
12 changes: 11 additions & 1 deletion src/allmydata/web/check_results.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
from future.builtins import str
"""
Ported to Python 3.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from future.utils import PY2
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401

import time

Expand Down
30 changes: 22 additions & 8 deletions src/allmydata/web/filenode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
from past.builtins import unicode, long
"""
Ported to Python 3.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from future.utils import PY2
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, max, min # noqa: F401
# Use native unicode() as str() to prevent leaking futurebytes in ways that
# break string formattin.
from past.builtins import unicode as str
from past.builtins import long

from twisted.web import http, static
from twisted.internet import defer
Expand Down Expand Up @@ -130,7 +144,7 @@ def render_PUT(self, req):
if t == b"uri":
return self.replace_me_with_a_childcap(req, self.client, replace)

raise WebError("PUT to a file: bad t=%s" % unicode(t, "utf-8"))
raise WebError("PUT to a file: bad t=%s" % str(t, "utf-8"))

@render_exception
def render_POST(self, req):
Expand All @@ -147,7 +161,7 @@ def render_POST(self, req):
# t=mkdir is handled in DirectoryNodeHandler._POST_mkdir, so
# there are no other t= values left to be handled by the
# placeholder.
raise WebError("POST to a file: bad t=%s" % unicode(t, "utf-8"))
raise WebError("POST to a file: bad t=%s" % str(t, "utf-8"))

return handle_when_done(req, d)

Expand Down Expand Up @@ -180,7 +194,7 @@ def getChild(self, name, req):

@render_exception
def render_GET(self, req):
t = unicode(get_arg(req, b"t", b"").strip(), "ascii")
t = str(get_arg(req, b"t", b"").strip(), "ascii")

# t=info contains variable ophandles, so is not allowed an ETag.
FIXED_OUTPUT_TYPES = ["", "json", "uri", "readonly-uri"]
Expand Down Expand Up @@ -287,7 +301,7 @@ def render_PUT(self, req):
assert self.parentnode and self.name
return self.replace_me_with_a_childcap(req, self.client, replace)

raise WebError("PUT to a file: bad t=%s" % unicode(t, "utf-8"))
raise WebError("PUT to a file: bad t=%s" % str(t, "utf-8"))

@render_exception
def render_POST(self, req):
Expand All @@ -309,7 +323,7 @@ def render_POST(self, req):
assert self.parentnode and self.name
d = self.replace_me_with_a_formpost(req, self.client, replace)
else:
raise WebError("POST to file: bad t=%s" % unicode(t, "ascii"))
raise WebError("POST to file: bad t=%s" % str(t, "ascii"))

return handle_when_done(req, d)

Expand Down Expand Up @@ -374,7 +388,7 @@ def __init__(self, filenode, filename):
self.filenode = filenode
self.filename = filename

def parse_range_header(self, range):
def parse_range_header(self, range_header):
# Parse a byte ranges according to RFC 2616 "14.35.1 Byte
# Ranges". Returns None if the range doesn't make sense so it
# can be ignored (per the spec). When successful, returns a
Expand All @@ -385,7 +399,7 @@ def parse_range_header(self, range):

try:
# byte-ranges-specifier
units, rangeset = range.split('=', 1)
units, rangeset = range_header.split('=', 1)
if units != 'bytes':
return None # nothing else supported

Expand Down
14 changes: 12 additions & 2 deletions src/allmydata/web/info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
from past.builtins import unicode
"""
Ported to Python 3.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from future.utils import PY2
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401

import os
from urllib.parse import quote as urlquote
Expand Down Expand Up @@ -47,7 +57,7 @@ def __init__(self, node):

def abbrev(self, storage_index_or_none):
if storage_index_or_none:
return unicode(base32.b2a(storage_index_or_none)[:6], "ascii")
return str(base32.b2a(storage_index_or_none)[:6], "ascii")
return "LIT file"

def get_type(self):
Expand Down
11 changes: 11 additions & 0 deletions src/allmydata/web/introweb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""
Ported to Python 3.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from future.utils import PY2
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401

import time, os
from pkg_resources import resource_filename
Expand Down

0 comments on commit 9b4486a

Please sign in to comment.