Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

valar-0.0.14.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

valar-0.0.14-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file valar-0.0.14.tar.gz.

File metadata

  • Download URL: valar-0.0.14.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for valar-0.0.14.tar.gz
Algorithm Hash digest
SHA256 2c3fde940cfd5dbc477635e721ffd055cdc7008c9ca14b415ef2aa6be0c8fe4d
MD5 e7c4b39a03c7bd668744db6e6c29642d
BLAKE2b-256 c621b4e092f6bf21da6ca8f879cb34c70fadc4e938809db47d0f7daca75f4968

See more details on using hashes here.

File details

Details for the file valar-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: valar-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for valar-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 a200b0cf34a17a683c6738086dec0c4d36fcd52303273523ed92ad4b7bdc46e7
MD5 7e8b972e84205efcd07af3c5deda5e17
BLAKE2b-256 068716f02c3c48b728d4790e89c61642d17058ba3a496f9f50fdbbd6810cc615

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page