mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-22 02:16:42 +00:00
Yank direct support for URLPath from common.py
This commit is contained in:
parent
72e60f8301
commit
b68c08cff9
@ -37,9 +37,6 @@ from twisted.web.util import (
|
|||||||
from twisted.python.reflect import (
|
from twisted.python.reflect import (
|
||||||
fullyQualifiedName,
|
fullyQualifiedName,
|
||||||
)
|
)
|
||||||
from twisted.python.urlpath import (
|
|
||||||
URLPath,
|
|
||||||
)
|
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.python.failure import (
|
from twisted.python.failure import (
|
||||||
Failure,
|
Failure,
|
||||||
@ -583,15 +580,6 @@ def _finish(result, render, request):
|
|||||||
)
|
)
|
||||||
request.write(result)
|
request.write(result)
|
||||||
request.finish()
|
request.finish()
|
||||||
elif isinstance(result, URLPath):
|
|
||||||
Message.log(
|
|
||||||
message_type=u"allmydata:web:common-render:URLPath",
|
|
||||||
)
|
|
||||||
if result.netloc == b"":
|
|
||||||
root = URLPath.fromRequest(request)
|
|
||||||
result.scheme = root.scheme
|
|
||||||
result.netloc = root.netloc
|
|
||||||
_finish(redirectTo(str(result), request), render, request)
|
|
||||||
elif isinstance(result, DecodedURL):
|
elif isinstance(result, DecodedURL):
|
||||||
Message.log(
|
Message.log(
|
||||||
message_type=u"allmydata:web:common-render:DecodedURL",
|
message_type=u"allmydata:web:common-render:DecodedURL",
|
||||||
@ -684,3 +672,34 @@ def handle_when_done(req, d):
|
|||||||
if when_done:
|
if when_done:
|
||||||
d.addCallback(lambda res: DecodedURL.from_text(when_done.decode("utf-8")))
|
d.addCallback(lambda res: DecodedURL.from_text(when_done.decode("utf-8")))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
def url_for_string(req, url_string):
|
||||||
|
"""
|
||||||
|
Construct a universal URL using the given URL string.
|
||||||
|
|
||||||
|
:param IRequest req: The request being served. If ``redir_to`` is not
|
||||||
|
absolute then this is used to determine the net location of this
|
||||||
|
server and the resulting URL is made to point at it.
|
||||||
|
|
||||||
|
:param bytes url_string: A byte string giving a universal or absolute URL.
|
||||||
|
|
||||||
|
:return DecodedURL: An absolute URL based on this server's net location
|
||||||
|
and the given URL string.
|
||||||
|
"""
|
||||||
|
url = DecodedURL.from_text(url_string.decode("utf-8"))
|
||||||
|
if url.host == b"":
|
||||||
|
root = req.URLPath()
|
||||||
|
netloc = root.netloc.split(b":", 1)
|
||||||
|
if len(netloc) == 1:
|
||||||
|
host = netloc
|
||||||
|
port = None
|
||||||
|
else:
|
||||||
|
host = netloc[0]
|
||||||
|
port = int(netloc[1])
|
||||||
|
url = url.replace(
|
||||||
|
scheme=root.scheme.decode("ascii"),
|
||||||
|
host=host.decode("ascii"),
|
||||||
|
port=port,
|
||||||
|
)
|
||||||
|
return url
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
|
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
from twisted.web import http
|
from twisted.web import http
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.python.urlpath import (
|
|
||||||
URLPath,
|
|
||||||
)
|
|
||||||
from twisted.python.filepath import FilePath
|
from twisted.python.filepath import FilePath
|
||||||
from twisted.web.resource import Resource
|
from twisted.web.resource import Resource
|
||||||
from twisted.web.template import (
|
from twisted.web.template import (
|
||||||
@ -23,6 +21,7 @@ from allmydata.web.common import (
|
|||||||
get_format,
|
get_format,
|
||||||
get_mutable_type,
|
get_mutable_type,
|
||||||
render_exception,
|
render_exception,
|
||||||
|
url_for_string,
|
||||||
)
|
)
|
||||||
from allmydata.web import status
|
from allmydata.web import status
|
||||||
|
|
||||||
@ -68,7 +67,7 @@ def POSTUnlinkedCHK(req, client):
|
|||||||
def _done(upload_results, redir_to):
|
def _done(upload_results, redir_to):
|
||||||
if "%(uri)s" in redir_to:
|
if "%(uri)s" in redir_to:
|
||||||
redir_to = redir_to.replace("%(uri)s", urllib.quote(upload_results.get_uri()))
|
redir_to = redir_to.replace("%(uri)s", urllib.quote(upload_results.get_uri()))
|
||||||
return URLPath.fromString(redir_to)
|
return url_for_string(req, redir_to)
|
||||||
d.addCallback(_done, when_done)
|
d.addCallback(_done, when_done)
|
||||||
else:
|
else:
|
||||||
# return the Upload Results page, which includes the URI
|
# return the Upload Results page, which includes the URI
|
||||||
|
Loading…
x
Reference in New Issue
Block a user