def test_as_urls():
    assert_equals(utils.as_url("C:\\Users\\Administrator\\AppData\\Local\\Temp\\2\\tmpvixuld.txt"),
                  "file:///C:/Users/Administrator/AppData/Local/Temp/2/tmpvixuld.txt")
    assert_equals(utils.as_url("/foo/bar/bat/zoinks.txt"), "file:///foo/bar/bat/zoinks.txt")
    assert_equals(utils.as_url("http://foo/bar/bat/zoinks.txt"), "http://foo/bar/bat/zoinks.txt")
    assert_equals(utils.as_url("ftp://foo/bar/bat/zoinks.txt"), "ftp://foo/bar/bat/zoinks.txt")
    assert_equals(utils.as_url("sftp://foo/bar/bat/zoinks.txt"), "sftp://foo/bar/bat/zoinks.txt")
示例#2
0
def test_as_urls():
    assert utils.as_url(
        "C:\\Users\\Administrator\\AppData\\Local\\Temp\\2\\tmpvixuld.txt"
    ) == "file:///C:/Users/Administrator/AppData/Local/Temp/2/tmpvixuld.txt"
    assert utils.as_url(
        "/foo/bar/bat/zoinks.txt") == "file:///foo/bar/bat/zoinks.txt"
    assert utils.as_url(
        "http://foo/bar/bat/zoinks.txt") == "http://foo/bar/bat/zoinks.txt"
    assert utils.as_url(
        "ftp://foo/bar/bat/zoinks.txt") == "ftp://foo/bar/bat/zoinks.txt"
    assert utils.as_url(
        "sftp://foo/bar/bat/zoinks.txt") == "sftp://foo/bar/bat/zoinks.txt"
示例#3
0
    def __setitem__(self, key, value):
        if (key == '_file_handle'):
            self._update_file_handle(value)
        elif key in self.__class__._file_handle_aliases:
            self._file_handle[self.__class__._file_handle_aliases[key]] = value
        else:
            expand_and_convert_to_URL = lambda path: utils.as_url(
                os.path.expandvars(os.path.expanduser(path)))
            #hacky solution to allowing immediate switching into a ExternalFileHandle pointing to the current path
            if key == 'synapseStore' and value == False and self[
                    'synapseStore'] == True and utils.caller_module_name(
                        inspect.currentframe()
                    ) != 'client':  #yes, there is boolean zen but I feel like it is easier to read/understand this way
                self['externalURL'] = expand_and_convert_to_URL(self['path'])

            #hacky solution because we historically allowed modifying 'path' to indicate wanting to change to a new ExternalFileHandle
            if key == 'path' and not self[
                    'synapseStore'] and utils.caller_module_name(
                        inspect.currentframe()
                    ) != 'client':  #don't change exernalURL if it's just the synapseclient setting metadata after a function call such as syn.get()
                self['externalURL'] = expand_and_convert_to_URL(value)
                self['contentMd5'] = None
                self['contentSize'] = None
            super(File, self).__setitem__(key, value)