<commit_before>__author__ = '<NAME>'
__credits__ = ["<NAME>"]
__license__ = "Apache License"
__version__ = "1.0.0"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Release"

import urllib.parse
import mimetypes
import base64
import pycurl
import json
import io


class PushBullet:
    def __init__(self, api_id):
        self.auth_id = api_id
        self.post_data = {}

    def pb_request(self, url, req_method=None):
        curl_obj = pycurl.Curl()
        response = io.BytesIO()
        encoded_string = base64.encodebytes(('%s:' % self.auth_id).encode())[:-1]
        auth = "Basic %s" % encoded_string.decode('utf-8')
        if self.post_data:
            req_data = json.dumps(self.post_data)
            curl_obj.setopt(pycurl.POST, 1)
            curl_obj.setopt(curl_obj.POSTFIELDS, req_data)
        if req_method:
            curl_obj.setopt(pycurl.CUSTOMREQUEST, req_method)
        curl_obj.setopt(pycurl.URL, url)
        curl_obj.setopt(curl_obj.WRITEFUNCTION, response.write)
        curl_obj.setopt(curl_obj.HTTPHEADER, ["Authorization: " + auth,
                                              "Accept: application/json",
                                              "Content-Type: application/json",
                                              "User-Agent: PushBullet-agent"])
        curl_obj.perform()
        return curl_obj.getinfo(pycurl.HTTP_CODE), \
               curl_obj.getinfo(pycurl.EFFECTIVE_URL), \
               json.loads(response.getvalue().decode())


class PBPushes(PushBullet):
    def __init__(self, api_key_id):
        PushBullet.__init__(self, api_key_id)

    def get_push_history(self):
        return self.pb_request('https://api.pushbullet.com/v2/pushes?modified_after=0')

    def del_pushes(self, push_id):
        return self.pb_request('https://api.pushbullet.com/v2/pushes/%s' % push_id, req_method='DELETE')

    def pushes(self, **pbargs):
        self.post_data = pbargs
        return self.pb_request('https://api.pushbullet.com/v2/pushes')


class PBFileUpload(PushBullet):
    def __init__(self, api_key_id):
        PushBullet.__init__(self, api_key_id)
        self.file_upload_param = {}

    def upload_request(self, file_name):
        my_mime = mimetypes.guess_type(file_name)[0]
        url_param = urllib.parse.urlencode({'file_name': file_name, 'file_type': my_mime})
        response = self.pb_request('https://api.pushbullet.com/v2/upload-request?' + url_param)[2]
        self.file_upload_param = response
        return response

    def pb_upload(self, file_path):
        buffer = io.BytesIO()
        data = [(elm, str(val)) for (elm, val) in self.file_upload_param['data'].items()]
        data.append(('file', (pycurl.FORM_FILE, file_path)))
        my_curl = pycurl.Curl()
        my_curl.setopt(pycurl.URL, self.file_upload_param['upload_url'])
        my_curl.setopt(pycurl.POST, 1)
        my_curl.setopt(pycurl.HTTPPOST, data)
        my_curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
        my_curl.perform()
        return my_curl.getinfo(pycurl.HTTP_CODE), \
               my_curl.getinfo(pycurl.EFFECTIVE_URL)


class PBUsers(PushBullet):
    def __init__(self, api_key_id):
        PushBullet.__init__(self, api_key_id)

    def get_me(self):
        return self.pb_request('https://api.pushbullet.com/v2/users/me')


class PBContacts(PushBullet):
    def __init__(self, api_key_id):
        PushBullet.__init__(self, api_key_id)

    def get_contacts(self):
        return self.pb_request('https://api.pushbullet.com/v2/contacts')

    def del_contact(self, contact_iden):
        return self.pb_request('https://api.pushbullet.com/v2/contacts/%s' % contact_iden, req_method='DELETE')


class PBDevices(PushBullet):
    def __init__(self, api_key_id):
        PushBullet.__init__(self, api_key_id)

    def get_connected_devices(self):
        return self.pb_request('https://api.pushbullet.com/v2/devices')

    def del_connected_device(self, dev_id):
        return self.pb_request('https://api.pushbullet.com/v2/devices/%s' % dev_id, req_method='DELETE')<commit_msg>reduce number of lines. optimization has been done<commit_after>__author__ = '<NAME>'
__credits__ = ["<NAME>"]
__license__ = "Apache License"
__version__ = "1.0.0"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Release"

import urllib.parse
import mimetypes
import base64
import pycurl
import json
import io


class PushBullet:
    def __init__(self, api_id):
        self.auth_id = api_id
        self.post_data = {}
        self.main_url = 'https://api.pushbullet.com/v2/'

    def pb_request(self, url, req_method=None):
        curl_obj = pycurl.Curl()
        response = io.BytesIO()
        encoded_string = base64.encodebytes(('%s:' % self.auth_id).encode())[:-1]
        auth = "Basic %s" % encoded_string.decode('utf-8')
        if self.post_data:
            req_data = json.dumps(self.post_data)
            curl_obj.setopt(curl_obj.POSTFIELDS, req_data)
        if req_method:
            curl_obj.setopt(pycurl.CUSTOMREQUEST, req_method)
        curl_obj.setopt(pycurl.URL, url)
        curl_obj.setopt(curl_obj.WRITEFUNCTION, response.write)
        curl_obj.setopt(curl_obj.HTTPHEADER, ["Authorization: %s" % auth,
                                              "Accept: application/json",
                                              "Content-Type: application/json",
                                              "User-Agent: PushBullet-agent"])
        curl_obj.perform()
        return curl_obj.getinfo(pycurl.HTTP_CODE), \
               curl_obj.getinfo(pycurl.EFFECTIVE_URL), \
               json.loads(response.getvalue().decode())


class PBFileUpload(PushBullet):
    def __init__(self, api_key_id):
        PushBullet.__init__(self, api_key_id)
        self.file_upload_param = {}

    def upload_request(self, file_name):
        url_param = urllib.parse.urlencode({'file_name': file_name, 'file_type': mimetypes.guess_type(file_name)[0]})
        self.file_upload_param = self.pb_request('%supload-request?%s' % (self.main_url, url_param))[2]

    def pb_upload(self, file_path):
        buffer = io.BytesIO()
        data = [(elm, str(val)) for (elm, val) in self.file_upload_param['data'].items()]
        data.append(('file', (pycurl.FORM_FILE, file_path)))
        my_curl = pycurl.Curl()
        my_curl.setopt(pycurl.URL, self.file_upload_param['upload_url'])
        my_curl.setopt(pycurl.HTTPPOST, data)
        my_curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
        my_curl.perform()
        return my_curl.getinfo(pycurl.HTTP_CODE), \
               my_curl.getinfo(pycurl.EFFECTIVE_URL)


class PBUsers(PushBullet):
    def __init__(self, api_key_id):
        PushBullet.__init__(self, api_key_id)

    def get_me(self):
        return self.pb_request('%susers/me' % self.main_url)


class PBContacts(PushBullet):
    def __init__(self, api_key_id):
        PushBullet.__init__(self, api_key_id)

    def get_contacts(self):
        return self.pb_request('%scontacts' % self.main_url)

    def del_contact(self, contact_iden):
        return self.pb_request('%scontacts/%s' % (self.main_url, contact_iden), req_method='DELETE')


class PBDevices(PushBullet):
    def __init__(self, api_key_id):
        PushBullet.__init__(self, api_key_id)

    def get_connected_devices(self):
        return self.pb_request('%sdevices' % self.main_url)

    def del_connected_device(self, dev_id):
        return self.pb_request('%sdevices/%s' % (self.main_url, dev_id), req_method='DELETE')


class PBPushes(PushBullet):
    def __init__(self, api_key_id):
        PushBullet.__init__(self, api_key_id)

    def get_push_history(self):
        return self.pb_request('%spushes?modified_after=0' % self.main_url)

    def del_pushes(self, push_id):
        return self.pb_request('%spushes/%s' % (self.main_url, push_id), req_method='DELETE')

    def pushes(self, **pbargs):
        self.post_data = pbargs
        return self.pb_request('%spushes' % self.main_url)
{'fraction_non_alphanumeric': 0.1256413465148292, 'fraction_numerical': 0.0045050682017269425, 'mean_word_length': 2.9099804305283756, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2522136', 'n_tokens_mistral': 2763, 'n_tokens_neox': 2667, 'n_words': 422}