/usr/share/pyshared/dap/client.py is in python-dap 2.2.6.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | __author__ = "Roberto De Almeida <rob@pydap.org>"
import dap.lib
from dap.util.http import openurl
from dap.exceptions import ClientError
def open(url, cache=None, username=None, password=None, verbose=False):
"""Connect to a remote dataset.
This function opens a dataset stored in a DAP server:
>>> dataset = open(url, cache=None, username=None, password=None, verbose=False):
You can specify a cache location (a directory), so that repeated
accesses to the same URL avoid the network.
The username and password may be necessary if the DAP server requires
authentication. The 'verbose' option will make pydap print all the
URLs that are acessed.
"""
# Set variables on module namespace.
dap.lib.VERBOSE = verbose
if url.startswith('http'):
for response in [_ddx, _ddsdas]:
dataset = response(url, cache, username, password)
if dataset: return dataset
else:
raise ClientError("Unable to open dataset.")
else:
from dap.plugins.lib import loadhandler
from dap.helper import walk
# Open a local file. This is a clever hack. :)
handler = loadhandler(url)
dataset = handler._parseconstraints()
# Unwrap any arrayterators in the dataset.
for var in walk(dataset):
try: var.data = var.data._var
except: pass
return dataset
def _ddsdas(baseurl, cache, username, password):
ddsurl, dasurl = '%s.dds' % baseurl, '%s.das' % baseurl
# Get metadata.
respdds, dds = openurl(ddsurl, cache, username, password)
respdas, das = openurl(dasurl, cache, username, password)
if respdds['status'] == '200' and respdas['status'] == '200':
from dap.parsers.dds import DDSParser
from dap.parsers.das import DASParser
# Build dataset.
dataset = DDSParser(dds, ddsurl, cache, username, password).parse()
# Add attributes.
dataset = DASParser(das, dasurl, dataset).parse()
return dataset
def _ddx(baseurl, cache, username, password):
pass
|