valar for morghulis
Project description
valar for morghulis
settings
from pathlib import Path
""" Compulsory settings """
DEBUG = True
BASE_DIR = Path(__file__).resolve().parent.parent
BASE_APP = str(BASE_DIR.name)
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
""" Minimized compulsory settings """
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
INSTALLED_APPS = [
'django.contrib.sessions',
"corsheaders",
'channels',
'valar.data'
]
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'valar.Middleware'
]
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer"
}
}
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
ROOT_URLCONF = "%s.urls" % BASE_APP
ASGI_APPLICATION = "%s.asgi.application" % BASE_APP
VALAR_CHANNEL_HANDLER_MAPPING = "%s.urls.channel_handler_mapping" % BASE_APP
""" Optional settings """
# ALLOWED_HOSTS = ['*']
# LANGUAGE_CODE = 'en-us'
# TIME_ZONE = 'Asia/Shanghai'
# USE_I18N = True
# USE_TZ = False
# SESSION_SAVE_EVERY_REQUEST = True
# SESSION_COOKIE_AGE = 60 * 60
# FILE_UPLOAD_MAX_MEMORY_SIZE = 1024 * 1024 * 100
# DATA_UPLOAD_MAX_MEMORY_SIZE = 1024 * 1024 * 100
root urls
from django.urls import path
from valar.channels import ValarSocketSender
from valar.channels.views import handel_channel
urlpatterns = [
path('socket/<str:handler>', handel_channel),
]
async def test_handler(data, sender: ValarSocketSender):
# print(data, sender.handler, sender.client, sender.uid)
await sender.to_users({'user': 15}, 15)
for i in range(3):
await sender.to_clients({'h': i},sender.client)
channel_handler_mapping = {
'test': test_handler
}
asgi
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from django.urls import re_path
from valar.channels import ValarConsumer
application = ProtocolTypeRouter({
'http': get_asgi_application(),
'websocket': URLRouter([
re_path(r'(?P<client>\w+)/$', ValarConsumer.as_asgi()),
])
})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
valar-1.0.19.tar.gz
(22.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
valar-1.0.19-py3-none-any.whl
(26.5 kB
view details)
File details
Details for the file valar-1.0.19.tar.gz.
File metadata
- Download URL: valar-1.0.19.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
262fe856dc858be16b55d50e55c1b1009d62d44bdced829c2cf51db8f8b37dd0
|
|
| MD5 |
e66e2105aecbdfda7b1bf7e377f19496
|
|
| BLAKE2b-256 |
7ba58b235e4559b05565102d26858ba0d0ce2bb599eb3c09e3d4650786e0d181
|
File details
Details for the file valar-1.0.19-py3-none-any.whl.
File metadata
- Download URL: valar-1.0.19-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82438e1184552b3c673f3734938eb76ff4aa93c0023484659f1ade8b0cae8c59
|
|
| MD5 |
9ebd9b6c0da023fa1956da1fda05a6c7
|
|
| BLAKE2b-256 |
1d364e51b7f1fa0c1c1914dafcfaa79d5916377bbf98e8b55d70ff697a1a7126
|