# Path: girlfriend/util/lang.py
# def args2fields(private=True):
#     """专门是应用于构造函数的修饰器
#        可以将构造函数除self以外的参数悉数赋值给类属性
# 
#        比如
# 
#        class A(object):
# 
#             def __init__(self, a, b, c):
#                 self._a = a
#                 self._b = b
#                 self._c = c
#                 self.sum = self._a + self._b + self._c
# 
#         只要写成这样就好:
# 
#         class A(object):
# 
#             @args2fields()
#             def __init__(self, a, b, c):
#                 self.sum = self._a + self._b + self._c
# 
#         不必再去写上面那些无聊的赋值语句了
# 
#         :param private 是否转变为私有字段，如果为True，那么会在所有字段名前加个下划线
#     """
# 
#     def _field_name(arg_name):
#         return "_" + arg_name if private else arg_name
# 
#     def _args2fields(constructor):
# 
#         @wraps(constructor)
#         def _wrapped_constuctor(self, *args, **kws):
#             args_spec = inspect.getargspec(constructor)
#             for idx, arg in enumerate(args, start=1):
#                 arg_name = args_spec.args[idx]
#                 field_name = _field_name(arg_name)
#                 setattr(self, field_name, arg)
#             for arg_name, arg in kws.items():
#                 field_name = _field_name(arg_name)
#                 setattr(self, field_name, arg)
# 
#             # 处理没有赋值的默认参数
#             default_args = get_default_args(args_spec)
#             if default_args:
#                 for arg_name, default_value in default_args.items():
#                     if arg_name == "self":
#                         continue
#                     field_name = _field_name(arg_name)
#                     if hasattr(self, field_name):
#                         continue
#                     setattr(self, field_name, default_value)
# 
#             constructor(self, *args, **kws)
# 
#         return _wrapped_constuctor
# 
#     return _args2fields
# 
# Path: girlfriend/util/resource.py
# HTTP_SCHEMA = "http://", "https://"
# 
# Path: girlfriend/plugin/data.py
# class AbstractDataReader(AbstractDataHandler):
# 
#     __metaclass__ = ABCMeta
# 
#     def _handle_result(self, context, result):
#         """对最终结果进行包装
#         """
#         if self._result_wrapper is not None:
#             result = self._result_wrapper(result)
#         if self._variable:
#             context[self._variable] = result
#         return result
# 
# class AbstractDataWriter(AbstractDataHandler):
# 
#     __metaclass__ = ABCMeta
# 
#     pass
# 
# Path: girlfriend/exception.py
# class InvalidArgumentException(GirlFriendSysException):
# 
#     """当函数输入的参数不正确时抛出此异常
#     """
#     pass


import re
import types
import ujson
import requests
from girlfriend.util.lang import args2fields
from girlfriend.util.resource import HTTP_SCHEMA
from girlfriend.plugin.data import (
    AbstractDataReader,
    AbstractDataWriter
)
from girlfriend.exception import InvalidArgumentException
                    elif in_block:
                        json_buffer.append(char)
            # 按数组读取
            elif self._style == "array":
                json_array = ujson.loads(json_content)
                for record in json_array:
                    self._handle_record(record, result.append)
            # 使用属性提取器
            elif self._style.startswith("extract:"):
                json_obj = ujson.loads(json_content)
                keys = self._style[len("extract:"):].split(".")
                for key in keys:
                    json_obj = json_obj[key]
                for record in json_obj:
                    self._handle_record(record, result.append)

        return self._handle_result(context, result)


class JSONWriterPlugin(object):

    name = "write_json"

    def execute(self, context, *json_writers):
        for json_writer in json_writers:
            json_writer(context)


class JSONW(AbstractDataWriter):


# Path: girlfriend/util/lang.py
# def args2fields(private=True):
#     """专门是应用于构造函数的修饰器
#        可以将构造函数除self以外的参数悉数赋值给类属性
# 
#        比如
# 
#        class A(object):
# 
#             def __init__(self, a, b, c):
#                 self._a = a
#                 self._b = b
#                 self._c = c
#                 self.sum = self._a + self._b + self._c
# 
#         只要写成这样就好:
# 
#         class A(object):
# 
#             @args2fields()
#             def __init__(self, a, b, c):
#                 self.sum = self._a + self._b + self._c
# 
#         不必再去写上面那些无聊的赋值语句了
# 
#         :param private 是否转变为私有字段，如果为True，那么会在所有字段名前加个下划线
#     """
# 
#     def _field_name(arg_name):
#         return "_" + arg_name if private else arg_name
# 
#     def _args2fields(constructor):
# 
#         @wraps(constructor)
#         def _wrapped_constuctor(self, *args, **kws):
#             args_spec = inspect.getargspec(constructor)
#             for idx, arg in enumerate(args, start=1):
#                 arg_name = args_spec.args[idx]
#                 field_name = _field_name(arg_name)
#                 setattr(self, field_name, arg)
#             for arg_name, arg in kws.items():
#                 field_name = _field_name(arg_name)
#                 setattr(self, field_name, arg)
# 
#             # 处理没有赋值的默认参数
#             default_args = get_default_args(args_spec)
#             if default_args:
#                 for arg_name, default_value in default_args.items():
#                     if arg_name == "self":
#                         continue
#                     field_name = _field_name(arg_name)
#                     if hasattr(self, field_name):
#                         continue
#                     setattr(self, field_name, default_value)
# 
#             constructor(self, *args, **kws)
# 
#         return _wrapped_constuctor
# 
#     return _args2fields
# 
# Path: girlfriend/util/resource.py
# HTTP_SCHEMA = "http://", "https://"
# 
# Path: girlfriend/plugin/data.py
# class AbstractDataReader(AbstractDataHandler):
# 
#     __metaclass__ = ABCMeta
# 
#     def _handle_result(self, context, result):
#         """对最终结果进行包装
#         """
#         if self._result_wrapper is not None:
#             result = self._result_wrapper(result)
#         if self._variable:
#             context[self._variable] = result
#         return result
# 
# class AbstractDataWriter(AbstractDataHandler):
# 
#     __metaclass__ = ABCMeta
# 
#     pass
# 
# Path: girlfriend/exception.py
# class InvalidArgumentException(GirlFriendSysException):
# 
#     """当函数输入的参数不正确时抛出此异常
#     """
#     pass


# Path: girlfriend/plugin/json.py
import re
import types
import ujson
import requests
from girlfriend.util.lang import args2fields
from girlfriend.util.resource import HTTP_SCHEMA
from girlfriend.plugin.data import (
    AbstractDataReader,
    AbstractDataWriter
)
from girlfriend.exception import InvalidArgumentException

                    elif in_block:
                        json_buffer.append(char)
            # 按数组读取
            elif self._style == "array":
                json_array = ujson.loads(json_content)
                for record in json_array:
                    self._handle_record(record, result.append)
            # 使用属性提取器
            elif self._style.startswith("extract:"):
                json_obj = ujson.loads(json_content)
                keys = self._style[len("extract:"):].split(".")
                for key in keys:
                    json_obj = json_obj[key]
                for record in json_obj:
                    self._handle_record(record, result.append)

        return self._handle_result(context, result)


class JSONWriterPlugin(object):

    name = "write_json"

    def execute(self, context, *json_writers):
        for json_writer in json_writers:
            json_writer(context)


class JSONW(AbstractDataWriter):


    @args2fields()