<commit_before>import pycurl
import gzip
from StringIO import StringIO as sio
from urllib import urlencode
from oslo.config import cfg

class RPC:
    """ RPC class. Used to connect to the client and pass the XML files.
    """
    def __init__(self):
        self.auth = self.CONF.dm_username+':'+self.CONF.dm_password
        self.host = cfg.CONF.dm_host
        self.method = cfg.CONF.method

    def _create_url(self):
        return self.method+'://'+self.auth+'@'+self.host+\
               '/System/File/file_config.html'


    def send_xml(self, xml):
        c = pycurl.Curl()

        #ignore ssl certificate verification
        if self.method is 'https'
            c.setopt(c.SSL_VERIFYPEER, 0)
            c.setopt(c.SSL_VERIFYHOST, 0)

        #set url being used
        c.setopt(c.URL, self._create_url())

        #oppening and zipping the xml file
        with open('teste.xml', 'r') as xml_file:
            xml_content = xml_file.read()

        ziped = sio()
        with gzip.GzipFile(fileobj=ziped, mode='w') as f:
            f.write(xml_content)

        run_data = ziped.getvalue()

        #sets necessary multipart fields and adds the zip from buffer
        data = [('page', 'file_upload'),
               ('running_part', '1'),
               ('file_to_upload', (c.FORM_BUFFER, 'upate_config',
                                  c.FORM_BUFFERPTR, run_data))]

        #sets POST method and the multipart packet
        c.setopt(c.HTTPPOST, data)

        #executes curl and exits
        c.perform()
        c.close()

    def _update_boundary(self, req, bound):
        """ Update the request with the expected boundary
        """
        current_boundary = self._get_boundary(req.headers)

        req.headers['Content-Type'] = req.headers['Content-Type'].\
            replace(current_boundary, self.expected_boundary)

        req.body = req.body.replace(current_boundary, self.expected_boundary)

    def _get_boundary(self, header):
        """ Returns the current boundary of the header
        """
        return re.findall('boundary=(.*)', header)[0]
<commit_msg>Fix and Clean-up the RPC class<commit_after>""" RPC class used to communicate with the hardware
"""
import pycurl
import gzip
from StringIO import StringIO as sio
from oslo.config import cfg

class RPC:
    """ RPC class. Used to connect to the client and pass the XML files.
    """
    def __init__(self):
        self.auth = self.CONF.dm_username+':'+self.CONF.dm_password
        self.host = cfg.CONF.dm_host
        self.method = cfg.CONF.method

    def _create_url(self):
        """ Internal method that returns the switches' URLs given the cfg
        attributes.
        """
        return self.method+'://'+self.auth+'@'+self.host+\
               '/System/File/file_config.html'


    def send_xml(self):
        """ Method used to send a given xml file to the switches
        """
        req = pycurl.Curl()

        #ignore ssl certificate verification
        if self.method is 'https':
            req.setopt(req.SSL_VERIFYPEER, 0)
            req.setopt(req.SSL_VERIFYHOST, 0)

        #set url being used
        req.setopt(req.URL, self._create_url())

        #oppening and zipping the xml file
        with open('teste.xml', 'r') as xml_file:
            xml_content = xml_file.read()

        ziped = sio()
        with gzip.GzipFile(fileobj=ziped, mode='w') as gzip_file:
            gzip_file.write(xml_content)

        run_data = ziped.getvalue()

        #sets necessary multipart fields and adds the zip from buffer
        data = [('page', 'file_upload'),
               ('running_part', '1'),
               ('file_to_upload', (req.FORM_BUFFER, 'upate_config',
                                  req.FORM_BUFFERPTR, run_data))]

        #sets POST method and the multipart packet
        req.setopt(req.HTTPPOST, data)

        #executes curl and exits
        req.perform()
        req.close()

{'fraction_non_alphanumeric': 0.10972505091649694, 'fraction_numerical': 0.0017820773930753565, 'mean_word_length': 2.1736672051696284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, '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': '1948207', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1160, 'n_words': 318}