<commit_before># Copyright 2010 <NAME>
"""
OpenStack Client interface. Handles the REST calls and responses.
"""

import time
import urlparse
import urllib
import httplib2
import logging

try:
    import json
except ImportError:
    import simplejson as json

# Python 2.5 compat fix
if not hasattr(urlparse, 'parse_qsl'):
    import cgi
    urlparse.parse_qsl = cgi.parse_qsl

import novaclient
from novaclient import exceptions

_logger = logging.getLogger(__name__)

class OpenStackClient(httplib2.Http):

    USER_AGENT = 'python-novaclient/%s' % novaclient.__version__

    def __init__(self, user, apikey, auth_url):
        super(OpenStackClient, self).__init__()
        self.user = user
        self.apikey = apikey
        self.auth_url = auth_url

        self.management_url = None
        self.auth_token = None

        # httplib2 overrides
        self.force_exception_to_status_code = True

    def http_log(self, args, kwargs, resp, body):
        string_parts = ['curl -i']
        for element in args:
            if element in ('GET','POST'):
                string_parts.append(' -X %s' % element)
            else:
                string_parts.append(' %s' % element)

        for element in kwargs['headers']:
            string_parts.append(' -H "%s: %s"' % (element,kwargs['headers'][element]))

        _logger.debug("REQ: %s\n" % "".join(string_parts))
        _logger.debug("RESP:%s %s\n", resp,body)

    def request(self, *args, **kwargs):
        kwargs.setdefault('headers', {})
        kwargs['headers']['User-Agent'] = self.USER_AGENT<commit_msg>fix to reviewer comment: add check if logging disabled<commit_after># Copyright 2010 <NAME>
"""
OpenStack Client interface. Handles the REST calls and responses.
"""

import time
import urlparse
import urllib
import httplib2
import logging

try:
    import json
except ImportError:
    import simplejson as json

# Python 2.5 compat fix
if not hasattr(urlparse, 'parse_qsl'):
    import cgi
    urlparse.parse_qsl = cgi.parse_qsl

import novaclient
from novaclient import exceptions

_logger = logging.getLogger(__name__)

class OpenStackClient(httplib2.Http):

    USER_AGENT = 'python-novaclient/%s' % novaclient.__version__

    def __init__(self, user, apikey, auth_url):
        super(OpenStackClient, self).__init__()
        self.user = user
        self.apikey = apikey
        self.auth_url = auth_url

        self.management_url = None
        self.auth_token = None

        # httplib2 overrides
        self.force_exception_to_status_code = True

    def http_log(self, args, kwargs, resp, body):
        if not _logger.isEnabledFor(logging.DEBUG):
            return
            
        string_parts = ['curl -i']
        for element in args:
            if element in ('GET','POST'):
                string_parts.append(' -X %s' % element)
            else:
                string_parts.append(' %s' % element)

        for element in kwargs['headers']:
            string_parts.append(' -H "%s: %s"' % (element,kwargs['headers'][element]))

        _logger.debug("REQ: %s\n" % "".join(string_parts))
        _logger.debug("RESP:%s %s\n", resp,body)

    def request(self, *args, **kwargs):
        kwargs.setdefault('headers', {})
        kwargs['headers']['User-Agent'] = self.USER_AGENT
{'fraction_non_alphanumeric': 0.11385083713850837, 'fraction_numerical': 0.005479452054794521, 'mean_word_length': 2.7857142857142856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2601088', 'n_tokens_mistral': 1029, 'n_tokens_neox': 997, 'n_words': 261}