<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals, print_function
import os
import sys

import pytest
from six import StringIO
from six.moves.urllib.parse import urlparse
from httmock import urlmatch, HTTMock, response
from tornado.concurrent import Future
from tornado.httpclient import HTTPResponse
from wechatpy._compat import json


pytestmark = pytest.mark.skipif(
    sys.version_info < (2, 7),
    reason='requires Python 2.7'
)

_TESTS_PATH = os.path.abspath(os.path.dirname(__file__))
_FIXTURE_PATH = os.path.join(_TESTS_PATH, 'fixtures')
APPID = '123456'
SECRET = '123456'


@urlmatch(netloc=r'(.*\.)?api\.weixin\.qq\.com$')
def access_token_mock(url, request):
    path = url.path.replace('/cgi-bin/', '').replace('/', '_')
    if path.startswith('_'):
        path = path[1:]
    res_file = os.path.join(_FIXTURE_PATH, '%s.json' % path)
    content = {
        'errcode': 99999,
        'errmsg': 'can not find fixture %s' % res_file,
    }
    headers = {
        'Content-Type': 'application/json'
    }
    try:
        with open(res_file, 'rb') as f:
            content = json.loads(f.read().decode('utf-8'))
    except (IOError, ValueError) as e:
        content['errmsg'] = 'Loads fixture {0} failed, error: {1}'.format(
            res_file,
            e
        )
    return response(200, content, headers, request=request)


def wechat_api_mock(client, request, *args, **kwargs):
    url = urlparse(request.url)
    path = url.path.replace('/cgi-bin/', '').replace('/', '_')<commit_msg>Fix test failure on Python 2.6<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals, print_function
import os
import sys

import pytest
from six import StringIO
from six.moves.urllib.parse import urlparse
from httmock import urlmatch, HTTMock, response
from wechatpy._compat import json


pytestmark = pytest.mark.skipif(
    sys.version_info < (2, 7),
    reason='requires Python 2.7'
)

_TESTS_PATH = os.path.abspath(os.path.dirname(__file__))
_FIXTURE_PATH = os.path.join(_TESTS_PATH, 'fixtures')
APPID = '123456'
SECRET = '123456'


@urlmatch(netloc=r'(.*\.)?api\.weixin\.qq\.com$')
def access_token_mock(url, request):
    path = url.path.replace('/cgi-bin/', '').replace('/', '_')
    if path.startswith('_'):
        path = path[1:]
    res_file = os.path.join(_FIXTURE_PATH, '%s.json' % path)
    content = {
        'errcode': 99999,
        'errmsg': 'can not find fixture %s' % res_file,
    }
    headers = {
        'Content-Type': 'application/json'
    }
    try:
        with open(res_file, 'rb') as f:
            content = json.loads(f.read().decode('utf-8'))
    except (IOError, ValueError) as e:
        content['errmsg'] = 'Loads fixture {0} failed, error: {1}'.format(
            res_file,
            e
        )
    return response(200, content, headers, request=request)


def wechat_api_mock(client, request, *args, **kwargs):
    from tornado.concurrent import Future
    from tornado.httpclient import HTTPResponse

    url = urlparse(request.url)
    path = url.path.replace('/cgi-bin/', '').replace('/', '_')
{'fraction_non_alphanumeric': 0.14955357142857142, 'fraction_numerical': 0.01913265306122449, 'mean_word_length': 3.2506775067750677, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4209644', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1065, 'n_words': 251}