<commit_before>#!/usr/bin/python
import httplib
import urllib

class OpsviewServer(object):
    def __init__(self, domain, username, password, path='/', secure=True):
        self.domain = domain
        self.username = username
        self.password = password
        self.path = path
        self.port = port
        self.hosts = []

        self.api_urls = dict({
            'acknowledge':      '%sstatus/service/acknowledge' % self.path,
            'status_all':       '%sapi/status/service',
            'status_service':   '%sapi/status/service',
            'status_host':      '%sapi/status/service',
            'status_hostgroup': '%sapi/status/hostgroup',
            'login':            '%slogin',
            'api':              '%sapi',
        })

    def __str__(self):
        return '%s:%i#%s' % (self.domain, self.port, self.path)

    def __repr__(self):
        return 'Server %s' % self

    def _connect(self):
        pass

    def _login(self):
        self._sendPost(self.api_urls['login'], urllib.urlencode(dict({'login':'Log In', 'back':'', 'login_username':self.username, 'login_password':<PASSWORD>})))

    def _acknowledge(self, targets, comment, notify, auto_remove_comment):
        pass

    def _sendXML(self, payload):
        pass

    def _sendGet(self, location, parameters=None, headers=None):
        if self.secure:
            connection = httplib.HTTPSConnection(self.host)
        else:
            connection = httplib.HTTPConnection(self.host)
        connection.request('GET', location, urllib.urlencode(parameters), headers)
        response = connection.getresponse()
        connection.close()

        return response.read()

    def _sendPost(self, location, parameters=None, headers=None):
        if self.secure:
            connection = httplib.HTTPSConnection(self.host, self.port)
        else:
            connection = httplib.HTTPConnection(self.host, self.port)
        connection.request('POST', location, urllib.urlencode(parameters), headers)
        response = connection.getresponse()
        connection.close()

        return response.read()

    def getStatusAll(self, filters):
        pass

    def getStatusHost(self, filters, host):
        pass

    def getStatusService(self, host, service):
        pass

    def getStatusHostgroup(self, hostgroup):
        pass

    def acknowledgeService(self, host, service, comment, notify=True, auto_remove_comment=True):
        pass

    def acknowledgeHost(self, host, comment, notify=True, auto_remove_comment=True):
        pass

    def acknowledgeAll(self, comment, notify=True, auto_remove_comment=True):
        pass

    def createHost(self, new_host_name):
        pass

    def cloneHost(self, new_host_name, old_host_name):
        pass

    def createHost(self, host):
        pass<commit_msg>can send post and get requests now<commit_after>#!/usr/bin/python
import urllib2, urllib
import xml.dom.minidom as minidom

class OpsviewException(Exception):
    def __init__(self, msg=None):
        self.msg = msg or 'Unknown Error'

    def __str__(self):
        return self.msg

class OpsviewServer(object):
    def __init__(self, domain, username, password, path=''):
        self.domain = domain
        self.username = username
        self.password = password
        self.path = path
        self.hosts = []
        self.api_urls = dict({
            'acknowledge':      '%sstatus/service/acknowledge' % self.path,
            'status_all':       '%sapi/status/service' % self.path,
            'status_service':   '%sapi/status/service' % self.path,
            'status_host':      '%sapi/status/service' % self.path,
            'status_hostgroup': '%sapi/status/hostgroup' % self.path,
            'login':            '%slogin' % self.path,
            'api':              '%sapi' % self.path,
        })

        self._cookies = urllib2.HTTPCookieProcessor()
        self._opener = urllib2.build_opener(self._cookies)

    def __str__(self):
        return '%s:%i#%s' % (self.domain, self.port, self.path)

    def __repr__(self):
        return 'Server %s' % self

    def _connect(self):
        pass

    def _login(self):
        if 'auth_tkt' not in [cookie.name for cookie in self._cookies.cookiejar]:
            self._sendPost(self.api_urls['login'], dict({'login':'Log In', 'back':'', 'login_username':self.username, 'login_password':<PASSWORD>}))
        assert 'auth_tkt' in [cookie.name for cookie in self._cookies.cookiejar], OpsviewException('Login failed')

    def _acknowledge(self, targets, comment, notify, auto_remove_comment):
        pass

    def _sendXML(self, payload):
        pass

    def _sendGet(self, location, parameters=[], headers=None):
        request = urllib2.Request('https://%s/%s?%s' % (self.domain, location, urllib.urlencode(parameters)))
        if headers:
            map(lambda header_key: request.add_header(header_key, headers[header_key]), headers)
        request.add_header('Content-Type', 'text/xml')
        try:
            reply = self._opener.open(request)
        except urllib2.HTTPError, reply:
            return reply
        else:
            return reply

    def _sendPost(self, location, data, headers=None):
        request = urllib2.Request('https://%s/%s' % (self.domain, location), urllib.urlencode(data))
        if headers:
            map(lambda header_key: request.add_header(header_key, headers[header_key]), headers)
        try:
            reply = self._opener.open(request)
        except urllib2.HTTPError, reply:
            return reply
        else:
            return reply

    def getStatusAll(self, filters=None):
        return minidom.parse(self._sendGet(self.api_urls['status_all']))

    def getStatusHost(self, filters, host):
        pass

    def getStatusService(self, host, service):
        pass

    def getStatusHostgroup(self, hostgroup):
        pass

    def acknowledgeService(self, host, service, comment, notify=True, auto_remove_comment=True):
        pass

    def acknowledgeHost(self, host, comment, notify=True, auto_remove_comment=True):
        pass

    def acknowledgeAll(self, comment, notify=True, auto_remove_comment=True):
        pass

    def createHost(self, new_host_name):
        pass

    def cloneHost(self, new_host_name, old_host_name):
        pass

    def createHost(self, host):
        pass
{'fraction_non_alphanumeric': 0.11834040546911834, 'fraction_numerical': 0.0011001100110011, 'mean_word_length': 2.5572945779765233, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3261320', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1871, 'n_words': 409}