def get_format(self): fmt = guess_format(self.source.url) # if format can't be guessed from the url # we fallback on the declared Content-Type if not fmt: response = requests.head(self.source.url) mime_type = response.headers.get('Content-Type', '').split(';', 1)[0] if not mime_type: msg = 'Unable to detect format from extension or mime type' raise ValueError(msg) fmt = guess_format(mime_type) if not fmt: msg = 'Unsupported mime type "{0}"'.format(mime_type) raise ValueError(msg) return fmt
def initialize(self): '''List all datasets for a given ...''' fmt = guess_format(self.source.url) # if format can't be guessed from the url # we fallback on the declared Content-Type if not fmt: response = requests.head(self.source.url) mime_type = response.headers.get('Content-Type', '').split(';', 1)[0] if not mime_type: msg = 'Unable to detect format from extension or mime type' raise ValueError(msg) fmt = guess_format(mime_type) if not fmt: msg = 'Unsupported mime type "{0}"'.format(mime_type) raise ValueError(msg) self.parse_graph(self.source.url, fmt)
def test_unkown_mime(self): assert guess_format('unknown/mime') is None
def test_unkown_extension(self): assert guess_format('resource.unknonn') is None
def test_guess_from_mime_type(self, mime, expected): assert guess_format(mime) == expected
def test_guess_from_extension(self, suffix, expected): assert guess_format('resource.{0}'.format(suffix)) == expected
def initialize(self): '''List all datasets for a given ...''' fmt = guess_format(self.source.url) self.parse_graph(self.source.url, fmt)