# -*- coding: utf-8 -*-
# $Id$
"""
Common Web Utility Functions.
"""
__copyright__ = \
"""
Copyright (C) 2012-2014 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
# Standard Python imports.
import os;
import shutil;
import sys;
import unittest;
# Validation Kit imports.
# Python 3 hacks:
else:
"""
Escapes special character to HTML-safe sequences.
"""
"""
Escapes special character to HTML-safe sequences.
"""
"""
Stringifies the object and hands it to escapeElem.
"""
return escapeElem(oObject);
"""
Stringifies the object and hands it to escapeAttr. May return unicode string.
"""
return escapeAttr(oObject);
""" Escapes a javascript string that is to be emitted between double quotes. """
if '"' not in sText:
return sText;
sRet = '';
if ch == '"':
sRet += '\\"';
elif ch == '\n':
sRet += '\\n';
elif ch == '\r':
sRet += '\\r';
elif ch == '\t':
sRet += '\\t';
else:
return sRet;
"""
See urllib.quote().
"""
return urllib_quote(sText);
"""
See urllib.urlencode().
"""
"""
Returns True if schema is present, False if not.
"""
if iColon > 0:
return True;
return False;
"""
Extracts the filename from the URL.
"""
## @TODO This isn't entirely correct. Use the urlparser instead!
return sFilename;
"""
Downloads the given file if an URL is given, otherwise assume it's
something on the build share and copy it from there.
Raises no exceptions, returns log + success indicator instead.
Note! This method may use proxies configured on the system and the
http_proxy, ftp_proxy, no_proxy environment variables.
@todo Fixed build burn here. Please set default value for fNoProxies
to appropriate one.
"""
if fnError is None:
# Download the file.
try:
## @todo We get 404.html content instead of exceptions here, which is confusing and should be addressed.
if fNoProxies:
else:
return False;
else:
# Assumes file from the build share.
try:
return False;
return True;
#
# Unit testing.
#
# pylint: disable=C0111
if __name__ == '__main__':
# not reached.