httpstate 0.0.14__tar.gz → 0.0.15__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,3 +1,17 @@
1
+ Metadata-Version: 2.4
2
+ Name: httpstate
3
+ Version: 0.0.15
4
+ Summary: HTTPState, httpstate.com
5
+ Author-email: "Alex Morales, HTTPState" <alex@httpstate.com>
6
+ License-Expression: AGPL-3.0
7
+ License-File: LICENSE
8
+ Keywords: httpstate
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.10
12
+ Requires-Dist: websockets>=16.0
13
+ Description-Content-Type: text/markdown
14
+
1
15
  # httpstate (python)
2
16
 
3
17
  ## Quick Start
@@ -45,18 +59,24 @@ That's it! 🐙
45
59
  ### Functions
46
60
 
47
61
  - `get(uuid)`
48
- Get state of UUIDv4.
62
+ Get state of UUIDv4. Returns `None|str`.
49
63
 
50
- - `post(uuid, data)`
51
- Alias for `set`.
64
+ - `message.unpack(bytes)`
65
+ Unpack binary WebSocket message into `MessageType(uuid, timestamp, type, value)`.
66
+
67
+ - `post(uuid, data=None)`
68
+ Alias for `set`. Returns `None|int`.
69
+
70
+ - `put(uuid, data=None)`
71
+ Alias for `set`. Returns `None|int`.
52
72
 
53
73
  - `read(uuid)`
54
74
  Alias for `get`.
55
75
 
56
- - `set(uuid, data)`
57
- Set state of UUIDv4.
76
+ - `set(uuid, data=None)`
77
+ Set state of UUIDv4. Returns `None|int`. If `data` is `None`, defaults to `''`.
58
78
 
59
- - `write(uuid, data)`
79
+ - `write(uuid, data=None)`
60
80
  Alias for `set`.
61
81
 
62
82
  ### HttpState Class
@@ -69,14 +89,16 @@ That's it! 🐙
69
89
  <br>
70
90
 
71
91
  - `<HttpState>.get()`
72
- Get state.
73
- - `<HttpState>.post(data)`
92
+ Get state. Returns `None|str`.
93
+ - `<HttpState>.post(data=None)`
94
+ Alias for `set`.
95
+ - `<HttpState>.put(data=None)`
74
96
  Alias for `set`.
75
97
  - `<HttpState>.read()`
76
98
  Alias for `get`.
77
- - `<HttpState>.set(data)`
78
- Set state.
79
- - `<HttpState>.write(data)`
99
+ - `<HttpState>.set(data=None)`
100
+ Set state. Returns `None|int`. If `data` is `None`, defaults to `''`.
101
+ - `<HttpState>.write(data=None)`
80
102
  Alias for `set`.
81
103
 
82
104
  <br>
@@ -1,17 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: httpstate
3
- Version: 0.0.14
4
- Summary: HTTP State, httpstate.com
5
- Author-email: "Alex Morales, HTTP State" <alex@httpstate.com>
6
- License-Expression: AGPL-3.0
7
- License-File: LICENSE
8
- Keywords: httpstate
9
- Classifier: Operating System :: OS Independent
10
- Classifier: Programming Language :: Python :: 3
11
- Requires-Python: >=3.10
12
- Requires-Dist: websockets>=16.0
13
- Description-Content-Type: text/markdown
14
-
15
1
  # httpstate (python)
16
2
 
17
3
  ## Quick Start
@@ -59,18 +45,24 @@ That's it! 🐙
59
45
  ### Functions
60
46
 
61
47
  - `get(uuid)`
62
- Get state of UUIDv4.
48
+ Get state of UUIDv4. Returns `None|str`.
63
49
 
64
- - `post(uuid, data)`
65
- Alias for `set`.
50
+ - `message.unpack(bytes)`
51
+ Unpack binary WebSocket message into `MessageType(uuid, timestamp, type, value)`.
52
+
53
+ - `post(uuid, data=None)`
54
+ Alias for `set`. Returns `None|int`.
55
+
56
+ - `put(uuid, data=None)`
57
+ Alias for `set`. Returns `None|int`.
66
58
 
67
59
  - `read(uuid)`
68
60
  Alias for `get`.
69
61
 
70
- - `set(uuid, data)`
71
- Set state of UUIDv4.
62
+ - `set(uuid, data=None)`
63
+ Set state of UUIDv4. Returns `None|int`. If `data` is `None`, defaults to `''`.
72
64
 
73
- - `write(uuid, data)`
65
+ - `write(uuid, data=None)`
74
66
  Alias for `set`.
75
67
 
76
68
  ### HttpState Class
@@ -83,14 +75,16 @@ That's it! 🐙
83
75
  <br>
84
76
 
85
77
  - `<HttpState>.get()`
86
- Get state.
87
- - `<HttpState>.post(data)`
78
+ Get state. Returns `None|str`.
79
+ - `<HttpState>.post(data=None)`
80
+ Alias for `set`.
81
+ - `<HttpState>.put(data=None)`
88
82
  Alias for `set`.
89
83
  - `<HttpState>.read()`
90
84
  Alias for `get`.
91
- - `<HttpState>.set(data)`
92
- Set state.
93
- - `<HttpState>.write(data)`
85
+ - `<HttpState>.set(data=None)`
86
+ Set state. Returns `None|int`. If `data` is `None`, defaults to `''`.
87
+ - `<HttpState>.write(data=None)`
94
88
  Alias for `set`.
95
89
 
96
90
  <br>
@@ -3,20 +3,20 @@ build-backend = "hatchling.build"
3
3
  requires = ["hatchling >= 1.26"]
4
4
 
5
5
  [project]
6
- authors = [{ email="alex@httpstate.com", name="Alex Morales, HTTP State" }]
6
+ authors = [{ email="alex@httpstate.com", name="Alex Morales, HTTPState" }]
7
7
  classifiers = [
8
8
  "Operating System :: OS Independent",
9
9
  "Programming Language :: Python :: 3"
10
10
  ]
11
11
  dependencies = ["websockets>=16.0"]
12
- description = "HTTP State, httpstate.com"
12
+ description = "HTTPState, httpstate.com"
13
13
  keywords = ["httpstate"]
14
14
  license = "AGPL-3.0"
15
15
  license-files = ["LICEN[CS]E*"]
16
16
  name = "httpstate"
17
17
  readme = "README.md"
18
18
  requires-python = ">=3.10"
19
- version = "0.0.14"
19
+ version = "0.0.15"
20
20
 
21
21
  [project.url]
22
22
  Homepage = "https://httpstate.com"
@@ -1,4 +1,4 @@
1
- # HTTP State, https://httpstate.com/
1
+ # HTTPState, https://httpstate.com/
2
2
  # Copyright (C) Alex Morales, 2026
3
3
 
4
4
  # Unless otherwise stated in particular files or directories, this software is free software.
@@ -1,4 +1,4 @@
1
- # HTTP State, https://httpstate.com/
1
+ # HTTPState, https://httpstate.com/
2
2
  # Copyright (C) Alex Morales, 2026
3
3
 
4
4
  # Unless otherwise stated in particular files or directories, this software is free software.
@@ -9,7 +9,6 @@
9
9
  import asyncio
10
10
  import struct
11
11
  import threading
12
- import types
13
12
  import urllib.error
14
13
  import urllib.request
15
14
  import websockets
@@ -49,16 +48,19 @@ class Message:
49
48
 
50
49
  message:type = Message
51
50
 
52
- def post(uuid:str, data:str) -> None|int:
51
+ def post(uuid:str, data:None|str = None) -> None|int:
53
52
  return set(uuid, data)
54
53
 
55
- def put(uuid:str, data:str) -> None|int:
54
+ def put(uuid:str, data:None|str = None) -> None|int:
56
55
  return set(uuid, data)
57
56
 
58
57
  def read(uuid:str) -> None|str:
59
58
  return get(uuid)
60
59
 
61
- def set(uuid:str, data:str) -> None|int:
60
+ def set(uuid:str, data:None|str = None) -> None|int:
61
+ if(data is None):
62
+ data = ''
63
+
62
64
  req:urllib.request.Request = urllib.request.Request(
63
65
  f'https://httpstate.com/{uuid}',
64
66
  data=data.encode('utf-8'),
@@ -74,15 +76,16 @@ def set(uuid:str, data:str) -> None|int:
74
76
  except Exception:
75
77
  return None
76
78
 
77
- def write(uuid:str, data:str) -> None|int:
79
+ def write(uuid:str, data:None|str = None) -> None|int:
78
80
  return set(uuid, data)
79
81
 
80
- # HTTP State
82
+ # HTTPState
81
83
  class HttpState:
82
84
  def __init__(self, uuid:str) -> None:
83
85
  self.data:None|str = None
84
86
  self.el:None|asyncio.AbstractEventLoop = None
85
87
  self.et:Dict[str, List[Callable[[None|str], None]]] = {}
88
+ self.lock:threading.Lock = threading.Lock()
86
89
  self.uuid:str = uuid
87
90
  self.ws:None|websockets.WebSocketClientProtocol = None
88
91
 
@@ -120,7 +123,8 @@ class HttpState:
120
123
  and data.uuid == self.uuid
121
124
  and data.type == 1
122
125
  ):
123
- self.data:None|str = data.value.decode()
126
+ with self.lock:
127
+ self.data:None|str = data.value.decode()
124
128
 
125
129
  self.emit('change', self.data)
126
130
 
@@ -154,10 +158,12 @@ class HttpState:
154
158
  def get(self) -> None|str:
155
159
  data:None|str = get(self.uuid)
156
160
 
157
- if(data != self.data):
158
- self.el.call_soon_threadsafe(lambda : self.emit('change', self.data))
161
+ with self.lock:
162
+ if(data != self.data):
163
+ if self.el is not None:
164
+ self.el.call_soon_threadsafe(lambda : self.emit('change', self.data))
159
165
 
160
- self.data = data
166
+ self.data = data
161
167
 
162
168
  return self.data
163
169
 
@@ -181,17 +187,17 @@ class HttpState:
181
187
 
182
188
  return self
183
189
 
184
- def post(self, data:str) -> None|int:
190
+ def post(self, data:None|str = None) -> None|int:
185
191
  return self.set(data)
186
192
 
187
- def put(self, data:str) -> None|int:
193
+ def put(self, data:None|str = None) -> None|int:
188
194
  return self.set(data)
189
195
 
190
196
  def read(self) -> None|str:
191
197
  return self.get()
192
198
 
193
- def set(self, data:str) -> None|int:
199
+ def set(self, data:None|str = None) -> None|int:
194
200
  return set(self.uuid, data)
195
201
 
196
- def write(self, data:str) -> None|int:
202
+ def write(self, data:None|str = None) -> None|int:
197
203
  return self.set(data)
File without changes
File without changes