Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Name | Version | Description |
---|---|---|
Ming Ke Ming (名可名) | Decentralized User Identity Authentication | |
Dao Ke Dao (道可道) | Universal Message Module | |
DIMP (去中心化通讯协议) | Decentralized Instant Messaging Protocol |
extends CustomizedContent
from abc import ABC, abstractmethod
from typing import Optional, List
from dimsdk import ID
from dimsdk import ReliableMessage
from dimsdk import Content
from dimsdk.cpu import BaseContentProcessor
from ...common import CustomizedContent
class CustomizedContentHandler(ABC):
"""
Handler for Customized Content
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
@abstractmethod
async def handle_action(self, act: str, sender: ID,
content: CustomizedContent, msg: ReliableMessage) -> List[Content]:
"""
Do your job
@param act: action
@param sender: user ID
@param content: customized content
@param msg: network message
@return contents
"""
raise NotImplemented
class CustomizedContentProcessor(BaseContentProcessor, CustomizedContentHandler):
"""
Customized Content Processing Unit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
# Override
async def process_content(self, content: Content, r_msg: ReliableMessage) -> List[Content]:
assert isinstance(content, CustomizedContent), 'customized content error: %s' % content
# 1. check app id
app = content.application
responses = self._filter(app, content=content, msg=r_msg)
if responses is not None:
# app id not found
return responses
# 2. get handler with module name
mod = content.module
handler = self._fetch(mod, content=content, msg=r_msg)
if handler is None:
# module not support
return []
# 3. do the job
act = content.action
sender = r_msg.sender
return await handler.handle_action(act, sender=sender, content=content, msg=r_msg)
def _filter(self, app: str, content: CustomizedContent, msg: ReliableMessage) -> Optional[List[Content]]:
# Override for your application
"""
Check for application
:param app: app ID
:param content: customized content
:param msg: received message
:return: None on app ID matched
"""
text = 'Content not support.'
return self._respond_receipt(text=text, content=content, envelope=msg.envelope, extra={
'template': 'Customized content (app: ${app}) not support yet!',
'replacements': {
'app': app,
}
})
def _fetch(self, mod: str, content: CustomizedContent, msg: ReliableMessage) -> Optional[CustomizedContentHandler]:
""" Override for you module """
# if the application has too many modules, I suggest you to
# use different handler to do the job for each module.
return self
# Override
async def handle_action(self, act: str, sender: ID,
content: CustomizedContent, msg: ReliableMessage) -> List[Content]:
""" Override for customized actions """
app = content.application
mod = content.module
text = 'Content not support.'
return self._respond_receipt(text=text, content=content, envelope=msg.envelope, extra={
'template': 'Customized content (app: ${app}, mod: ${mod}, act: ${act}) not support yet!',
'replacements': {
'app': app,
'mod': mod,
'act': act,
}
})
from dimsdk import ContentType
from dimsdk.plugins import ExtensionLoader
from ..protocol import HandshakeCommand
from ..protocol import AppCustomizedContent
class CommonLoader(ExtensionLoader):
def _register_customized_factories(self):
# Application Customized
self._set_content_factory(msg_type=ContentType.APPLICATION, content_class=AppCustomizedContent)
self._set_content_factory(msg_type=ContentType.CUSTOMIZED, content_class=AppCustomizedContent)
# Override
def _register_content_factories(self):
super()._register_content_factories()
self._register_customized_factories()
# Override
def _register_command_factories(self):
super()._register_command_factories()
# Handshake
self._set_command_factory(cmd=HandshakeCommand.HANDSHAKE, command_class=HandshakeCommand)
You must load all extensions before your business run:
from ..common import CommonLoader
if __name__ == '__main__':
loader = CommonLoader()
loader.run()
# do your jobs after all extensions loaded.
Also, to let your CustomizedContentProcessor start to work,
you must override BaseContentProcessorCreator
for message types:
and then set your creator for GeneralContentProcessorFactory
in the MessageProcessor
.
FAQs
Decentralized Instant Messaging SDK
We found that dimsdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.