Esempio n. 1
0
    def size(self, name):

        logger.debug(u'getting {0} size'.format(name))

        for location in self._locations:
            logger.debug(u'getting via {0}'.format(location))
            try:
                response = requests.head(
                    self._get_full_path(location, name), timeout=self._timeout)
            except Exception as err:
                logger.exception(err)
            else:
                return response.headers.get('Content-Length')

        logger.error(u'file size not found')

        return None
Esempio n. 2
0
    def exists(self, name):

        logger.debug(u'checking existing of {0}'.format(name))

        file_found = False

        # check all dav instances for file existence,
        # if file exist in one of them then we think that file exists
        for location in self._locations:
            logger.debug(u'checking via location {0}'.format(location))
            response = requests.head(
                self._get_full_path(location, name), timeout=self._timeout)
            if response.status_code == 200:
                file_found = True
                logger.debug(u'file found')
                break

        if not file_found:
            logger.debug(u'file does not exist')

        return file_found
Esempio n. 3
0
 def test_HTTP_HEAD(self):
     r = requests.head(build_url("head"))
     self.assertEquals(r.status_code, 200)
Esempio n. 4
0
def head(uri, token=None):
    headers = {"X-Auth-Token": token, "content-type": "application/json"}
    return requests.head(uri, headers=headers)