<commit_before>#!/usr/bin/env python
# -*- coding:utf8 -*-

import urllib
import urllib2
try:
    import simplejson as json
except ImportError:
    import json


class PyUniSend(object):
    errorMessage = ''
    errorCode = ''

    def __init__(self, api_key='', lang='ru',
                 secure=False, format='json',
                 test_mode=False, extra_params={}):
        """
        Cache API key, lang, secure, format and address.
        """
        self.api_key = api_key
        self.lang = lang
        self.secure = secure
        self.format = format
        self.test_mode = test_mode

        self.default_params = {'api_key': api_key,
                               'format': format,
                               'test_mode': test_mode}
        if not test_mode:
            self.default_params.pop('test_mode')
        self.default_params.update(extra_params)
        if secure:
            self.base_api_url = 'https://www.unisender.com/%s/api/' % self.lang
        else:
            self.base_api_url = 'http://api.unisender.com/%s/api/' % self.lang

    def call(self, method, params={}):
        url = self.base_api_url + method
        params.update(self.default_params)

        params = urllib.urlencode(self.http_build_query(params),
                                  doseq=True)

        request = urllib2.Request(url, params,
                                  {'User-Agent': 'PyUniSender 0.1.0'})
        response = urllib2.urlopen(request)

        result = json.loads(response.read())

        try:
            if 'error' in result:
                self.errorMessage = result['code']
                self.errorCode = result['error']
        except TypeError:
            pass  # exception for non-iterable (boolean) types

        return result

    def __getattr__(self, method_name):

        def get(self, *args, **kwargs):
            params = dict((i, j) for (i, j) in enumerate(args))
            params.update(kwargs)
            return self.call(method_name, params)

        return get.__get__(self)

    def http_build_query(self, params, key=None):<commit_msg>fix secure url; code style<commit_after>#!/usr/bin/env python
# -*- coding:utf8 -*-

import urllib
import urllib2
try:
    import simplejson as json
except ImportError:
    import json


class PyUniSend(object):

    errorMessage = ''
    errorCode = ''

    def __init__(self, api_key='', lang='ru', secure=False, format_='json',
        test_mode=False, extra_params={}):
        """
        Cache API key, lang, secure, format and address.
        """
        self.api_key = api_key
        self.lang = lang
        self.secure = secure
        self.format = format_
        self.test_mode = test_mode

        self.default_params = {
            'api_key': api_key,
            'format': format_,
        }
        if test_mode:
            self.default_params['test_mode'] = test_mode
        self.default_params.update(extra_params)

        self.base_api_url = '{scheme}://api.unisender.com/{lang}/api/'.format(
            scheme=('https' if secure else 'http'), lang=lang)

    def call(self, method, params={}):
        url = self.base_api_url + method
        params.update(self.default_params)
        params = urllib.urlencode(self.http_build_query(params), doseq=True)

        request = urllib2.Request(url, params,
            {'User-Agent': 'PyUniSender 0.1.0'})
        response = urllib2.urlopen(request)

        result = json.loads(response.read())

        try:
            if 'error' in result:
                self.errorMessage = result['code']
                self.errorCode = result['error']
        except TypeError:
            pass  # exception for non-iterable (boolean) types

        return result

    def __getattr__(self, method_name):

        def get(self, *args, **kwargs):
            params = dict(enumerate(args))
            params.update(kwargs)
            return self.call(method_name, params)

        return get.__get__(self)

    def http_build_query(self, params, key=None):
{'fraction_non_alphanumeric': 0.1156614544551998, 'fraction_numerical': 0.003474807644576818, 'mean_word_length': 1.991833704528582, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, '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': '6237155', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1172, 'n_words': 258}