valar 0.0.3__tar.gz → 0.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2024 Valar Margulis
1
+ Copyright (c) 2018 The Python Packaging Authority
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
valar-0.0.5/PKG-INFO ADDED
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.2
2
+ Name: valar
3
+ Version: 0.0.5
4
+ Summary: valar for morghulis
5
+ Author: LYP
6
+ Author-email: liuyinpeng@buaa.edu.cn
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: channels==3.0.3
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: requires-dist
16
+ Dynamic: requires-python
17
+ Dynamic: summary
18
+
19
+ valar for morghulis
valar-0.0.5/README.md ADDED
@@ -0,0 +1 @@
1
+ valar for morghulis
valar-0.0.5/setup.py ADDED
@@ -0,0 +1,25 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as f:
4
+ long_description = f.read()
5
+
6
+ # with open('requirements.txt', "r", encoding="utf-8") as f:
7
+ # required = f.read().splitlines()
8
+
9
+ requires = ['channels==3.0.3']
10
+
11
+ setup(
12
+ name="valar", # 包名
13
+ version="0.0.5", # 版本号
14
+ author="LYP", # 作者
15
+ author_email="liuyinpeng@buaa.edu.cn", # 邮箱
16
+ description="valar for morghulis", # 简短描述
17
+ long_description=long_description, # 详细说明
18
+ long_description_content_type="text/markdown", # 详细说明使用标记类型
19
+ # url="https://github.com/", # 项目主页
20
+ packages=find_packages(where="src"), # 需要打包的部分
21
+ package_dir={"": "src"}, # 设置src目录为根目录
22
+ python_requires=">=3.9", # 项目支持的Python版本
23
+ install_requires=requires, # 项目必须的依赖
24
+ include_package_data=False # 是否包含非Python文件(如资源文件)
25
+ )
@@ -0,0 +1,135 @@
1
+ import asyncio
2
+ import importlib
3
+ import json
4
+ from datetime import datetime
5
+
6
+ from channels.generic.websocket import AsyncJsonWebsocketConsumer
7
+ from channels.layers import get_channel_layer
8
+ from django.core.exceptions import ImproperlyConfigured
9
+ from django.http import JsonResponse
10
+ from django.conf import settings
11
+
12
+ GROUP = 'VALAR'
13
+
14
+ class ValarSocketSender:
15
+ def __init__(self, data: dict, handler: str, message = None, code = None):
16
+ self.data = data
17
+ self.handler = handler
18
+ self.send = get_channel_layer().group_send
19
+ self.message = message
20
+ self.code = code
21
+
22
+ def __convert_body(self, emit, clients = None, users = None):
23
+ return {
24
+ 'type': emit,
25
+ 'data': {
26
+ 'handler': self.handler,
27
+ 'payload': self.data,
28
+ 'message': self.message,
29
+ 'type': self.code,
30
+ 'timestamp': datetime.now().timestamp()
31
+ },
32
+ 'clients': clients or [],
33
+ 'users': users or [],
34
+ }
35
+
36
+ async def set_message(self, message, code):
37
+ self.message = message
38
+ self.code = code
39
+
40
+ async def to_users(self, *users):
41
+ body = self.__convert_body('user.emit', users=users)
42
+ await self.send(GROUP, body)
43
+
44
+ async def to_clients(self, *clients):
45
+ body = self.__convert_body('client.emit', clients=clients)
46
+ await self.send(GROUP, body)
47
+
48
+ async def broadcast(self):
49
+ body = self.__convert_body('broadcast.emit')
50
+ await self.send(GROUP, body)
51
+
52
+ async def register(self, client, uid):
53
+ body = self.__convert_body('register.emit', [client], [uid])
54
+ await self.send(GROUP, body)
55
+
56
+
57
+ class ValarConsumer(AsyncJsonWebsocketConsumer):
58
+
59
+ def __init__(self):
60
+ self.client = None
61
+ self.uid = None
62
+ super().__init__()
63
+
64
+
65
+ async def connect(self):
66
+ params = self.scope['url_route']['kwargs']
67
+ self.client = params.get('client')
68
+ await self.channel_layer.group_add(GROUP, self.channel_name)
69
+ await self.accept()
70
+
71
+ async def disconnect(self, code):
72
+ await self.channel_layer.group_discard(GROUP, self.channel_name)
73
+ await self.close(code)
74
+
75
+ async def receive_json(self, data, *args, **kwargs):
76
+ print(data)
77
+ pass
78
+
79
+ async def user_emit(self, event):
80
+ users: list = event.get('users',[])
81
+ data = event.get('data',{})
82
+ if self.uid in users:
83
+ await self.send_json(data)
84
+
85
+
86
+ async def client_emit(self, event):
87
+ clients: list = event.get('clients',[])
88
+ data = event.get('data',{})
89
+ if self.client in clients:
90
+ await self.send_json(data)
91
+
92
+ async def broadcast_emit(self, event):
93
+ data = event.get('data',{})
94
+ await self.send_json(data)
95
+
96
+ async def register_emit(self, event):
97
+ users: list = event.get('users', [])
98
+ clients: list = event.get('clients',[])
99
+ if self.client in clients:
100
+ self.uid = users[0]
101
+
102
+
103
+
104
+ def get_valar_channel_handler(handler):
105
+ try:
106
+ root = settings.VALAR_CHANNEL_HANDLER_MAPPING
107
+ path, name = root.rsplit(".", 1)
108
+ except (ValueError, AttributeError):
109
+ raise ImproperlyConfigured("Cannot find VALAR_CHANNEL_HANDLER_MAPPING setting.")
110
+ try:
111
+ module = importlib.import_module(path)
112
+ mapping = getattr(module, name)
113
+ except ImportError:
114
+ raise ImproperlyConfigured("Cannot import VALAR_CHANNEL_HANDLER_MAPPING module %r" % path)
115
+ except AttributeError:
116
+ raise ImproperlyConfigured("module %r has no attribute %r" % (path, name))
117
+ try:
118
+ method = mapping[handler]
119
+ except KeyError:
120
+ raise ImproperlyConfigured("Cannot find handler in %r" % root)
121
+ return method
122
+
123
+
124
+
125
+
126
+ async def socket(request, handler):
127
+ client = request.headers.get('CLIENT')
128
+ uid = request.session.get('UID')
129
+ data = json.loads(request.body)
130
+ method = get_valar_channel_handler(handler)
131
+ loop = asyncio.get_event_loop()
132
+ loop.create_task(method(data, handler, client, uid))
133
+ return JsonResponse({'status':'OK'}, safe=False)
134
+
135
+
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.2
2
+ Name: valar
3
+ Version: 0.0.5
4
+ Summary: valar for morghulis
5
+ Author: LYP
6
+ Author-email: liuyinpeng@buaa.edu.cn
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: channels==3.0.3
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: requires-dist
16
+ Dynamic: requires-python
17
+ Dynamic: summary
18
+
19
+ valar for morghulis
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ src/module/__init__.py
5
+ src/module/channels.py
6
+ src/valar.egg-info/PKG-INFO
7
+ src/valar.egg-info/SOURCES.txt
8
+ src/valar.egg-info/dependency_links.txt
9
+ src/valar.egg-info/requires.txt
10
+ src/valar.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ channels==3.0.3
@@ -0,0 +1 @@
1
+ module
valar-0.0.3/PKG-INFO DELETED
@@ -1,9 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: valar
3
- Version: 0.0.3
4
- Summary: Valar Margulis
5
- Home-page: https://gitee.com/GRIFFIN120/valar
6
- Author: 刘寅鹏
7
- Author-email: liuyinpeng@buaa.edu.cn
8
- License: MIT License
9
- License-File: LICENSE.txt
valar-0.0.3/README.md DELETED
@@ -1,10 +0,0 @@
1
- Valar Margulis
2
-
3
- write readme latter.
4
-
5
- python setup.py sdist
6
- twine upload dist/*
7
-
8
-
9
- pip install --upgrade valar
10
-
valar-0.0.3/setup.py DELETED
@@ -1,16 +0,0 @@
1
- from setuptools import setup
2
- VERSION = '0.0.3'
3
-
4
-
5
- setup(
6
- name='valar',
7
- version=VERSION,
8
- packages=['valar'],
9
- url='https://gitee.com/GRIFFIN120/valar',
10
- license='MIT License',
11
- author='刘寅鹏',
12
- author_email='liuyinpeng@buaa.edu.cn',
13
- description='Valar Margulis'
14
- )
15
-
16
- print(f'twine upload dist/valar-{VERSION}.tar.gz ')
valar-0.0.3/valar/dao.py DELETED
@@ -1,2 +0,0 @@
1
- def exp():
2
- print('hello valar!!!!!')
@@ -1,9 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: valar
3
- Version: 0.0.3
4
- Summary: Valar Margulis
5
- Home-page: https://gitee.com/GRIFFIN120/valar
6
- Author: 刘寅鹏
7
- Author-email: liuyinpeng@buaa.edu.cn
8
- License: MIT License
9
- License-File: LICENSE.txt
@@ -1,9 +0,0 @@
1
- LICENSE.txt
2
- README.md
3
- setup.py
4
- valar/__init__.py
5
- valar/dao.py
6
- valar.egg-info/PKG-INFO
7
- valar.egg-info/SOURCES.txt
8
- valar.egg-info/dependency_links.txt
9
- valar.egg-info/top_level.txt
@@ -1 +0,0 @@
1
- valar
File without changes