Skip to content
Snippets Groups Projects
Commit a8e2b7eb authored by sveseli's avatar sveseli
Browse files

generic url parsing functions

parent b292cf0b
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,38 @@ class FtpUtility:
dirPath = parseResult.path
return (scheme, host, port, dirPath)
@classmethod
def parseUrl(cls, url, defaultHost=None, defaultPort=None):
host = defaultHost
port = defaultPort
parseResult = urlparse.urlparse(url)
scheme = parseResult.scheme
netlocTokens = parseResult.netloc
if netlocTokens:
netlocTokens = netlocTokens.split(':')
host = netlocTokens[0]
if len(netlocTokens) > 1:
port = int(netlocTokens[1])
dirPath = parseResult.path
dirPath = os.path.normpath(dirPath)
return (scheme, host, port, dirPath)
@classmethod
def assembleUrl(cls, scheme, host, port, dirPath):
url = ''
if scheme:
url += '%s://' % scheme
if host:
url += '%s' % (host)
if port:
url += ':%s' % (port)
if dirPath:
if len(url) and not dirPath.startswith('/'):
url += '/%s' % (os.path.normpath(dirPath))
else:
url += '%s' % (os.path.normpath(dirPath))
return url
@classmethod
def getFtpClient(cls, host, port, username=None, password=None):
ftp = FTP()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment