示例#1
0
 def default(self, o):
     if isinstance(o, datetime.datetime):
         return o.strftime('%Y-%m-%d %H:%M:%S')
     elif isinstance(o, datetime.date):
         return o.strftime('%Y-%m-%d')
     else:
         return JSONEncoder.default(self, o)
示例#2
0
def _toggle_speedups(enabled):
    import simplejson.decoder as dec
    import simplejson.encoder as enc
    import simplejson.scanner as scan
    c_make_encoder = _import_c_make_encoder()
    if enabled:
        dec.scanstring = dec.c_scanstring or dec.py_scanstring
        enc.c_make_encoder = c_make_encoder
        enc.encode_basestring_ascii = (enc.c_encode_basestring_ascii
                                       or enc.py_encode_basestring_ascii)
        scan.make_scanner = scan.c_make_scanner or scan.py_make_scanner
    else:
        dec.scanstring = dec.py_scanstring
        enc.c_make_encoder = None
        enc.encode_basestring_ascii = enc.py_encode_basestring_ascii
        scan.make_scanner = scan.py_make_scanner
    dec.make_scanner = scan.make_scanner
    global _default_decoder
    _default_decoder = JSONDecoder(
        encoding=None,
        object_hook=None,
        object_pairs_hook=None,
    )
    global _default_encoder
    _default_encoder = JSONEncoder(
        skipkeys=False,
        ensure_ascii=True,
        check_circular=True,
        allow_nan=True,
        indent=None,
        separators=None,
        encoding='utf-8',
        default=None,
    )
 def default(self, obj):
     if isinstance(obj, QuerySet):
         return list(obj)
     if isinstance(obj, DBRef):
         doc = get_db().dereference(obj)
         try:
             doc.pop('_cls')
             doc.pop('_types')
         except:
             pass
         return doc
     if isinstance(obj, (Document, EmbeddedDocument)):
         doc = obj.to_mongo()
         try:
             doc.pop('_cls')
             doc.pop('_types')
         except:
             pass
         return doc
     if isinstance(obj, ObjectId):
         return str(obj)
     elif isinstance(obj, datetime):
         return obj.isoformat().replace('T', ' ')
     elif isinstance(obj, (date, time)):
         return obj.isoformat()
     return JSONEncoder.default(self, obj)
示例#4
0
	def processOfRequest(self):
		self._approot_path = os.path.dirname(__file__)

		last_modified_language = ''	# Wed, 21 Jun 2006 07:00:25 GMT
		last_modified_default = ''	# Wed, 21 Jun 2006 07:00:25 GMT
		language = UcfUtil.nvl(self.getRequest('ln'));
		if language != '':
			last_modified_language = UcfMessage.getLangFileLastModified(self._approot_path, language=language)
		if language.lower() != UcfConfig.MESSAGE_DEFAULT_FILE.lower():
			last_modified_default = UcfMessage.getLangFileLastModified(self._approot_path, language=UcfConfig.MESSAGE_DEFAULT_FILE)
		else:
			last_modified_default = last_modified_language

		last_modified = str(last_modified_language) + '|' + str(last_modified_default)

#		if self.request.headers.has_key('If-Modified-Since'):
#			logging.info('If-Modified-Since=' + self.request.headers['If-Modified-Since'])
#		logging.info('last_modified=' + last_modified)

		if self.request.headers.has_key('If-Modified-Since') and last_modified is not None and self.request.headers['If-Modified-Since'] == last_modified:
			self.response.set_status(304)
			return

		msgs = UcfMessage.getMessageList(self._approot_path, language=language,is_only_js=True)

		template_vals = {
			'lang_json':JSONEncoder().encode(msgs)
		}
		#self.appendBasicInfoToTemplateVals(template_vals)
		self.response.headers['Last-Modified'] = last_modified
		self.render('jslang.html', self._design_type, template_vals, content_type='text/javascript')
示例#5
0
def custom_iterencode(value):
    from simplejson.encoder import (
        _make_iterencode,
        encode_basestring,
        FLOAT_REPR,
        JSONEncoder,
        PosInf,
    )

    j = JSONEncoder()

    def floatstr(o,
                 allow_nan=j.allow_nan,
                 ignore_nan=j.ignore_nan,
                 _repr=FLOAT_REPR,
                 _inf=PosInf,
                 _neginf=-PosInf):  # pragma: no cover
        if o != o:
            text = 'NaN'
        elif o == _inf:
            text = 'Infinity'
        elif o == _neginf:
            text = '-Infinity'
        else:
            return str(round(o, DEGREE_DECIMAL_PLACES))
        if ignore_nan:
            text = 'null'
        elif not allow_nan:
            raise ValueError(
                "Out of range float values are not JSON compliant: " + repr(o))

        return text

    markers = {}
    _encoder = encode_basestring
    _one_shot = False
    _iterencode = _make_iterencode(
        markers,
        j.default,
        _encoder,
        j.indent,
        floatstr,
        j.key_separator,
        j.item_separator,
        j.sort_keys,
        j.skipkeys,
        _one_shot,
        j.use_decimal,
        j.namedtuple_as_object,
        j.tuple_as_array,
        j.int_as_string_bitcount,
        j.item_sort_key,
        j.encoding,
        j.for_json,
    )

    return _iterencode(value, 0)
示例#6
0
def SRP_store(req, data):
    """
	Protocolo para tratar con passwords de forma criptograficamente segura.
	
	Recibe diccionario data con :
	username: String con el username
	v : Bigint de verificacion para SRP
	salt: Salt usada
	
	Devuelve diccionario con status (si status == OK, todo en orden)
	"""

    data = JSONDecoder("UTF-8").decode(data)
    db = MySQLdb.connect(host="localhost",
                         user="******",
                         passwd="1234",
                         db="prueba")

    ## Mirar que el user no exista ya
    if user_exists(data['username']):
        req.write(
            JSONEncoder("UTF-8").encode({"status": "Duplicated username."}))
        return

    ## Preparar transaccion
    sql = """
	INSERT INTO usuarios 
	(userName,v,salt,mail,sex,age,country,registrationDate,status) 
	VALUES( "%s","%s","%s","%s","%s","%s","%s","%s","NV")
	""" % (data['username'], data['v'], data['salt'], urllib.unquote(
        data["mail"]), data["sex"], data["age"], urllib.unquote(
            data["country"]), str(datetime.today()))

    cursor = db.cursor()
    #~ try:
    cursor.execute(sql)
    db.commit()
    req.write(JSONEncoder("UTF-8").encode({"status": "OK"}))
    #~ except:
    #~ db.rollback()
    #~ req.write(JSONEncoder("UTF-8").encode({"status":"Database operation failed."}))

    ## Desconectar
    db.close()
示例#7
0
    def putLoginInfoForDelay(cls, helper, operator_unique_id,
                             operator_mail_address, params):
        unique_id = UcfUtil.guid()
        key_name = UcfUtil.nvl(
            int(UcfUtil.nvl(int(time.time())).ljust(
                10, '0'))) + UcfConfig.KEY_PREFIX + unique_id  # 古いの順
        entry = UCFMDLLoginInfoForDelay(unique_id=unique_id, id=key_name)
        entry.operator_unique_id = operator_unique_id
        entry.operator_id_lower = operator_mail_address.lower()
        entry.params = JSONEncoder().encode(params)
        entry.date_changed = UcfUtil.getNow()
        entry.put()

        return entry
示例#8
0
def get_upload_progress(req, files, **kargs):
    ret = {}
    files = JSONDecoder("UTF-8").decode(files)
    session = req.session
    session.lock()
    for (slot, upfile) in files.iteritems():
        upfile = os.path.split(upfile)[1]
        if session.get('temp_name_' + upfile):
            cursize = 0
            try:
                cursize = os.path.getsize(session['temp_name_' + upfile])
            except:
                pass
            ret[slot] = (cursize * 100) / (session.get('temp_size_' + upfile) or 1)
    session.unlock()
    req.content_type = 'application/json; charset=UTF-8'
    return JSONEncoder("UTF-8").encode(ret)
示例#9
0
	def editVoForRegist(cls, helper, vo, entry_vo, edit_type):
		if edit_type == UcfConfig.EDIT_TYPE_NEW:
			vo['dept_id'] = UcfUtil.getHashStr(helper.getDeptInfo(), 'dept_id')

		vo['link_id_lower'] = vo.get('link_id', '').lower()
		
		# リンク数を算出
		link_info_json = UcfUtil.getHashStr(vo, 'link_info')
		if link_info_json != '':
			link_info = JSONDecoder().decode(link_info_json)

			# 各リンクにidを付与(未設定の場合だけ)
			for link_data in link_info:
				link = link_data.get('link')
				if not link.has_key('id') or link['id'] == '':
					link['id'] = UcfUtil.guid()
			vo['link_info'] = JSONEncoder().encode(link_info)
			vo['link_count'] = str(len(link_info))
		else:
			vo['link_count'] = str(len(0))
示例#10
0
    def outputResult(self, return_code, params=None):
        params = {} if params is None else params

        msg = ''
        if params.has_key('errors'):
            for err in params['errors']:
                if msg != '':
                    msg += '\n'
                msg += err.get('message', '')

        result = {
            'code':
            str(return_code),
            'msg':
            msg,
            'active_users':
            params['active_users'] if params.has_key('active_users') else -1
        }
        self.response.out.write(JSONEncoder().encode(result))
        logging.info(result)
示例#11
0
    def processOfRequest(self, tenant):

        CSRF_TOKEN_KEY = 'operator'

        try:
            self._approot_path = os.path.dirname(__file__)
            if self.isValidTenant() == False:
                return

            if loginfunc.checkLogin(self) == False:
                return

            # 権限チェック
            if self.isAdmin() == False and self.isOperator(
                    target_function=UcfConfig.DELEGATE_FUNCTION_OPERATOR_CONFIG
            ) == False:
                #				self.redirectError(UcfMessage.getMessage(self.getMsg('MSG_INVALID_ACCESS_AUTHORITY')))
                self.redirect('/a/' + tenant + '/personal/')
                return

            # ログイン時の各種情報を取得&チェック
            is_select_ok, user_vo, profile_vo, error_msg = loginfunc.checkLoginInfo(
                self)
            if is_select_ok == False:
                return
            # パスワード次回変更フラグをチェック
            if self.checkForcePasswordChange() == False:
                return

            # Requestからvoにセット
            req = UcfVoInfo.setRequestToVo(self)

            # ブラウザによる「employee_id」と「password」の自動セットを防止するため、「employee_id」が空の場合にダミーの空白をセットしておく(小細工... ここでクリア) 2015.09.01
            # 念のためTRIM
            #if req.get('employee_id', '') == '\t':
            #	req['employee_id'] = ''
            #if req.has_key('employee_id'):
            #	req['employee_id'] = req['employee_id'].strip()
            if req.has_key('federation_identifier'):
                req['federation_identifier'] = req[
                    'federation_identifier'].strip()

            # チェックボックス値補正(TODO 本来はフロントからPOSTするようにExtJsなどで処理すべきが取り急ぎ)
            OperatorUtils.setNotPostValue(self, req)

            # 新規 or 編集 or 削除
            edit_type = UcfUtil.getHashStr(req, UcfConfig.QSTRING_TYPE)
            # コピー新規
            edit_type2 = UcfUtil.getHashStr(req, UcfConfig.QSTRING_TYPE2)
            # ステータス
            edit_status = UcfUtil.getHashStr(req, UcfConfig.QSTRING_STATUS)
            # ユニークキー
            unique_id = UcfUtil.getHashStr(req, UcfConfig.QSTRING_UNIQUEID)
            if (edit_type == UcfConfig.EDIT_TYPE_RENEW
                    or edit_type == UcfConfig.EDIT_TYPE_DELETE or edit_type2
                    == UcfConfig.EDIT_TYPE_COPYNEWREGIST) and unique_id == '':
                self.redirectError(
                    UcfMessage.getMessage(self.getMsg('MSG_INVALID_ACCESS')))
                return

            ucfp = UcfTenantParameter(self)
            vo = {}
            entry_vo = {}
            if edit_status == UcfConfig.VC_CHECK:

                # CSRF対策:トークンチェック
                if not self.checkCSRFToken(
                        CSRF_TOKEN_KEY +
                    (unique_id if
                     edit_type2 != UcfConfig.EDIT_TYPE_COPYNEWREGIST else ''),
                        self.request.get(UcfConfig.REQUESTKEY_CSRF_TOKEN)):
                    self.redirectError(
                        UcfMessage.getMessage(self.getMsg('MSG_CSRF_CHECK')))
                    return

                # 削除処理の場合
                if edit_type == UcfConfig.EDIT_TYPE_DELETE:
                    entry = OperatorUtils.getData(self, unique_id)
                    if entry is None:
                        self.redirectError(
                            UcfMessage.getMessage(
                                self.getMsg('MSG_NOT_EXIST_DATA')))
                        return
                    entry_vo = entry.exchangeVo(self._timezone)  # 既存データをVoに変換
                    # 委託管理者の場合は自分がアクセスできる管理グループかをチェック
                    if self.isOperator(
                    ) and not ucffunc.isDelegateTargetManagementGroup(
                            UcfUtil.getHashStr(entry_vo, 'management_group'),
                            UcfUtil.csvToList(
                                self.getLoginOperatorDelegateManagementGroups(
                                ))):
                        self.redirectError(
                            UcfMessage.getMessage(
                                self.getMsg(
                                    'MSG_INVALID_ACCESS_BY_DELEGATE_MANAGEMENT_GROUPS'
                                )))
                        return

                    # このユーザを所属メンバーに持つグループからメンバーを削除
                    OperatorGroupUtils.removeOneMemberFromBelongGroups(
                        self, UcfUtil.getHashStr(entry_vo,
                                                 'operator_id_lower'))
                    ## このユーザを所属メンバーに持つ組織からメンバーを削除
                    #OrgUnitUtils.removeMemberFromBelongOrgUnits(self, [UcfUtil.getHashStr(entry_vo, 'operator_id_lower')], None)
                    # 削除(※トランザクションは制約やデメリットが多いので使用しない)
                    entry.delete()
                    ## ユーザー数キャッシュをクリア
                    #UCFMDLOperator.clearActiveUserAmountCache(tenant)
                    # オペレーションログ出力
                    UCFMDLOperationLog.addLog(
                        self.getLoginOperatorMailAddress(),
                        self.getLoginOperatorUniqueID(),
                        UcfConfig.SCREEN_OPERATOR,
                        UcfConfig.OPERATION_TYPE_REMOVE,
                        entry_vo.get('operator_id', ''),
                        entry_vo.get('unique_id',
                                     ''), self.getClientIPAddress(), '')
                    # 処理後一覧ページに遷移
                    # ダッシュボードに遷移に変更
                    #self.redirect('/a/' + self._tenant + '/operator/')
                    self.redirect('/a/' + self._tenant + '/')
                    return

                # 新規登録の場合
                elif edit_type == UcfConfig.EDIT_TYPE_NEW:
                    # RequestからVoを作成
                    UcfUtil.margeHash(vo, req)  # Requestからの情報をVoにマージ
                    # パスワード更新フラグによってパスワード上書きするかどうかの制御
                    if UcfUtil.getHashStr(vo,
                                          'PasswordUpdateFlag') != 'UPDATE':
                        vo['password'] = ''
                    #if UcfUtil.getHashStr(vo, 'Password1UpdateFlag') != 'UPDATE':
                    #	vo['password1'] = ''
                    #if UcfUtil.getHashStr(vo, 'MatrixAuthPinCodeUpdateFlag') != 'UPDATE':
                    #	vo['matrixauth_pin_code'] = ''

                # 編集の場合
                elif edit_type == UcfConfig.EDIT_TYPE_RENEW:
                    entry = OperatorUtils.getData(self, unique_id)
                    if entry is None:
                        self.redirectError(
                            UcfMessage.getMessage(
                                self.getMsg('MSG_NOT_EXIST_DATA')))
                        return

                    entry_vo = entry.exchangeVo(self._timezone)  # 既存データをVoに変換
                    OperatorUtils.editVoForSelect(
                        self, entry_vo,
                        is_with_parent_group_info=True)  # データ加工(取得用)
                    UcfUtil.margeHash(vo, entry_vo)  # 既存データをVoにコピー
                    UcfUtil.margeHash(vo, req)  # Requestからの情報をVoにマージ
                    # パスワード更新フラグによってパスワード上書きするかどうかの制御
                    if UcfUtil.getHashStr(vo,
                                          'PasswordUpdateFlag') != 'UPDATE':
                        vo['password'] = entry_vo['password']
                    #if UcfUtil.getHashStr(vo, 'Password1UpdateFlag') != 'UPDATE':
                    #	vo['password1'] = entry_vo['password1']
                    #if UcfUtil.getHashStr(vo, 'MatrixAuthPinCodeUpdateFlag') != 'UPDATE':
                    #	vo['matrixauth_pin_code'] = entry_vo['matrixauth_pin_code']

                else:
                    # エラーページに遷移
                    self.redirectError(
                        UcfMessage.getMessage(
                            self.getMsg('MSG_INVALID_ACCESS')))
                    return

                # 入力チェック
                vc = OperatorValidator(
                    edit_type,
                    self.isOperator()
                    and self.getLoginOperatorDelegateManagementGroups() != '',
                    self.getLoginOperatorDelegateManagementGroups().split(',')
                    if self.getLoginOperatorDelegateManagementGroups() != ''
                    else None)
                # AD連携パスワード桁数制御撤廃対応:一環でパスワード更新時以外はパスワードチェックしないように対応 2017.03.17
                is_without_password_check = UcfUtil.getHashStr(
                    vo, 'PasswordUpdateFlag') != 'UPDATE'
                vc.validate(
                    self,
                    vo,
                    self.getLoginOperatorMailAddress(),
                    is_without_password_check=is_without_password_check)
                ucfp.voinfo.validator = vc
                # 入力エラーがなければ登録処理
                if ucfp.voinfo.validator.total_count <= 0:

                    # 更新日時チェック(編集時のみ)
                    if edit_type == UcfConfig.EDIT_TYPE_RENEW and not self.checkDateChanged(
                            entry):
                        # エラーページに遷移
                        self.redirectError(
                            UcfMessage.getMessage(
                                self.getMsg('MSG_ALREADY_UPDATED_DATA')))
                        return

                    # オペレーションログ詳細用に更新フィールドを取得(加工前に比較しておく)
                    if edit_type == UcfConfig.EDIT_TYPE_NEW:
                        is_diff = True
                        diff_for_operation_log = []
                    else:
                        is_diff, diff_for_operation_log = OperatorUtils.isDiff(
                            self, vo, entry_vo)

                    # 加工データ
                    OperatorUtils.editVoForRegist(self, vo, entry_vo,
                                                  edit_type)

                    # 新規登録場合モデルを新規作成
                    if edit_type == UcfConfig.EDIT_TYPE_NEW:
                        unique_id = UcfUtil.guid()
                        vo['unique_id'] = unique_id
                        entry = UCFMDLOperator(unique_id=unique_id,
                                               id=OperatorUtils.getKey(
                                                   self, vo))

                    # Voからモデルにマージ
                    entry.margeFromVo(vo, self._timezone)

                    # 更新日時、更新者の更新
                    entry.updater_name = UcfUtil.nvl(self.getLoginID())
                    entry.date_changed = UcfUtil.getNow()

                    # 新規登録場合ユニークIDを生成
                    if edit_type == UcfConfig.EDIT_TYPE_NEW:
                        # 作成日時、作成者の更新
                        entry.creator_name = UcfUtil.nvl(self.getLoginID())
                        entry.date_created = UcfUtil.getNow()

                    ########################
                    # 親グループ
                    parent_groups = []
                    parent_group_info = OperatorUtils.getParentGroupInfoFromRequest(
                        vo)
                    if parent_group_info is not None:
                        for member in parent_group_info:
                            parent_groups.append(
                                UcfUtil.getHashStr(member,
                                                   'MailAddress').lower())

                    # 親グループ情報を更新
                    add_groups, del_groups = OperatorGroupUtils.setOneUserToBelongGroups(
                        self, UcfUtil.getHashStr(vo, 'operator_id_lower'),
                        parent_groups)
                    # 更新処理(※トランザクションは制約やデメリットが多いので使用しない)
                    entry.put()
                    # UserEntryにレコード追加
                    sateraito_func.addUpdateUserEntryTaskQueue(tenant, entry)
                    ## ユーザー数キャッシュをクリア
                    #if edit_type == UcfConfig.EDIT_TYPE_NEW:
                    #	UCFMDLOperator.clearActiveUserAmountCache(tenant)

                    # オペレーションログ出力
                    operation_log_detail = {}
                    if edit_type == UcfConfig.EDIT_TYPE_RENEW:
                        operation_log_detail['fields'] = diff_for_operation_log
                    operation_log_detail['add_groups'] = add_groups
                    if edit_type == UcfConfig.EDIT_TYPE_RENEW:
                        operation_log_detail['del_groups'] = del_groups
                    UCFMDLOperationLog.addLog(
                        self.getLoginOperatorMailAddress(),
                        self.getLoginOperatorUniqueID(),
                        UcfConfig.SCREEN_OPERATOR, UcfConfig.OPERATION_TYPE_ADD
                        if edit_type == UcfConfig.EDIT_TYPE_NEW else
                        UcfConfig.OPERATION_TYPE_MODIFY,
                        vo.get('operator_id', ''), vo.get('unique_id', ''),
                        self.getClientIPAddress(),
                        JSONEncoder().encode(operation_log_detail))

                    # 処理後一覧ページに遷移
                    # ダッシュボードに遷移に変更
                    #self.redirect('/a/' + self._tenant + '/operator/')
                    self.redirect('/a/' + self._tenant + '/')
                    return

                # 入力エラーがあれば画面に戻る
                else:

                    for k, v in vc.msg.iteritems():
                        logging.info(k)
                        logging.info(v)

                    ucfp.voinfo.setVo(vo, OperatorViewHelper(), None, self)

            # 初回表示
            else:
                # コピー新規
                if edit_type2 == UcfConfig.EDIT_TYPE_COPYNEWREGIST:
                    entry = OperatorUtils.getData(self, unique_id)
                    if entry is None:
                        self.redirectError(
                            UcfMessage.getMessage(
                                self.getMsg('MSG_NOT_EXIST_DATA')))
                        return

                    vo = entry.exchangeVo(self._timezone)  # 既存データをVoに変換
                    OperatorUtils.editVoForSelect(
                        self, vo, is_with_parent_group_info=True)  # データ加工(取得用)

                    # コピー新規なので不要なデータを削除
                    OperatorUtils.removeFromVoForCopyRegist(self, vo)

                    ucfp.voinfo.setVo(vo, None, None, self)

                else:
                    # 新規
                    if edit_type == UcfConfig.EDIT_TYPE_NEW:
                        OperatorUtils.editVoForDefault(self, vo)  # データ加工(初期値用)
                    # 編集
                    elif edit_type == UcfConfig.EDIT_TYPE_RENEW:
                        entry = OperatorUtils.getData(self, unique_id)
                        if entry is None:
                            self.redirectError(
                                UcfMessage.getMessage(
                                    self.getMsg('MSG_NOT_EXIST_DATA')))
                            return

                        vo = entry.exchangeVo(self._timezone)  # 既存データをVoに変換
                        OperatorUtils.editVoForSelect(
                            self, vo,
                            is_with_parent_group_info=True)  # データ加工(取得用)

                        # 委託管理者の場合は自分がアクセスできる管理グループかをチェック
                        if self.isOperator(
                        ) and not ucffunc.isDelegateTargetManagementGroup(
                                UcfUtil.getHashStr(vo, 'management_group'),
                                UcfUtil.csvToList(
                                    self.
                                    getLoginOperatorDelegateManagementGroups())
                        ):
                            self.redirectError(
                                UcfMessage.getMessage(
                                    self.getMsg(
                                        'MSG_INVALID_ACCESS_BY_DELEGATE_MANAGEMENT_GROUPS'
                                    )))
                            return

                    else:
                        # エラーページに遷移
                        self.redirectError(
                            UcfMessage.getMessage(
                                self.getMsg('MSG_INVALID_ACCESS')))
                        return

                    ucfp.voinfo.setVo(vo, None, None, self)

            # ブラウザによる「employee_id」と「password」の自動セットを防止するため、「employee_id」が空の場合にダミーの空白をセットしておく(小細工... ↑とFocus時にクリア) 2015.09.01
            #if vo is not None and vo.get('employee_id', '') == '':
            #	vo['employee_id'] = '\t'
            #if vo is not None and vo.get('federation_identifier', '') == '':
            #	vo['federation_identifier'] = '\t'
            # CSRF対策:トークン発行
            ucfp.data['token'] = self.createCSRFToken(CSRF_TOKEN_KEY + (
                unique_id
                if edit_type2 != UcfConfig.EDIT_TYPE_COPYNEWREGIST else ''))

            ucfp.data['gnaviid'] = _gnaviid
            ucfp.data['leftmenuid'] = _leftmenuid
            ucfp.data['explains'] = [self.getMsg('EXPLAIN_OPERATOR_HEADER')]
            ucfp.data[UcfConfig.QSTRING_TYPE] = UcfUtil.nvl(
                self.getRequest(UcfConfig.QSTRING_TYPE))

            # マルチドメイン時のドメインリストを作成
            #domain_list = []
            #domain_list.extend(UcfUtil.csvToList(UcfUtil.getHashStr(self.getDeptInfo(), 'federated_domains')))
            #domain_list = sateraito_func.getFederatedDomainList(self._tenant, is_with_cache=True)

            # 言語一覧
            language_list = []
            for language in sateraito_func.ACTIVE_LANGUAGES:
                language_list.append([
                    language,
                    self.getMsg(
                        sateraito_func.LANGUAGES_MSGID.get(language, ''))
                ])

            template_vals = {
                'ucfp':
                ucfp,
                'vcmsg':
                ucfp.voinfo.validator.msg
                if ucfp.voinfo.validator != None else {},
                'is_exist_delegate_management_groups':
                True if len(
                    UcfUtil.csvToList(
                        self.getLoginOperatorDelegateManagementGroups())) > 0
                else False,
                #'is_multidomain':True if len(domain_list) > 1 else False,
                #'domain_list':JSONEncoder().encode(domain_list),
                'language_list':
                JSONEncoder().encode(language_list)
            }
            self.appendBasicInfoToTemplateVals(template_vals)

            self.render('operator_regist.html', self._design_type,
                        template_vals)
        except BaseException, e:
            self.outputErrorLog(e)
            self.redirectError(
                UcfMessage.getMessage(self.getMsg('MSG_SYSTEM_ERROR'), ()))
            return
示例#12
0

# Override default JSONEncoder/JSONDecoder classes in jsonutil to handle
# dates:
def _extended_json_encoding(obj):
    if isinstance(obj, DateTime):
        return {'<datetime>': True, 'datetime': obj.ISO()}
    return json.dumps(obj)


json._default_encoder = JSONEncoder(
    skipkeys=False,
    ensure_ascii=True,
    check_circular=True,
    allow_nan=True,
    indent=None,
    separators=None,
    encoding='utf-8',
    default=_extended_json_encoding,
    use_decimal=True,
)


def _extended_json_decoding(dct):
    if '<datetime>' in dct:
        # 2013-10-18T20:35:18+07:00
        return StringToDate(dct['datetime'], format=None)
    return dct


json._default_decoder = JSONDecoder(encoding=None,
示例#13
0
    def processOfRequest(self, tenant):

        CSRF_TOKEN_KEY = 'operator_changeid'

        try:
            ret_value = {}
            if self.isValidTenant(not_redirect=True) == False:
                self._code = 400
                self._msg = self.getMsg('MSG_NOT_INSTALLED', (self._tenant))
                self.responseAjaxResult()
                return

            if loginfunc.checkLogin(self, not_redirect=True) == False:
                self._code = 403
                self._msg = self.getMsg('MSG_NOT_LOGINED')
                self.responseAjaxResult()
                return

            # ログイン時の各種情報を取得&チェック
            is_select_ok, user_vo, profile_vo, error_msg = loginfunc.checkLoginInfo(
                self, not_redirect=True)
            if is_select_ok == False:
                self._code = 403
                self._msg = error_msg
                self.responseAjaxResult()
                return

            if self.isAdmin() == False and self.isOperator(
                    target_function=UcfConfig.DELEGATE_FUNCTION_OPERATOR_CONFIG
            ) == False:
                self._code = 403
                self._msg = self.getMsg('MSG_INVALID_ACCESS_AUTHORITY')
                self.responseAjaxResult()
                return

            # Requestからvoにセット
            req = UcfVoInfo.setRequestToVo(self)

            # ユニークキー
            unique_id = UcfUtil.getHashStr(req, UcfConfig.QSTRING_UNIQUEID)
            if unique_id == '':
                self._code = 403
                self._msg = self.getMsg('MSG_INVALID_ACCESS')
                self.responseAjaxResult(ret_value)
                return
            logging.info('unique_id=' + unique_id)

            # CSRF対策:トークンチェック
            if not self.checkCSRFToken(
                    CSRF_TOKEN_KEY + unique_id,
                    self.request.get(UcfConfig.REQUESTKEY_CSRF_TOKEN)):
                self._code = 400
                self._msg = self.getMsg('MSG_CSRF_CHECK')
                self.responseAjaxResult()
                return

            # 入力チェック
            vc = OperatorChangeIDValidator()
            vc.validate(self, req)
            # 入力エラーがあれば終了
            if vc.total_count > 0:
                self._code = 100
                ret_value['vcmsg'] = vc.msg
                self.responseAjaxResult(ret_value)
                return

            # 入力エラーがなければ登録処理
            else:

                entry = OperatorUtils.getData(self, unique_id)
                if entry is None:
                    self._code = 400
                    self._msg = UcfMessage.getMessage(
                        self.getMsg('MSG_NOT_EXIST_DATA'))
                    self.responseAjaxResult(ret_value)
                    return

                src_email = UcfUtil.getHashStr(req, 'src_accountid')
                #dst_email = UcfUtil.getHashStr(req, 'dst_accountid_localpart') + '@' + UcfUtil.getHashStr(req, 'federated_domain')
                dst_email = UcfUtil.getHashStr(req, 'dst_accountid')
                logging.info('src_email=' + src_email)
                logging.info('dst_email=' + dst_email)
                # 1アカウントの情報を更新
                result_code, result_msg, result_vcmsg, vo = OperatorUtils.changeOneOperatorID(
                    self,
                    src_email,
                    dst_email,
                    entry,
                    self.isOperator(),
                    UcfUtil.csvToList(
                        self.getLoginOperatorDelegateManagementGroups()),
                    login_operator_id=UcfUtil.nvl(self.getLoginID()))
                if result_code != 0:
                    self._code = result_code
                    self._msg = result_msg
                    ret_value['vcmsg'] = result_vcmsg
                    self.responseAjaxResult(ret_value)
                    return

                # オペレーションログ出力
                operation_log_detail = {}
                operation_log_detail['fields'] = [{
                    'key': 'email',
                    'before': src_email,
                    'after': dst_email
                }]
                UCFMDLOperationLog.addLog(
                    self.getLoginOperatorMailAddress(),
                    self.getLoginOperatorUniqueID(), UcfConfig.SCREEN_OPERATOR,
                    UcfConfig.OPERATION_TYPE_CHANGEID,
                    vo.get('operator_id', ''), vo.get('unique_id', ''),
                    self.getClientIPAddress(),
                    JSONEncoder().encode(operation_log_detail))

                self._code = result_code
                self.responseAjaxResult()

        except BaseException, e:
            self.outputErrorLog(e)
            self._code = 999
            self.responseAjaxResult()
示例#14
0
def SRP_Auth_1(req, data):
    """
	Primer paso del protocolo para el servidor
	Recibe diccionario con :
	username: String con el username
	A: Bigint string -> A = g ^a donde a es un bigint al azar
	"""
    try:
        session = req.session
        session.lock()
        if session.has_key("logged"):
            if session["logged"]:
                rdata = {
                    "status": "Already logged in."
                }
                req.write(JSONEncoder("UTF-8").encode(rdata))
                return
        session.unlock()

        data = JSONDecoder("UTF-8").decode(data)

        ## recogemos A
        A = hex2dec(data["A"])

        ## Abortar si A%N == 0
        if (A % N == 0):
            rdata = {
                "status": "Server step 1 failed."
            }
            req.write(JSONEncoder("UTF-8").encode(rdata))

        ## Conectar
        db = MySQLdb.connect(host="localhost",
                             user="******",
                             passwd="1234",
                             db="prueba")

        ## Preparar transaccion
        sql = """
		SELECT * 
		FROM usuarios 
		WHERE userName = "******" 
		""" % (data['username'])

        cursor = db.cursor()
        cursor.execute(sql)
        resultado = cursor.fetchall()

        ## Desconectar
        db.close()

        user_id = None
        ## Asegurarse que no hay mas de un resultado
        if len(resultado) > 1:
            rdata = {
                "status": "Server step 1 failed: Duplicated username!."
            }
            req.write(JSONEncoder("UTF-8").encode(rdata))
            return
        else:
            if len(resultado) == 0:
                rdata = {
                    "status": "No existe el usuario."
                }
                req.write(JSONEncoder("UTF-8").encode(rdata))
                return
            else:
                user_id = resultado[0][0]

        ## Devuelve el salt (2a columna) y B
        ## k = H(N, g)
        ## Si se ha de calcular k, lo podemos hacer aqui
        dbsalt = resultado[0][3]
        dbv = resultado[0][2]
        v = hex2dec(dbv)
        salt = hex2dec(dbsalt)

        ## b es un numero al azar de como maximo 32 bytes
        random.seed()
        b = random.getrandbits(256)

        ## B=	kv + g^b   (mod N)
        kv = k * v
        gb = powMod(g, b, N)
        B = (kv + gb) % N

        rdata = {
            "salt": dbsalt.upper(),
            "B": dec2hex(B).upper(),
            "status": "OK"
        }
        req.write(JSONEncoder("UTF-8").encode(rdata))

        ## Create crypto data structure
        cryptovars = {
            "A": A,
            "B": B,
            "v": v,
            "b": b,
            "user": data['username'],
            "salt": dbsalt.upper(),
            "user_id": user_id
        }
        save_crypto_vars(req, cryptovars)

    except:
        rdata = {
            "status": "Server step 1 failed."
        }
        req.write(JSONEncoder("UTF-8").encode(rdata))
示例#15
0
def SRP_Auth_2(req, data):
    """
	Acaba de hacer los calculos de la clave de sesion y hace la comprobacion de la 
	clave de sesion que envia el usuario (segun el protocolo el usuario ha de ser el 
	primero en enviar, si no corresponden abortar).
	"""

    #~ try:
    ## Recuperar K
    data = JSONDecoder("UTF-8").decode(data)
    Mc = data["M"]

    ## Recuperar las variables de la sesion
    cryptovars = retrieve_crypto_vars(req)

    B = cryptovars["B"]
    v = cryptovars["v"]
    b = cryptovars["b"]
    A = cryptovars["A"]
    user = cryptovars["user"].upper()
    salt = cryptovars["salt"].upper()

    ## u = H(A, B)
    u = calc_u(A, B, N)
    u = hex2dec(hash(dec2hex(A) + dec2hex(B)))

    ## S = (Av^u) ^ b
    S = powMod(A * powMod(v, u, N), b, N)

    ## Clave de sesion  K = H(S)
    K = hash(dec2hex(S).upper()).upper()

    ## Comprobar que la prueba del cliente es igual a lo que tenemos nosotros
    ## M = H(H(N) xor H(g), H(I), s, A, B, K)
    HN = hex2dec(hash(dec2hex(N)))
    Hg = hex2dec(hash(dec2hex(g)))
    HI = hash(user).upper()
    innerhash = dec2hex(
        (HN ^ Hg)).upper() + HI + salt + dec2hex(A) + dec2hex(B) + K
    Mc_s = hash(innerhash).upper()

    ## si no coincide lo que calculamos nosotros con lo que nos envian... nanay
    if (Mc != Mc_s):
        rdata = {
            "status": "FAILED"
        }
        req.write(JSONEncoder("UTF-8").encode(rdata))
    else:
        ## Si son iguales enviamos nuestra prueba al cliente

        ## Generar la prueba del servidor
        Ms = hash(dec2hex(A) + Mc + K)

        ## Hacer efectivo el login en el servidor y emitir cookie si es necesario
        session_login(req)

        if (data["remember"] == "yes"):
            message = createLoginCookie(req, req.session['SRP_crypto']['user'])
            if message != "OK":
                rdata = {
                    "status": message
                }

        ## Guardar la clave de sesion y proceder a la comprobacion por parte del cliente
        rdata = {
            "M": Ms.upper(),
            "status": "OK"
        }
        req.write(JSONEncoder("UTF-8").encode(rdata))

    #~ except:
    #~ rdata = {"status": "Second auth step failed."};
    #~ req.write(JSONEncoder("UTF-8").encode(rdata))

    ## Todo completado, eliminar la info de la variable de sesion
    delete_crypto_vars(req)
示例#16
0
__author__ = 'zwei'

from simplejson.encoder import JSONEncoder

encoder = JSONEncoder(for_json=True)


def encodeList():
    lst = [i for i in range(1000)]
    return encoder.encode(lst)


def encodeObject():
    class Foo:
        def for_json(self):
            return {'a': 1, 'b': 2, 'c': [i for i in range(1000)]}

    return encoder.encode(Foo())


json = encodeList()
print(json)
json = encodeObject()
print(json)
示例#17
0
    def importOneRecordGroup(self, csv_record, record_cnt, blob_key, data_key,
                             data_kind, login_operator_unique_id,
                             login_operator_id, login_operator_mail_address,
                             login_operator_client_ip, login_operator_entry):

        titles = GroupUtils.getCsvTitles(self)

        code = ''
        row_log_msg = []
        entry_vo = None
        current_belong_members = []  # 編集時に使用。編集前の所属メンバー(今回解除されたメンバーの判定に使用する)
        deal_type = ''
        edit_type = ''

        try:

            # CSVチェック
            vc = GroupCsvValidator()
            vc.validate(self, csv_record)
            # 入力エラーがあれば
            if vc.total_count > 0:
                code = '100'
                for title in titles:
                    if vc.msg.has_key(title):
                        #row_log_msg.extend(vc.msg[title])
                        row_log_msg.extend(
                            ['[' + title + ']' + msg for msg in vc.msg[title]])

            if code == '':
                command = UcfUtil.getHashStr(csv_record, 'command')
                # セールスフォースではグループIDとメールアドレスは別 2015.12.18
                #email = UcfUtil.getHashStr(csv_record, 'email')
                group_id = UcfUtil.getHashStr(csv_record, 'group_id')

                q = sateraito_db.Group.query()
                q = q.filter(
                    sateraito_db.Group.group_id_lower == group_id.lower())
                key = q.get(keys_only=True)
                entry = key.get() if key is not None else None
                # 委託管理者の場合は自分がアクセスできるカテゴリかをチェック
                if entry is not None and ucffunc.isDelegateOperator(
                        login_operator_entry
                ) and not ucffunc.isDelegateTargetManagementGroup(
                        entry.management_group,
                        login_operator_entry.delegate_management_groups
                        if login_operator_entry is not None else None):
                    code = '400'
                    row_log_msg.append(
                        UcfMessage.getMessage(
                            self.getMsg(
                                'MSG_INVALID_ACCESS_BY_DELEGATE_MANAGEMENT_GROUPS'
                            )))
                else:
                    vo = {}
                    # 削除処理の場合
                    if command == 'D':
                        if entry is None:
                            code = '400'
                            row_log_msg.append(
                                self._formatLogRecord(
                                    UcfMessage.getMessage(
                                        self.getMsg('MSG_NOT_EXIST_DATA'))))
                        else:
                            edit_type = UcfConfig.EDIT_TYPE_DELETE
                            entry_vo = entry.exchangeVo(
                                self._timezone)  # 既存データをVoに変換

                    # 新規登録の場合
                    elif command == 'I':
                        if entry is not None:
                            code = '400'
                            row_log_msg.append(
                                self._formatLogRecord(
                                    UcfMessage.getMessage(
                                        self.getMsg('MSG_VC_ALREADY_EXIST'))))
                        else:
                            edit_type = UcfConfig.EDIT_TYPE_NEW
                            GroupUtils.editVoForDefault(self, vo)
                            # csv_dataからマージ
                            GroupUtils.margeVoFromCsvRecord(
                                self, vo, csv_record, login_operator_entry)
                            GroupUtils.editVoForSelectCsvImport(
                                self, vo)  # データ加工(取得用)

                    # 編集の場合
                    elif command == 'U':
                        if entry is None:
                            code = '400'
                            row_log_msg.append(
                                self._formatLogRecord(
                                    UcfMessage.getMessage(
                                        self.getMsg('MSG_NOT_EXIST_DATA'))))
                        else:
                            edit_type = UcfConfig.EDIT_TYPE_RENEW
                            entry_vo = entry.exchangeVo(
                                self._timezone)  # 既存データをVoに変換
                            GroupUtils.editVoForSelect(
                                self,
                                entry_vo,
                                is_with_parent_group_info=False,
                                is_with_belong_member_info=False)  # データ加工(取得用)
                            UcfUtil.margeHash(vo, entry_vo)  # 既存データをVoにコピー
                            # csv_dataからマージ
                            GroupUtils.margeVoFromCsvRecord(
                                self, vo, csv_record, login_operator_entry)
                            GroupUtils.editVoForSelectCsvImport(
                                self, vo)  # データ加工(取得用)

                            current_belong_members = UcfUtil.csvToList(
                                UcfUtil.getHashStr(entry_vo, 'belong_members'))

                    # 新規 or 編集の場合
                    elif command == 'IU':
                        if entry is not None:
                            edit_type = UcfConfig.EDIT_TYPE_RENEW
                            entry_vo = entry.exchangeVo(
                                self._timezone)  # 既存データをVoに変換
                            GroupUtils.editVoForSelect(
                                self,
                                entry_vo,
                                is_with_parent_group_info=False,
                                is_with_belong_member_info=False)  # データ加工(取得用)
                            UcfUtil.margeHash(vo, entry_vo)  # 既存データをVoにコピー
                        else:
                            edit_type = UcfConfig.EDIT_TYPE_NEW
                        # csv_dataからマージ
                        GroupUtils.margeVoFromCsvRecord(
                            self, vo, csv_record, login_operator_entry)
                        GroupUtils.editVoForSelectCsvImport(self,
                                                            vo)  # データ加工(取得用)

                    ########################
                    # 削除
                    if edit_type == UcfConfig.EDIT_TYPE_DELETE:
                        # トップグループなら子グループをトップに昇格
                        if UcfUtil.getHashStr(entry_vo,
                                              'top_group_flag') == 'TOP':
                            GroupUtils.updateBelongMembersTopGroupFlag(
                                self,
                                UcfUtil.getHashStr(entry_vo, 'group_id_lower'),
                                UcfUtil.csvToList(entry_vo['belong_members']),
                                'SET',
                                operator_id=login_operator_id)
                        # このグループをメイン組織に設定しているユーザのメイン組織をクリア
                        OperatorUtils.removeUsersTargetMainGroup(
                            self,
                            UcfUtil.getHashStr(entry_vo, 'group_id_lower'),
                            operator_id=login_operator_id)
                        # このグループをメイン組織に設定しているグループのメイン組織をクリア
                        GroupUtils.removeGroupsTargetMainGroup(
                            self,
                            UcfUtil.getHashStr(entry_vo, 'group_id_lower'),
                            operator_id=login_operator_id)
                        # このグループを所属メンバーとして持っている親グループからメンバーとして解除 2016.10.24
                        GroupUtils.removeOneMemberFromBelongGroups(
                            self,
                            UcfUtil.getHashStr(entry_vo, 'group_id_lower'),
                            operator_id=login_operator_id)
                        # このグループ自体を削除
                        entry.key.delete()
                        # オペレーションログ出力
                        UCFMDLOperationLog.addLog(
                            login_operator_mail_address,
                            login_operator_unique_id,
                            UcfConfig.SCREEN_GROUP,
                            UcfConfig.OPERATION_TYPE_REMOVE,
                            entry_vo.get('group_id', ''),
                            entry_vo.get('unique_id', ''),
                            login_operator_client_ip,
                            '',
                            is_async=True)
                        deal_type = edit_type

                    # 更新、新規
                    elif edit_type == UcfConfig.EDIT_TYPE_NEW or edit_type == UcfConfig.EDIT_TYPE_RENEW:

                        # 入力チェック
                        vc = GroupValidator(
                            edit_type,
                            ucffunc.isDelegateOperator(login_operator_entry),
                            login_operator_entry.delegate_management_groups
                            if login_operator_entry is not None else None)
                        vc.validate(self, vo)

                        # 入力エラーがなければ登録処理
                        if vc.total_count <= 0:

                            # オペレーションログ詳細用に更新フィールドを取得(加工前に比較しておく)
                            if edit_type == UcfConfig.EDIT_TYPE_NEW:
                                is_diff = True
                                diff_for_operation_log = []
                            else:
                                is_diff, diff_for_operation_log = GroupUtils.isDiff(
                                    self, vo, entry_vo)
                            # 差分があるかを判定
                            is_skip = not is_diff

                            # 加工データ
                            GroupUtils.editVoForRegist(self, vo, entry_vo,
                                                       edit_type)
                            # 新規登録場合モデルを新規作成
                            if edit_type == UcfConfig.EDIT_TYPE_NEW:
                                unique_id = UcfUtil.guid()
                                vo['unique_id'] = unique_id
                                entry = sateraito_db.Group(
                                    unique_id=unique_id,
                                    id=GroupUtils.getKey(self, vo))

                            #logging.info('vo=' + str(vo))
                            # Voからモデルにマージ
                            #logging.info(vo)
                            entry.margeFromVo(vo, self._timezone)
                            # 更新日時、更新者の更新
                            entry.updater_name = login_operator_id
                            entry.date_changed = UcfUtil.getNow()

                            # 新規登録場合ユニークIDを生成
                            if edit_type == UcfConfig.EDIT_TYPE_NEW:
                                # 作成日時、作成者の更新
                                entry.creator_name = login_operator_id
                                entry.date_created = UcfUtil.getNow()

                            belong_members = UcfUtil.csvToList(
                                vo['belong_members'])
                            release_members = []  # 今回の変更で所属メンバーから解除されたメンバー
                            for current_belong_member in current_belong_members:
                                if current_belong_member not in belong_members:
                                    release_members.append(
                                        current_belong_member)

                            # 子グループのトップフラグを更新
                            GroupUtils.updateBelongMembersTopGroupFlag(
                                self,
                                UcfUtil.getHashStr(vo, 'group_id'),
                                belong_members,
                                'REMOVE',
                                operator_id=login_operator_id)
                            # 今回このグループからメンバー解除されたグループのトップフラグ更新
                            GroupUtils.updateBelongMembersTopGroupFlag(
                                self,
                                UcfUtil.getHashStr(vo, 'group_id'),
                                release_members,
                                'SET',
                                operator_id=login_operator_id)

                            # 登録、更新処理(※トランザクションは制約やデメリットが多いので使用しない)
                            if not is_skip:
                                entry.put()

                                # オペレーションログ出力
                                operation_log_detail = {}
                                if edit_type == UcfConfig.EDIT_TYPE_RENEW:
                                    operation_log_detail[
                                        'fields'] = diff_for_operation_log
                                UCFMDLOperationLog.addLog(
                                    login_operator_mail_address,
                                    login_operator_unique_id,
                                    UcfConfig.SCREEN_GROUP,
                                    UcfConfig.OPERATION_TYPE_ADD
                                    if edit_type == UcfConfig.EDIT_TYPE_NEW
                                    else UcfConfig.OPERATION_TYPE_MODIFY,
                                    vo.get('group_id', ''),
                                    vo.get('unique_id', ''),
                                    login_operator_client_ip,
                                    JSONEncoder().encode(operation_log_detail),
                                    is_async=True)

                                deal_type = edit_type
                            else:
                                deal_type = UcfConfig.EDIT_TYPE_SKIP

                        # 入力エラーがあれば
                        else:
                            code = '100'
                            for key, value in vc.msg.iteritems():
                                #row_log_msg.extend(value)
                                row_log_msg.extend(
                                    ['[' + key + ']' + msg for msg in value])

        except BaseException, e:
            self.outputErrorLog(e)
            code = '500'
            row_log_msg.append(self._formatLogRecord('system error.'))
]

if __name__ == '__main__':
    import warnings
    warnings.warn('python -msimplejson is deprecated, use python -msiplejson.tool', DeprecationWarning)
    from simplejson.decoder import JSONDecoder
    from simplejson.encoder import JSONEncoder
else:
    from decoder import JSONDecoder
    from encoder import JSONEncoder

_default_encoder = JSONEncoder(
    skipkeys=False,
    ensure_ascii=True,
    check_circular=True,
    allow_nan=True,
    indent=None,
    separators=None,
    encoding='utf-8',
    default=None,
)

def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
        allow_nan=True, cls=None, indent=None, separators=None,
        encoding='utf-8', default=None, **kw):
    """
    Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
    ``.write()``-supporting file-like object).

    If ``skipkeys`` is ``True`` then ``dict`` keys that are not basic types
    (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
    will be skipped instead of raising a ``TypeError``.
示例#19
0
 def default(self, o):
     if isinstance(o, Packet) or hasattr(o, 'serialized'):
         return o.serialized
         
     return JSONEncoder.default(self, o)