<commit_before>from constants import MAX_LIMIT
from version import __version__, version_info

import requests
from cStringIO import StringIO
import csv
import json

__author__ = "<NAME> <<EMAIL>>"


class Socrata(object):
    def __init__(self, domain, app_token, username=None, password=None,
                 access_token=None, session_adapter=None):
        '''
        The required arguments are:
            domain: the domain you wish you to access
            app_token: your Socrata application token
        Simple requests are possible without an app_token, though these
        requests will be rate-limited.

        For write/update/delete operations or private datasets, the Socrata API
        currently supports basic HTTP authentication, which requires these
        additional parameters.
            username: your Socrata username
            password: <PASSWORD>

        The basic HTTP authentication comes with a deprecation warning, and the
        current recommended authentication method is OAuth 2.0. To make
        requests on behalf of the user using OAuth 2.0 authentication, follow
        the recommended procedure and provide the final access_token to the
        client.

        More information about authentication can be found in the official
        docs:
            http://dev.socrata.com/docs/authentication.html
        '''
        if not domain:
            raise Exception("A domain is required.")
        self.domain = domain

        # set up the session with proper authentication crendentials
        self.session = requests.Session()
        if not app_token:
            print "Warning: requests made without an app_token will be subject"
            " to strict throttling limits."
        else:
            self.session.headers.update({"X-App-token": app_token})

        self.authentication_validation(username, password, access_token)

        # use either basic HTTP auth or OAuth2.0
        if username and password:
            self.session.auth = (username, password)
        elif access_token:
            self.session.headers.update({"Authorization": "OAuth {0}"
                                        .format(access_token)})

        if session_adapter:
            self.session.mount(session_adapter["prefix"],
                               session_adapter["adapter"])
            self.uri_prefix = session_adapter["prefix"]
        else:
            self.uri_prefix = "https"

    def authentication_validation(self, username, password, access_token):
        '''
        Only accept one form of authentication.
        '''
        if bool(username) != bool(password):
            raise Exception("Basic authentication requires a username AND"
                            " password.")
        if (username and access_token) or (password and access_token):
            raise Exception("Cannot use both Basic Authentication and"
                            " OAuth2.0. Please use only one authentication"
                            " method.")<commit_msg>Print full warning message.<commit_after>from constants import MAX_LIMIT
from version import __version__, version_info

import requests
from cStringIO import StringIO
import csv
import json

__author__ = "<NAME> <<EMAIL>>"


class Socrata(object):
    def __init__(self, domain, app_token, username=None, password=<PASSWORD>,
                 access_token=None, session_adapter=None):
        '''
        The required arguments are:
            domain: the domain you wish you to access
            app_token: your Socrata application token
        Simple requests are possible without an app_token, though these
        requests will be rate-limited.

        For write/update/delete operations or private datasets, the Socrata API
        currently supports basic HTTP authentication, which requires these
        additional parameters.
            username: your Socrata username
            password: <PASSWORD>

        The basic HTTP authentication comes with a deprecation warning, and the
        current recommended authentication method is OAuth 2.0. To make
        requests on behalf of the user using OAuth 2.0 authentication, follow
        the recommended procedure and provide the final access_token to the
        client.

        More information about authentication can be found in the official
        docs:
            http://dev.socrata.com/docs/authentication.html
        '''
        if not domain:
            raise Exception("A domain is required.")
        self.domain = domain

        # set up the session with proper authentication crendentials
        self.session = requests.Session()
        if not app_token:
            print ("Warning: requests made without an app_token will be subject"
            " to strict throttling limits.")
        else:
            self.session.headers.update({"X-App-token": app_token})

        self.authentication_validation(username, password, access_token)

        # use either basic HTTP auth or OAuth2.0
        if username and password:
            self.session.auth = (username, password)
        elif access_token:
            self.session.headers.update({"Authorization": "OAuth {0}"
                                        .format(access_token)})

        if session_adapter:
            self.session.mount(session_adapter["prefix"],
                               session_adapter["adapter"])
            self.uri_prefix = session_adapter["prefix"]
        else:
            self.uri_prefix = "https"

    def authentication_validation(self, username, password, access_token):
        '''
        Only accept one form of authentication.
        '''
        if bool(username) != bool(password):
            raise Exception("Basic authentication requires a username AND"
                            " password.")
        if (username and access_token) or (password and access_token):
            raise Exception("Cannot use both Basic Authentication and"
                            " OAuth2.0. Please use only one authentication"
                            " method.")
{'fraction_non_alphanumeric': 0.06641397495056031, 'fraction_numerical': 0.002966381015161503, 'mean_word_length': 2.1658841940532083, 'pattern_counts': {'":': 4, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3992874', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1357, 'n_words': 516}