<commit_before># -*- coding: utf-8 -*-

from __future__ import (absolute_import, division, print_function)



def _clean_response(response):
    """Allow for extension or .extension format.

    The user can, for example,
    use either `.csv` or `csv` in the response kwarg.

    """
    return response.lstrip('.')


class ERDDAP(object):
    """Returns a ERDDAP instance for the user defined server endpoint.

    Different from the R version there are no hard-coded servers!
    The user must pass the endpoint explicitly!!

    Examples:
        >>> e = ERDDAP(server_url='https://data.ioos.us/gliders/erddap')

    """
    def __init__(self, server_url):
        self.server_url = server_url
        # Caching the last request for quicker multiple access,
        # will be overridden when making a new requested.
        self._nc = None
        self._dataset_id = None
        self._variables = {}

    def search_url(self, response='csv', search_for=None, items_per_page=1000, page=1, **kwargs):
        """Compose the search URL for the `server_url` endpoint.

        Args:
            search_for (str): "Google-like" search
                - This is a Google-like search of the datasets' metadata:
                  Type the words you want to search for, with spaces between the words.
                  ERDDAP will search for the words separately, not as a phrase.
                - To search for a phrase, put double quotes around the phrase
                  (for example, `"wind speed"`).
                - To exclude datasets with a specific word, use `-excludedWord`.
                - To exclude datasets with a specific phrase, use `-"excluded phrase"`
                - Searches are not case-sensitive.
                - To find just grid or just table datasets, include `protocol=griddap`
                  or `protocol=tabledap` in your search.
                - You can search for any part of a word. For example,
                  searching for `spee` will find datasets with `speed` and datasets with
                `WindSpeed`
                - The last word in a phrase may be a partial word. For example,
                  to find datasets from a specific website (usually the start of the datasetID),
                  include (for example) `"datasetID=erd"` in your search.
            response (str): default is a Comma Separated Value ('csv').
                See ERDDAP docs for all the options,
                tabledap: http://coastwatch.pfeg.noaa.gov/erddap/tabledap/documentation.html
                griddap: http://coastwatch.pfeg.noaa.gov/erddap/griddap/documentation.html
            items_per_page (int): how many items per page in the return,
                default is 1000.
            page (int): which page to display, defatul is the first page (1).
        Returns:
            search_url (str): the search URL for the `response` chosen.
        """
        base = (
            '{server_url}/search/advanced.{response}'
            '?page={page}'
            '&itemsPerPage={itemsPerPage}'
            '&protocol={protocol}'
            '&cdm_data_type={cdm_data_type}'
            '&institution={institution}'
            '&ioos_category={ioos_category}'
            '&keywords={keywords}'
            '&long_name={long_name}'
            '&standard_name={standard_name}'
            '&variableName={variableName}'
            '&minLon={minLon}'
            '&maxLon={maxLon}'
            '&minLat={minLat}'
            '&maxLat={maxLat}'
            '&minTime={minTime}'
            '&maxTime={maxTime}'
            )
        if search_for:
            search_for = search_for.replace(' ', '+AND+')
            base += '&searchFor={searchFor}'

        default = '(ANY)'
        response = _clean_response(response)
        search_options = {
            'server_url': self.server_url,
            'response': response,
            'page': page,
            'itemsPerPage': items_per_page,
            'protocol': kwargs.get('protocol', default),
            'cdm_data_type': kwargs.get('cdm_data_type', default),
            'institution': kwargs.get('institution', default),
            'ioos_category': kwargs.get('ioos_category', default),
            'keywords': kwargs.get('keywords', default),
            'long_name': kwargs.get('long_name', default),<commit_msg>fix quoted searchFor<commit_after># -*- coding: utf-8 -*-

from __future__ import (absolute_import, division, print_function)

from urllib.parse import quote_plus


def _clean_response(response):
    """Allow for extension or .extension format.

    The user can, for example,
    use either `.csv` or `csv` in the response kwarg.

    """
    return response.lstrip('.')


class ERDDAP(object):
    """Returns a ERDDAP instance for the user defined server endpoint.

    Different from the R version there are no hard-coded servers!
    The user must pass the endpoint explicitly!!

    Examples:
        >>> e = ERDDAP(server_url='https://data.ioos.us/gliders/erddap')

    """
    def __init__(self, server_url):
        self.server_url = server_url
        # Caching the last request for quicker multiple access,
        # will be overridden when making a new requested.
        self._nc = None
        self._dataset_id = None
        self._variables = {}

    def search_url(self, response='csv', search_for=None, items_per_page=1000, page=1, **kwargs):
        """Compose the search URL for the `server_url` endpoint.

        Args:
            search_for (str): "Google-like" search
                - This is a Google-like search of the datasets' metadata:
                  Type the words you want to search for, with spaces between the words.
                  ERDDAP will search for the words separately, not as a phrase.
                - To search for a phrase, put double quotes around the phrase
                  (for example, `"wind speed"`).
                - To exclude datasets with a specific word, use `-excludedWord`.
                - To exclude datasets with a specific phrase, use `-"excluded phrase"`
                - Searches are not case-sensitive.
                - To find just grid or just table datasets, include `protocol=griddap`
                  or `protocol=tabledap` in your search.
                - You can search for any part of a word. For example,
                  searching for `spee` will find datasets with `speed` and datasets with
                  `WindSpeed`
                - The last word in a phrase may be a partial word. For example,
                  to find datasets from a specific website (usually the start of the datasetID),
                  include (for example) `"datasetID=erd"` in your search.
            response (str): default is a Comma Separated Value ('csv').
                See ERDDAP docs for all the options,
                tabledap: http://coastwatch.pfeg.noaa.gov/erddap/tabledap/documentation.html
                griddap: http://coastwatch.pfeg.noaa.gov/erddap/griddap/documentation.html
            items_per_page (int): how many items per page in the return,
                default is 1000.
            page (int): which page to display, defatul is the first page (1).
        Returns:
            search_url (str): the search URL for the `response` chosen.
        """
        base = (
            '{server_url}/search/advanced.{response}'
            '?page={page}'
            '&itemsPerPage={itemsPerPage}'
            '&protocol={protocol}'
            '&cdm_data_type={cdm_data_type}'
            '&institution={institution}'
            '&ioos_category={ioos_category}'
            '&keywords={keywords}'
            '&long_name={long_name}'
            '&standard_name={standard_name}'
            '&variableName={variableName}'
            '&minLon={minLon}'
            '&maxLon={maxLon}'
            '&minLat={minLat}'
            '&maxLat={maxLat}'
            '&minTime={minTime}'
            '&maxTime={maxTime}'
            )
        if search_for:
            search_for = quote_plus(search_for)
            base += '&searchFor={searchFor}'

        default = '(ANY)'
        response = _clean_response(response)
        search_options = {
            'server_url': self.server_url,
            'response': response,
            'page': page,
            'itemsPerPage': items_per_page,
            'protocol': kwargs.get('protocol', default),
            'cdm_data_type': kwargs.get('cdm_data_type', default),
            'institution': kwargs.get('institution', default),
            'ioos_category': kwargs.get('ioos_category', default),
            'keywords': kwargs.get('keywords', default),
            'long_name': kwargs.get('long_name', default),
{'fraction_non_alphanumeric': 0.10355949775371501, 'fraction_numerical': 0.0025342702453634374, 'mean_word_length': 2.051669595782074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '721540', 'n_tokens_mistral': 2393, 'n_tokens_neox': 2306, 'n_words': 732}