<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

# Hive Appier Framework
# Copyright (C) 2008-2014 Hive Solutions Lda.
#
# This file is part of Hive Appier Framework.
#
# Hive Appier Framework is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hive Appier Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Hive Appier Framework. If not, see <http://www.gnu.org/licenses/>.

__author__ = "<NAME> <<EMAIL>>"
""" The author(s) of the module """

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2014 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "GNU General Public License (GPL), Version 3"
""" The license for the module """

import hmac
import uuid
import time
import base64
import hashlib
import logging

from appier import base
from appier import http
from appier import legacy
from appier import observer
from appier import exceptions

class Api(observer.Observable):
    """
    Abstract and top level api class that should be used
    as the foundation for the creation of api clients.

    This class should offer a set of services so that a
    concrete api implementation should not be concerned
    with issues like: logging, building and destruction.
    """

    def __init__(self, owner = None, *args, **kwargs):
        observer.Observable.__init__(self, *args, **kwargs)
        self.owner = owner or base.APP
        if not hasattr(self, "auth_callback"): self.auth_callback = None

    def get(self, url, headers = None, **kwargs):
        headers = headers or dict()
        self.build("GET", url, headers, kwargs)
        return self.request(
            http.get,
            url,
            params = kwargs,
            headers = headers,
            auth_callback = self.auth_callback
        )

    def post(
        self,
        url,
        data = None,
        data_j = None,
        data_m = None,
        headers = None,
        **kwargs
    ):
        headers = headers or dict()
        self.build("POST", url, headers, kwargs)
        return self.request(
            http.post,
            url,
            params = kwargs,
            data = data,
            data_j = data_j,
            data_m = data_m,
            headers = headers,
            auth_callback = self.auth_callback
        )

    def put(
        self,
        url,
        data = None,
        data_j = None,
        data_m = None,
        headers = None,
        **kwargs
    ):
        headers = headers or dict()
        self.build("PUT", url, headers, kwargs)
        return self.request(
            http.put,
            url,
            params = kwargs,
            data = data,
            data_j = data_j,
            data_m = data_m,
            headers = headers,
            auth_callback = self.auth_callback
        )

    def delete(self, url, headers = None, **kwargs):
        headers = headers or dict()
        self.build("DELETE", url, headers, kwargs)
        return self.request(
            http.delete,
            url,
            params = kwargs,
            headers = headers,
            auth_callback = self.auth_callback
        )

    def request(self, method, *args, **kwargs):
        try: result = method(*args, **kwargs)
        except exceptions.HTTPError as exception:
            self.handle_error(exception)
        else: return result
<commit_msg>support for "extra" params in api<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

# Hive Appier Framework
# Copyright (C) 2008-2014 Hive Solutions Lda.
#
# This file is part of Hive Appier Framework.
#
# Hive Appier Framework is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hive Appier Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Hive Appier Framework. If not, see <http://www.gnu.org/licenses/>.

__author__ = "<NAME> <<EMAIL>>"
""" The author(s) of the module """

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2014 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "GNU General Public License (GPL), Version 3"
""" The license for the module """

import hmac
import uuid
import time
import base64
import hashlib
import logging

from appier import base
from appier import http
from appier import legacy
from appier import observer
from appier import exceptions

class Api(observer.Observable):
    """
    Abstract and top level api class that should be used
    as the foundation for the creation of api clients.

    This class should offer a set of services so that a
    concrete api implementation should not be concerned
    with issues like: logging, building and destruction.
    """

    def __init__(self, owner = None, *args, **kwargs):
        observer.Observable.__init__(self, *args, **kwargs)
        self.owner = owner or base.APP
        if not hasattr(self, "auth_callback"): self.auth_callback = None

    def get(self, url, headers = None, params = None, **kwargs):
        headers = headers or dict()
        params = params or kwargs
        self.build("GET", url, headers, kwargs)
        return self.request(
            http.get,
            url,
            params = params,
            headers = headers,
            auth_callback = self.auth_callback
        )

    def post(
        self,
        url,
        data = None,
        data_j = None,
        data_m = None,
        headers = None,
        params = None,
        **kwargs
    ):
        headers = headers or dict()
        params = params or kwargs
        self.build("POST", url, headers, kwargs)
        return self.request(
            http.post,
            url,
            params = params,
            data = data,
            data_j = data_j,
            data_m = data_m,
            headers = headers,
            auth_callback = self.auth_callback
        )

    def put(
        self,
        url,
        data = None,
        data_j = None,
        data_m = None,
        headers = None,
        params = None,
        **kwargs
    ):
        headers = headers or dict()
        params = params or kwargs
        self.build("PUT", url, headers, kwargs)
        return self.request(
            http.put,
            url,
            params = params,
            data = data,
            data_j = data_j,
            data_m = data_m,
            headers = headers,
            auth_callback = self.auth_callback
        )

    def delete(self, url, headers = None, params = None, **kwargs):
        headers = headers or dict()
        params = params or kwargs
        self.build("DELETE", url, headers, kwargs)
        return self.request(
            http.delete,
            url,
            params = params,
            headers = headers,
            auth_callback = self.auth_callback
        )

    def request(self, method, *args, **kwargs):
        try: result = method(*args, **kwargs)
        except exceptions.HTTPError as exception:
            self.handle_error(exception)
        else: return result

{'fraction_non_alphanumeric': 0.08855818492315198, 'fraction_numerical': 0.005855086606489388, 'mean_word_length': 2.1977379095163805, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4507830', 'n_tokens_mistral': 2228, 'n_tokens_neox': 2187, 'n_words': 859}