コード例 #1
0
ファイル: core.py プロジェクト: abigailStev/astroquery
    def _submit_form(self, input=None):
        """Fill out the form of the SkyView site and submit it with the
        values given in `input` (a dictionary where the keys are the form
        element's names and the values are their respective values).

        """
        if input is None:
            input = {}
        response = self._request("GET", url=self.FORM_URL, data={},
                                 timeout=self.TIMEOUT)
        bs = BeautifulSoup(response.text)
        form = bs.find('form')
        # cache the default values to save HTTP traffic
        if self._default_form_values is None:
            self._default_form_values = self._get_default_form_values(form)
        # only overwrite payload's values if the `input` value is not None
        # to avoid overwriting of the form's default values
        payload = self._default_form_values.copy()
        for k, v in six.iteritems(input):
            if v is not None:
                payload[k] = v
        url = urlparse.urljoin(self.FORM_URL, form.get('action'))
        response = self._request("POST", url=url, data=payload,
                                 timeout=self.TIMEOUT)
        return response
コード例 #2
0
ファイル: core.py プロジェクト: james-allen/astroquery
 def _parse_response(self, response):
     bs = BeautifulSoup(response.content)
     urls = []
     for a in bs.find_all('a'):
         if a.text == 'FITS':
             href = a.get('href')
             urls.append(urlparse.urljoin(response.url, href))
     return urls
コード例 #3
0
ファイル: core.py プロジェクト: martindurant/astroquery
 def _parse_response(self, response):
     bs = BeautifulSoup(response.content, "html.parser")
     urls = []
     for a in bs.find_all("a"):
         if a.text == "FITS":
             href = a.get("href")
             urls.append(urlparse.urljoin(response.url, href))
     return urls
コード例 #4
0
ファイル: test_generic_io.py プロジェクト: aarchiba/pyasdf
 def get_read_fd():
     f = generic_io.get_file(path, mode='r')
     assert isinstance(f, generic_io.RealFile)
     assert f._uri == urljoin('file:', pathname2url(path))
     # This is to check for a "feature" in Python 3.x that reading zero
     # bytes from a socket causes it to stop.  We have code in generic_io.py
     # to workaround it.
     f.read(0)
     return f
コード例 #5
0
ファイル: generic_io.py プロジェクト: nden/pyasdf
def resolve_uri(base, uri):
    """
    Resolve a URI against a base URI.
    """
    if base is None:
        if uri == '':
            return ''
        parsed = urlparse.urlparse(uri)
        if parsed.path.startswith('/'):
            return uri
        raise ValueError(
            "Can not resolve relative URLs since the base is unknown.")
    return urlparse.urljoin(base, uri)
コード例 #6
0
ファイル: core.py プロジェクト: weaverba137/astroquery
 def _generate_payload(self, input=None):
     """
     Fill out the form of the SkyView site and submit it with the
     values given in `input` (a dictionary where the keys are the form
     element's names and the values are their respective values).
     """
     if input is None:
         input = {}
     form_response = self._request('GET', self.URL)
     bs = BeautifulSoup(form_response.content, "html.parser")
     form = bs.find('form')
     # cache the default values to save HTTP traffic
     if self._default_form_values is None:
         self._default_form_values = self._get_default_form_values(form)
     # only overwrite payload's values if the `input` value is not None
     # to avoid overwriting of the form's default values
     payload = self._default_form_values.copy()
     for k, v in six.iteritems(input):
         if v is not None:
             payload[k] = v
     url = urlparse.urljoin(self.URL, form.get('action'))
     return url, payload
コード例 #7
0
 def get_write_fd():
     f = generic_io.get_file(open(path, 'wb'), mode='w')
     assert isinstance(f, generic_io.RealFile)
     assert f._uri == urljoin('file:', pathname2url(path))
     return f
コード例 #8
0
ファイル: test_generic_io.py プロジェクト: aarchiba/pyasdf
 def get_write_fd():
     f = generic_io.get_file(path, mode='w')
     assert isinstance(f, generic_io.RealFile)
     assert f._uri == urljoin('file:', pathname2url(path))
     return f
コード例 #9
0
ファイル: test_generic_io.py プロジェクト: aarchiba/pyasdf
 def get_read_fd():
     f = generic_io.get_file(io.open(path, 'r+b'), mode='rw')
     assert isinstance(f, generic_io.RealFile)
     assert f._uri == urljoin('file:', pathname2url(path))
     return f
コード例 #10
0
ファイル: test_asdftypes.py プロジェクト: aarchiba/pyasdf
 def url_mapping(self):
     return [('http://nowhere.org/schemas/custom/1.0.0/',
              urljoin('file:', pathname2url(os.path.join(
                  TEST_DATA_PATH))) + '/{url_suffix}.yaml')]
コード例 #11
0
 def url_mapping(self):
     return [
         ('http://nowhere.org/schemas/custom/1.0.0/',
          urljoin('file:', pathname2url(os.path.join(TEST_DATA_PATH))) +
          '/{url_suffix}.yaml')
     ]
コード例 #12
0
ファイル: resolver.py プロジェクト: aarchiba/pyasdf
                        return None
                    return _map_func

                func = _make_map_func(mapping)
            else:
                raise ValueError("Invalid mapping '{0}'".format(mapping))

            normalized.append(func)

        return tuple(normalized)

    def __call__(self, input):
        for mapper in self._mapping:
            output = mapper(input)
            if output is not None:
                return output
        return input

    def __hash__(self):
        return hash(self._mapping)


DEFAULT_URL_MAPPING = [
    (constants.STSCI_SCHEMA_URI_BASE,
     urljoin('file:', pathname2url(os.path.join(
         SCHEMA_PATH, 'stsci.edu'))) + '/{url_suffix}.yaml')
]


default_url_mapping = Resolver(DEFAULT_URL_MAPPING, 'url')
コード例 #13
0
ファイル: resolver.py プロジェクト: astrofrog/pyasdf
                        return None

                    return _map_func

                func = _make_map_func(mapping)
            else:
                raise ValueError("Invalid mapping '{0}'".format(mapping))

            normalized.append(func)

        return tuple(normalized)

    def __call__(self, input):
        for mapper in self._mapping:
            output = mapper(input)
            if output is not None:
                return output
        return input

    def __hash__(self):
        return hash(self._mapping)


DEFAULT_URL_MAPPING = [
    (constants.STSCI_SCHEMA_URI_BASE,
     urljoin('file:', pathname2url(os.path.join(SCHEMA_PATH, 'stsci.edu'))) +
     '/{url_suffix}.yaml')
]

default_url_mapping = Resolver(DEFAULT_URL_MAPPING, 'url')