# Path: wxpy/utils/misc.py
# def handle_response(to_class=None):
#     """
#     装饰器：检查从 itchat 返回的字典对象，并将其转化为指定类的实例
#     若返回值不为0，会抛出 ResponseError 异常
# 
#     :param to_class: 需转化成的类，若为None则不转换
#     """
# 
#     def decorator(func):
#         @wraps(func)
#         def wrapped(*args, **kwargs):
#             ret = func(*args, **kwargs)
# 
#             if ret is None:
#                 return
# 
#             smart_map(check_response_body, ret)
# 
#             if to_class:
#                 if args:
#                     self = args[0]
#                 else:
#                     self = inspect.currentframe().f_back.f_locals.get('self')
# 
#                 from wxpy.api.bot import Bot
#                 if isinstance(self, Bot):
#                     bot = weakref.proxy(self)
#                 else:
#                     bot = getattr(self, 'bot', None)
#                     if not bot:
#                         raise ValueError('bot not found:m\nmethod: {}\nself: {}\nbot: {}'.format(
#                             func, self, bot
#                         ))
# 
#                 ret = smart_map(to_class, ret, bot)
# 
#                 if isinstance(ret, list):
#                     from wxpy.api.chats import Group
#                     if to_class == Group:
#                         from wxpy.api.chats import Groups
#                         ret = Groups(ret)
#                     else:
#                         from wxpy.api.chats import Chats
#                         ret = Chats(ret, bot)
# 
#             return ret
# 
#         return wrapped
# 
#     return decorator


import functools
import json
import itchat.config
import itchat.returnvalues
from .misc import handle_response
        :param bot: 所使用的机器人对象
        :param uri: API 路径，将与基础 URL 进行拼接
        """
        self.bot = bot
        self.url = self.bot.core.loginInfo['url'] + uri
        self.params = params
        self.data = {'BaseRequest': self.bot.core.loginInfo['BaseRequest']}
        self.headers = {
            'ContentType': 'application/json; charset=UTF-8',
            'User-Agent': itchat.config.USER_AGENT
        }

        for method in 'get', 'post', 'put', 'delete':
            setattr(self, method, functools.partial(
                self.request, method=method.upper()
            ))

    def request(self, method, to_class=None):
        """
        (在完成修改后) 发送请求
        
        :param method: 请求方法: 'GET', 'POST'，'PUT', 'DELETE' 等
        :param to_class: 使用 `@handle_response(to_class)` 把结果转化为相应的类
        """

        if self.data:
            self.data = json.dumps(self.data, ensure_ascii=False).encode('utf-8')
        else:
            self.data = None


# Path: wxpy/utils/misc.py
# def handle_response(to_class=None):
#     """
#     装饰器：检查从 itchat 返回的字典对象，并将其转化为指定类的实例
#     若返回值不为0，会抛出 ResponseError 异常
# 
#     :param to_class: 需转化成的类，若为None则不转换
#     """
# 
#     def decorator(func):
#         @wraps(func)
#         def wrapped(*args, **kwargs):
#             ret = func(*args, **kwargs)
# 
#             if ret is None:
#                 return
# 
#             smart_map(check_response_body, ret)
# 
#             if to_class:
#                 if args:
#                     self = args[0]
#                 else:
#                     self = inspect.currentframe().f_back.f_locals.get('self')
# 
#                 from wxpy.api.bot import Bot
#                 if isinstance(self, Bot):
#                     bot = weakref.proxy(self)
#                 else:
#                     bot = getattr(self, 'bot', None)
#                     if not bot:
#                         raise ValueError('bot not found:m\nmethod: {}\nself: {}\nbot: {}'.format(
#                             func, self, bot
#                         ))
# 
#                 ret = smart_map(to_class, ret, bot)
# 
#                 if isinstance(ret, list):
#                     from wxpy.api.chats import Group
#                     if to_class == Group:
#                         from wxpy.api.chats import Groups
#                         ret = Groups(ret)
#                     else:
#                         from wxpy.api.chats import Chats
#                         ret = Chats(ret, bot)
# 
#             return ret
# 
#         return wrapped
# 
#     return decorator


# Path: wxpy/utils/base_request.py
import functools
import json
import itchat.config
import itchat.returnvalues
from .misc import handle_response

        :param bot: 所使用的机器人对象
        :param uri: API 路径，将与基础 URL 进行拼接
        """
        self.bot = bot
        self.url = self.bot.core.loginInfo['url'] + uri
        self.params = params
        self.data = {'BaseRequest': self.bot.core.loginInfo['BaseRequest']}
        self.headers = {
            'ContentType': 'application/json; charset=UTF-8',
            'User-Agent': itchat.config.USER_AGENT
        }

        for method in 'get', 'post', 'put', 'delete':
            setattr(self, method, functools.partial(
                self.request, method=method.upper()
            ))

    def request(self, method, to_class=None):
        """
        (在完成修改后) 发送请求
        
        :param method: 请求方法: 'GET', 'POST'，'PUT', 'DELETE' 等
        :param to_class: 使用 `@handle_response(to_class)` 把结果转化为相应的类
        """

        if self.data:
            self.data = json.dumps(self.data, ensure_ascii=False).encode('utf-8')
        else:
            self.data = None


        @handle_response(to_class)