source: DPPP/kml/csml2kml/python/csml2kml/csml2kml/utils.py @ 3684

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/DPPP/kml/csml2kml/python/csml2kml/csml2kml/utils.py@3684
Revision 3684, 767 bytes checked in by mkochan, 11 years ago (diff)

Changed wget to return urllib2.HTTPError on retrieval error; changed setup.py to include config files in the csml2kml distribution.

Line 
1'''
2Utility/convenience functions.
3'''
4
5import urllib2
6
7class UrlRetrievalError(Exception):
8    def __init__(self, value):
9        self.value = value
10    def __repr__(self):
11        return repr(self.value)
12
13def wget(url):
14    '''
15    Read data from an URL.
16    @param url: The URL.
17    @type url: C{str}
18    @return: The returned data as a string, or an C{urllib2.HTTPError} on retrieval error.
19    @rtype: C{str}
20    '''
21    content = None
22    try:
23        f = urllib2.urlopen(url)         # open a file-like object with the data
24        content = f.read()               # read the text in
25    finally:
26        try:
27            f.close()
28        except NameError:
29            pass                         # in case socket has not even been opened
30    return content
Note: See TracBrowser for help on using the repository browser.