comparison libervia/server/server.py @ 1459:47db314e60ca

server: `getExtBaseURL` type hints
author Goffi <goffi@goffi.org>
date Wed, 29 Sep 2021 17:39:35 +0200
parents db13f5c768a0
children 0ea54090e414
comparison
equal deleted inserted replaced
1458:db13f5c768a0 1459:47db314e60ca
21 import sys 21 import sys
22 import urllib.parse 22 import urllib.parse
23 import urllib.request, urllib.error 23 import urllib.request, urllib.error
24 import time 24 import time
25 import copy 25 import copy
26 from typing import Optional
26 from pathlib import Path 27 from pathlib import Path
27 from twisted.application import service 28 from twisted.application import service
28 from twisted.internet import reactor, defer, inotify 29 from twisted.internet import reactor, defer, inotify
29 from twisted.web import server 30 from twisted.web import server
30 from twisted.web import static 31 from twisted.web import static
1692 ext_data.path or "/", 1693 ext_data.path or "/",
1693 "", 1694 "",
1694 "", 1695 "",
1695 ) 1696 )
1696 1697
1697 def getExtBaseURL(self, request, path="", query="", fragment="", scheme=None): 1698 def getExtBaseURL(
1699 self,
1700 request: server.Request,
1701 path: str = "",
1702 query: str = "",
1703 fragment: str = "",
1704 scheme: Optional[str] = None,
1705 ) -> str:
1698 """Get external URL according to given elements 1706 """Get external URL according to given elements
1699 1707
1700 external URL is the URL seen by external user 1708 external URL is the URL seen by external user
1701 @param path(unicode): same as for urlsplit.urlsplit 1709 @param path: same as for urlsplit.urlsplit
1702 path will be prefixed to follow found external URL if suitable 1710 path will be prefixed to follow found external URL if suitable
1703 @param params(unicode): same as for urlsplit.urlsplit 1711 @param params: same as for urlsplit.urlsplit
1704 @param query(unicode): same as for urlsplit.urlsplit 1712 @param query: same as for urlsplit.urlsplit
1705 @param fragment(unicode): same as for urlsplit.urlsplit 1713 @param fragment: same as for urlsplit.urlsplit
1706 @param scheme(unicode, None): if not None, will override scheme from base URL 1714 @param scheme: if not None, will override scheme from base URL
1707 @return (unicode): external URL 1715 @return: external URL
1708 """ 1716 """
1709 split_result = self.getExtBaseURLData(request) 1717 split_result = self.getExtBaseURLData(request)
1710 return urllib.parse.urlunsplit( 1718 return urllib.parse.urlunsplit(
1711 ( 1719 (
1712 split_result.scheme if scheme is None else scheme, 1720 split_result.scheme if scheme is None else scheme,