Esempio n. 1
0
 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
Esempio n. 2
0
 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)
Esempio n. 3
0
 def test_unkown_mime(self):
     assert guess_format('unknown/mime') is None
Esempio n. 4
0
 def test_unkown_extension(self):
     assert guess_format('resource.unknonn') is None
Esempio n. 5
0
 def test_guess_from_mime_type(self, mime, expected):
     assert guess_format(mime) == expected
Esempio n. 6
0
 def test_guess_from_extension(self, suffix, expected):
     assert guess_format('resource.{0}'.format(suffix)) == expected
Esempio n. 7
0
 def test_unkown_mime(self):
     assert guess_format('unknown/mime') is None
Esempio n. 8
0
 def test_unkown_extension(self):
     assert guess_format('resource.unknonn') is None
Esempio n. 9
0
 def test_guess_from_mime_type(self, mime, expected):
     assert guess_format(mime) == expected
Esempio n. 10
0
 def test_guess_from_extension(self, suffix, expected):
     assert guess_format('resource.{0}'.format(suffix)) == expected
Esempio n. 11
0
 def initialize(self):
     '''List all datasets for a given ...'''
     fmt = guess_format(self.source.url)
     self.parse_graph(self.source.url, fmt)