diff --git a/metadig/checks.py b/metadig/checks.py index b34094b..512a56c 100644 --- a/metadig/checks.py +++ b/metadig/checks.py @@ -10,7 +10,19 @@ def getType(object): def isResolvable(url): # First parse the url for a protocol, host port and path - + """Function that checks if a url is resolvable + + The function first checks if the url uses HTTP protocols, which is + currently the only protocol supported. + + Args: + url - the url to check for resolvability + + Returns: + list: the first element is either True or False (i.e. is/is not resolvable) + the second element is a status message, describing success or an error message. + + """ #url = 'https://cn.dataone.org/cn/v2/resolve/urn:uuid:7098ba54-ca6f-4e35-beb3-718bd0fe58a8' urlComps = urlparse(url) location = urlComps.netloc @@ -55,44 +67,6 @@ def isResolvable(url): else: return (False, "Successfully resolved the URL {}".format(url)) - -def getSystemMetadata(identifier, memberNode): - # Get the DataONE system metadata for the given identifier - - url = 'https://cn.dataone.org/cn/v2/meta/{}'.format(identifier) - - request = urllib2.Request(url) - request.get_method = lambda : 'HEAD' - # Python urllib2 strangly throws an error for a http status, and the response object is returned - # by the exception code. - try: - response = urllib2.urlopen(request) - except urllib2.HTTPError as he: - # An error was encountered resolving the url, check which one so that we can print - # a more meaningful error message than provided by HTTPError - # FYI, HTTP status codes (from FAIR FM_A1.1 https://github.com/FAIRMetrics/Metrics/blob/master/Distributions/FM_A1.1.pdf) - if (he.code == 400): - return (False, "Unable to resolved URL {}: Bad request".format(url)) - elif (he.code == 401): - return (False, "Unable to resolved URL {}: Unauthorized".format(url)) - elif (he.code == 404): - return (False, "Unable to resolved URL {}: Not Found".format(url)) - elif (he.code == 500): - return (False, "Unable to resolved URL {}: Server Error".format(url)) - else: - return (False, 'Error resolving URL "{}": {} {}'.format(url, he.code, he.headers)) - except urllib2.URLError as ue: - print("URLError.reason", ue.reason) - return (False, ue.reason[1]) - except Exception() as e: - print("Exception: ", e) - return (False, str(e)) - - if(response.code in set([200, 202, 203, 206, 301, 302, 303])): - return (True, "Successfully resolved the URL {}: status {}".format(url, response.code)) - else: - return (False, "Successfully resolved the URL {}".format(url)) - # Check if an identifier has a valid, known namespace #def isNamespaceValid(identifier): # delimiter = ':'