<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/5/19 上午8:54
# @Author  : Matrix
# @Site    : 
# @File    : exception.py
# @Software: PyCharm
from json import JSONDecodeError

__author__ = 'blackmatrix'

'''
接口异常类型的管理与继承
'''

_no_value = object()


class ApiException(Exception):

    def __init__(self,  message, *, err_code='0000', status_code=500):
        self.err_code = err_code
        self.status_code = status_code
        self.message = message

    def __str__(self):
        return str('异常编号：{code} 异常信息：{message}'.format(
            code=self.err_code,
            message=self.message))

    # 让类实例变成可调用对象，用于接收自定义异常信息，并抛出
    def __call__(self, message=_no_value, *, err_code=_no_value, status_code=_no_value):
        if message is not _no_value:
            self.message = message
        if err_code is not _no_value:
            self.err_code = err_code
        if status_code is not _no_value:
            self.status_code = status_code
        return self


class MetaApiExceptions(type):

    def __getattribute__(self, item):
        # 改变ApiException继承关系，支持将ApiException自定义为任何异常类型的子类
        ex_conf = super().__getattribute__(item)
        supers = (ex_conf.get('ex_type'), Exception) \
            if ex_conf.get('ex_type') and ex_conf.get('ex_type') is not Exception \
            else (Exception, )<commit_msg>去除key only的限制<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/5/19 上午8:54
# @Author  : Matrix
# @Site    : 
# @File    : exception.py
# @Software: PyCharm
from json import JSONDecodeError

__author__ = 'blackmatrix'

'''
接口异常类型的管理与继承
'''

_no_value = object()


class ApiException(Exception):

    def __init__(self,  message, err_code='0000', status_code=500):
        self.err_code = err_code
        self.status_code = status_code
        self.message = message

    def __str__(self):
        return str('异常编号：{code} 异常信息：{message}'.format(
            code=self.err_code,
            message=self.message))

    # 让类实例变成可调用对象，用于接收自定义异常信息，并抛出
    def __call__(self, message=_no_value, *, err_code=_no_value, status_code=_no_value):
        if message is not _no_value:
            self.message = message
        if err_code is not _no_value:
            self.err_code = err_code
        if status_code is not _no_value:
            self.status_code = status_code
        return self


class MetaApiExceptions(type):

    def __getattribute__(self, item):
        # 改变ApiException继承关系，支持将ApiException自定义为任何异常类型的子类
        ex_conf = super().__getattribute__(item)
        supers = (ex_conf.get('ex_type'), Exception) \
            if ex_conf.get('ex_type') and ex_conf.get('ex_type') is not Exception \
            else (Exception, )
{'fraction_non_alphanumeric': 0.11058220432076163, 'fraction_numerical': 0.013181984621017943, 'mean_word_length': 2.7579092159559835, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1733456', 'n_tokens_mistral': 1004, 'n_tokens_neox': 1009, 'n_words': 185}