# Path: library/config/database.py

# 
# Path: library/utils/dict.py
# def dot2_(data):
#     
#     '''
#     用于处理字典的key中带有.转化为特定字符，如果写入mongodb，报错
#     :parm:
#         data:需要处理的字典
#     '''
#     
#     new_data = {}
#     if isinstance(data, dict) :
#         for key, vaule in data.items() :
#             key = key.replace('.' , fmt)
#             if isinstance(vaule, dict) :
#                 new_data[key] = dot2_(vaule)
#             else :
#                 new_data[key] = vaule
#     return new_data
# 
# def _2dot(data):   
#      
#     '''
#     用于处理字典的key中带有特定字符转化为.，如果写入mongodb，报错
#     :parm:
#         data:需要处理的字典
#     '''
#     
#     new_data = {}
#     if isinstance(data, dict) :
#         for key, vaule in data.items() :
#             key = key.replace(fmt , '.')
#             if isinstance(vaule, dict) :
#                 new_data[key] = _2dot(vaule)
#             else :
#                 new_data[key] = vaule
#     return new_data


import time, logging, pymongo
from bson.objectid import ObjectId
from library.config.database import mongo_config
from library.utils.dict import dot2_, _2dot
'''
参考文献https://pypi.python.org/pypi/pymongo/3.4.0
mongodb官方推荐
'''




class Op_Mongo():
    
    '''
    连接并操作mongo
    '''
    
    def __init__(self, dest=None, idletime=1000 * 60 * 60):
        
        self.logger = logging.getLogger("database")

# Path: library/config/database.py

# 
# Path: library/utils/dict.py
# def dot2_(data):
#     
#     '''
#     用于处理字典的key中带有.转化为特定字符，如果写入mongodb，报错
#     :parm:
#         data:需要处理的字典
#     '''
#     
#     new_data = {}
#     if isinstance(data, dict) :
#         for key, vaule in data.items() :
#             key = key.replace('.' , fmt)
#             if isinstance(vaule, dict) :
#                 new_data[key] = dot2_(vaule)
#             else :
#                 new_data[key] = vaule
#     return new_data
# 
# def _2dot(data):   
#      
#     '''
#     用于处理字典的key中带有特定字符转化为.，如果写入mongodb，报错
#     :parm:
#         data:需要处理的字典
#     '''
#     
#     new_data = {}
#     if isinstance(data, dict) :
#         for key, vaule in data.items() :
#             key = key.replace(fmt , '.')
#             if isinstance(vaule, dict) :
#                 new_data[key] = _2dot(vaule)
#             else :
#                 new_data[key] = vaule
#     return new_data


# Path: library/storage/database/mongo.py
import time, logging, pymongo
from bson.objectid import ObjectId
from library.config.database import mongo_config
from library.utils.dict import dot2_, _2dot

'''
参考文献https://pypi.python.org/pypi/pymongo/3.4.0
mongodb官方推荐
'''




class Op_Mongo():
    
    '''
    连接并操作mongo
    '''
    
    def __init__(self, dest=None, idletime=1000 * 60 * 60):
        
        self.logger = logging.getLogger("database")

        config = mongo_config