Skip to content

Commit

Permalink
Update source code docs
Browse files Browse the repository at this point in the history
gothub committed Mar 6, 2020
1 parent 867967a commit 447d8e6
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions metadig/checks.py
Original file line number Diff line number Diff line change
@@ -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 = ':'

0 comments on commit 447d8e6

Please sign in to comment.