<commit_before>import random
import string
import base64
import hashlib
import http.client
import json
import iyzipay


class IyzipayResource:
    def __init__(self):
        pass

    RANDOM_STRING_SIZE = 8

    def connect(self, method, url, options, request=None, pki=None):
        connection = http.client.HTTPConnection(options['base_url'])
        request_json = json.dumps(request, ensure_ascii=False)
        connection.request(method, url, request_json, self.get_http_header(options, pki))
        return connection.getresponse()

    def get_http_header(self, options=None, pki_string=None):
        header = {"Accept": "application/json", "Content-type": "application/json"}
        if pki_string is not None:
            random_header_value = "".join(
                random.SystemRandom().choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in
                range(self.RANDOM_STRING_SIZE))
            header.update(
                {'Authorization': self.prepare_auth_string(options, random_header_value, pki_string)})
            header.update({'x-iyzi-rnd': random_header_value})
        return header

    def get_plain_http_header(self, options):
        return self.get_http_header(None, options)

    def prepare_auth_string(self, options, random_str, pki_string):
        hashed = self.generate_hash(options['api_key'], options['secret_key'], random_str, pki_string)
        return self.format_header_string(options['api_key'], hashed)

    @staticmethod
    def generate_hash(api_key, secret_key, random_string, pki_string):
        hash_str = api_key + random_string + secret_key + pki_string
        hex_dig = hashlib.sha1(hash_str.encode()).digest()
        return base64.b64encode(hex_dig)
<commit_msg>BKM initialize and auth methods implemented.<commit_after>import random
import string
import base64
import hashlib
import http.client
import json
import iyzipay


class IyzipayResource:
    def __init__(self):
        pass

    RANDOM_STRING_SIZE = 8

    def connect(self, method, url, options, request=None, pki=None):
        connection = http.client.HTTPConnection(options['base_url'])
        request_json = json.dumps(request)
        connection.request(method, url, request_json, self.get_http_header(options, pki))
        return connection.getresponse()

    def get_http_header(self, options=None, pki_string=None):
        header = {"Accept": "application/json", "Content-type": "application/json"}
        if pki_string is not None:
            random_header_value = "".join(
                random.SystemRandom().choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in
                range(self.RANDOM_STRING_SIZE))
            header.update(
                {'Authorization': self.prepare_auth_string(options, random_header_value, pki_string)})
            header.update({'x-iyzi-rnd': random_header_value})
        return header

    def get_plain_http_header(self, options):
        return self.get_http_header(None, options)

    def prepare_auth_string(self, options, random_str, pki_string):
        hashed = self.generate_hash(options['api_key'], options['secret_key'], random_str, pki_string)
        return self.format_header_string(options['api_key'], hashed)

    @staticmethod
    def generate_hash(api_key, secret_key, random_string, pki_string):
        hash_str = api_key + random_string + secret_key + pki_string
        hex_dig = hashlib.sha1(hash_str.encode()).digest()
        return base64.b64encode(hex_dig)

{'fraction_non_alphanumeric': 0.09957446808510638, 'fraction_numerical': 0.0045390070921985815, 'mean_word_length': 3.5555555555555554, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3921386', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1038, 'n_words': 214}