<commit_before>"""
    Python Zendesk is wrapper for the Zendesk API. This library provides an
    easy and flexible way for developers to communicate with their Zendesk
    account in their application.

    Notes:
    API THROTTLE is not handled in this library:
        From Zendesk: The throttle will be applied once an API consumer
        reaches a certain threshold in terms of a maximum of requests per
        minute. Most clients will never hit this threshold, but those that do,
        will get met by a HTTP 503 response code and a text body of
        "Number of allowed API requests per minute exceeded"

    TICKETS AS AN END-USER is not handled in this library:
        There are a number of API calls for working with helpdesk tickets as
        if you were the person (end-user) who originally created them. At the
        moment, this library is primarily for admins and agents to interact

    FORUMS, ENTRIES, POSTS have not yet been implemented

"""

__author__ = "<NAME> <<EMAIL>>"
__version__ = "1.0.0"

import re
import httplib2
import urllib
try:
    import simplejson as json
except:
    import json
from httplib import responses
from endpoints import mapping_table


class ZendeskError(Exception):
    def __init__(self, msg, error_code=None):
        self.msg = msg
        self.error_code = error_code
        # Zendesk will throw a 401 response for un-authneticated call
        if self.error_code == 401:
            raise AuthenticationError(self.msg)

    def __str__(self):
        return repr('%s: %s' % (self.error_code, self.msg))


class AuthenticationError(ZendeskError):
    def __init__(self, msg):
        self.msg = msg

    def __str__(self):
        return repr(self.msg)


re_identifier = re.compile(r".*/(?P<identifier>\d+)\.(json|xml)")
def get_id_from_url(url):
    match = re_identifier.match(url)
    if match and match.group('identifier'):
        return match.group('identifier')


class Zendesk(object):
    """ Python API Wrapper for Zendesk"""

    def __init__(self, zendesk_url, zendesk_username=None,
                 zendesk_password=None, headers=None, client_args={}):
        """
        Instantiates an instance of Zendesk. Takes optional parameters for
        HTTP Basic Authentication

        Parameters:
        zendesk_url - https://company.zendesk.com (use http if not SSL enabled)
        zendesk_username - Specific to your Zendesk account (typically email)
        zendesk_password - Specific to your Zendesk account
        headers - Pass headers in dict form. This will override default.
        client_args - Pass arguments to http client in dict form.
            {'cache': False, 'timeout': 2}
        """
        self.data = None

        # Set attributes necessary for API
        self.zendesk_url = zendesk_url
        self.zendesk_username = zendesk_username
        self.zendesk_password = <PASSWORD><commit_msg>add support for using api token authentication<commit_after>"""
    Python Zendesk is wrapper for the Zendesk API. This library provides an
    easy and flexible way for developers to communicate with their Zendesk
    account in their application.

    Notes:
    API THROTTLE is not handled in this library:
        From Zendesk: The throttle will be applied once an API consumer
        reaches a certain threshold in terms of a maximum of requests per
        minute. Most clients will never hit this threshold, but those that do,
        will get met by a HTTP 503 response code and a text body of
        "Number of allowed API requests per minute exceeded"

    TICKETS AS AN END-USER is not handled in this library:
        There are a number of API calls for working with helpdesk tickets as
        if you were the person (end-user) who originally created them. At the
        moment, this library is primarily for admins and agents to interact

    FORUMS, ENTRIES, POSTS have not yet been implemented

"""

__author__ = "<NAME> <<EMAIL>>"
__version__ = "1.0.0"

import re
import httplib2
import urllib
try:
    import simplejson as json
except:
    import json
from httplib import responses
from endpoints import mapping_table


class ZendeskError(Exception):
    def __init__(self, msg, error_code=None):
        self.msg = msg
        self.error_code = error_code
        # Zendesk will throw a 401 response for un-authneticated call
        if self.error_code == 401:
            raise AuthenticationError(self.msg)

    def __str__(self):
        return repr('%s: %s' % (self.error_code, self.msg))


class AuthenticationError(ZendeskError):
    def __init__(self, msg):
        self.msg = msg

    def __str__(self):
        return repr(self.msg)


re_identifier = re.compile(r".*/(?P<identifier>\d+)\.(json|xml)")
def get_id_from_url(url):
    match = re_identifier.match(url)
    if match and match.group('identifier'):
        return match.group('identifier')


class Zendesk(object):
    """ Python API Wrapper for Zendesk"""

    def __init__(self, zendesk_url, zendesk_username=None,
                 zendesk_password=<PASSWORD>, use_api_token=True, headers=None, 
                 client_args={}):
        """
        Instantiates an instance of Zendesk. Takes optional parameters for
        HTTP Basic Authentication

        Parameters:
        zendesk_url - https://company.zendesk.com (use http if not SSL enabled)
        zendesk_username - Specific to your Zendesk account (typically email)
        zendesk_password - Specific to your Zendesk account or your account's 
            API token if use_api_token is True
        use_api_token - use api token for authentication instead of user's 
            actual password
        headers - Pass headers in dict form. This will override default.
        client_args - Pass arguments to http client in dict form.
            {'cache': False, 'timeout': 2}
        """
        self.data = None

        # Set attributes necessary for API
        self.zendesk_url = zendesk_url
        self.zendesk_username = zendesk_username
        if use_api_token:
            self.zendesk_username += "/token"
        self.zendesk_password = <PASSWORD>sk_password
{'fraction_non_alphanumeric': 0.06888671237349005, 'fraction_numerical': 0.004570682337577538, 'mean_word_length': 2.779765576804442, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4075813', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1645, 'n_words': 658}