memory-oc 1.0.0__tar.gz → 1.0.2__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.
- memory_oc-1.0.2/.gitignore +129 -0
- memory_oc-1.0.2/LICENSE +21 -0
- memory_oc-1.0.2/PKG-INFO +223 -0
- memory_oc-1.0.2/README.md +205 -0
- {memory-oc-1.0.0 → memory_oc-1.0.2}/memory/__init__.py +81 -21
- memory_oc-1.0.2/pyproject.toml +31 -0
- memory-oc-1.0.0/PKG-INFO +0 -19
- memory-oc-1.0.0/README.md +0 -2
- memory-oc-1.0.0/memory_oc.egg-info/PKG-INFO +0 -19
- memory-oc-1.0.0/memory_oc.egg-info/SOURCES.txt +0 -11
- memory-oc-1.0.0/memory_oc.egg-info/dependency_links.txt +0 -1
- memory-oc-1.0.0/memory_oc.egg-info/requires.txt +0 -3
- memory-oc-1.0.0/memory_oc.egg-info/top_level.txt +0 -1
- memory-oc-1.0.0/memory_oc.egg-info/zip-safe +0 -1
- memory-oc-1.0.0/setup.cfg +0 -7
- memory-oc-1.0.0/setup.py +0 -30
- {memory-oc-1.0.0 → memory_oc-1.0.2}/memory/__main__.py +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py,cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
target/
|
|
76
|
+
|
|
77
|
+
# Jupyter Notebook
|
|
78
|
+
.ipynb_checkpoints
|
|
79
|
+
|
|
80
|
+
# IPython
|
|
81
|
+
profile_default/
|
|
82
|
+
ipython_config.py
|
|
83
|
+
|
|
84
|
+
# pyenv
|
|
85
|
+
.python-version
|
|
86
|
+
|
|
87
|
+
# pipenv
|
|
88
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
89
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
90
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
91
|
+
# install all needed dependencies.
|
|
92
|
+
#Pipfile.lock
|
|
93
|
+
|
|
94
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
95
|
+
__pypackages__/
|
|
96
|
+
|
|
97
|
+
# Celery stuff
|
|
98
|
+
celerybeat-schedule
|
|
99
|
+
celerybeat.pid
|
|
100
|
+
|
|
101
|
+
# SageMath parsed files
|
|
102
|
+
*.sage.py
|
|
103
|
+
|
|
104
|
+
# Environments
|
|
105
|
+
.env
|
|
106
|
+
.venv
|
|
107
|
+
env/
|
|
108
|
+
venv/
|
|
109
|
+
ENV/
|
|
110
|
+
env.bak/
|
|
111
|
+
venv.bak/
|
|
112
|
+
|
|
113
|
+
# Spyder project settings
|
|
114
|
+
.spyderproject
|
|
115
|
+
.spyproject
|
|
116
|
+
|
|
117
|
+
# Rope project settings
|
|
118
|
+
.ropeproject
|
|
119
|
+
|
|
120
|
+
# mkdocs documentation
|
|
121
|
+
/site
|
|
122
|
+
|
|
123
|
+
# mypy
|
|
124
|
+
.mypy_cache/
|
|
125
|
+
.dmypy.json
|
|
126
|
+
dmypy.json
|
|
127
|
+
|
|
128
|
+
# Pyre type checker
|
|
129
|
+
.pyre/
|
memory_oc-1.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ouroboros Coding Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
memory_oc-1.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: memory_oc
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: A session library using redis
|
|
5
|
+
Project-URL: Source, https://github.com/ouroboroscoding/memory-python
|
|
6
|
+
Project-URL: Tracker, https://github.com/ouroboroscoding/memory-python/issues
|
|
7
|
+
Author-email: "Chris Nasr - Ouroboros Coding Inc." <chris@ouroboroscoding.com>
|
|
8
|
+
Maintainer-email: "Chris Nasr - Ouroboros Coding Inc." <chris@ouroboroscoding.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Requires-Dist: jobject<1.1,>=1.0.4
|
|
13
|
+
Requires-Dist: json-fix<1.1,>=1.0.0
|
|
14
|
+
Requires-Dist: jsonb<1.1,>=1.0.0
|
|
15
|
+
Requires-Dist: namedredis<1.1,>=1.0.2
|
|
16
|
+
Requires-Dist: strings-oc<1.1,>=1.0.7
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# memory_oc
|
|
20
|
+
[](https://pypi.org/project/memory_oc) 
|
|
21
|
+
|
|
22
|
+
Provides methods for creating and managing sessions in [body_oc](https://pypi.org/project/body-oc/)
|
|
23
|
+
projects.
|
|
24
|
+
|
|
25
|
+
Please see [LICENSE](https://github.com/ouroboroscoding/memory-python/blob/main/LICENSE)
|
|
26
|
+
for further information.
|
|
27
|
+
|
|
28
|
+
See [Releases](https://github.com/ouroboroscoding/memory-python/blob/main/releases.md)
|
|
29
|
+
for changes from release to release.
|
|
30
|
+
|
|
31
|
+
## Contents
|
|
32
|
+
- [Module Install](#module-install)
|
|
33
|
+
- [Configuration](#configuration)
|
|
34
|
+
- [Methods](#methods)
|
|
35
|
+
- [close](#memory-close)
|
|
36
|
+
- [create](#memory-create)
|
|
37
|
+
- [load](#memory-load)
|
|
38
|
+
- [Class](#class)
|
|
39
|
+
- [close](#instance-close)
|
|
40
|
+
- [extend](#instance-extend)
|
|
41
|
+
- [key](#instance-key)
|
|
42
|
+
- [save](#instance-save)
|
|
43
|
+
- [update](#instance-update)
|
|
44
|
+
|
|
45
|
+
## Module Install
|
|
46
|
+
|
|
47
|
+
### Requires
|
|
48
|
+
memory_oc requires python 3.10 or higher
|
|
49
|
+
|
|
50
|
+
### Install via pip
|
|
51
|
+
```bash
|
|
52
|
+
pip install memory_oc
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
[ [top](#memory_oc) / [contents](#contents) ]
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
Memory requires the use of a config_oc config.json file. See [config_oc](https://pypi.org/project/config-oc/)
|
|
59
|
+
for more info.
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"memory": {
|
|
64
|
+
"redis": "session"
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
"redis": {
|
|
68
|
+
"session": {
|
|
69
|
+
"host": "redis.mydomain.com",
|
|
70
|
+
"db": 1
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The `redis` section lists Redis connections by name and details to connect. Then
|
|
77
|
+
`memory.redis` specifies which connection to use to create the sessions on.
|
|
78
|
+
|
|
79
|
+
[ [top](#memory_oc) / [contents](#contents) ]
|
|
80
|
+
|
|
81
|
+
## Methods
|
|
82
|
+
Memory comes with three methods, to [`close`](#close), [`create`](#create), and [`load`](#load) sessions.
|
|
83
|
+
|
|
84
|
+
### close
|
|
85
|
+
Immediately closes and deletes a session from Redis.
|
|
86
|
+
|
|
87
|
+
#### example
|
|
88
|
+
```python
|
|
89
|
+
import memory
|
|
90
|
+
|
|
91
|
+
# Closes the session by key
|
|
92
|
+
memory.close(somekey)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### create
|
|
96
|
+
Creates a new session. Takes 3 optional arguments
|
|
97
|
+
|
|
98
|
+
| Argument | Type | Description |
|
|
99
|
+
| -------- | ---- | ----------- |
|
|
100
|
+
| `key` | str | The key to use to create the session in Redis. |
|
|
101
|
+
| `ttl` | unsigned integer | The time to live in seconds for the session. |
|
|
102
|
+
| `data` | dict | The initial data to be stored in the session. |
|
|
103
|
+
|
|
104
|
+
#### example
|
|
105
|
+
```python
|
|
106
|
+
import memory
|
|
107
|
+
|
|
108
|
+
# Creates a 10 minutes session
|
|
109
|
+
session = memory.create(ttl = 600, data = {
|
|
110
|
+
'email': 'sam@somedomain.com',
|
|
111
|
+
'name': 'Sam'
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
# Stores it in Redis
|
|
115
|
+
session.save()
|
|
116
|
+
|
|
117
|
+
# Returns the generated session key
|
|
118
|
+
return session.key()
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### load
|
|
122
|
+
Loads a session from a passed key.
|
|
123
|
+
|
|
124
|
+
#### example
|
|
125
|
+
```python
|
|
126
|
+
import memory
|
|
127
|
+
|
|
128
|
+
# Loads the session data from Redis
|
|
129
|
+
session = memory.load(somekey)
|
|
130
|
+
|
|
131
|
+
# Change data
|
|
132
|
+
session['name'] = 'Samuel'
|
|
133
|
+
|
|
134
|
+
# Store it in Redis
|
|
135
|
+
session.save()
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
[ [top](#memory_oc) / [contents](#contents) ]
|
|
139
|
+
|
|
140
|
+
## Class
|
|
141
|
+
The class is what is returned from the [create](#create) and
|
|
142
|
+
[load](#load) methods.
|
|
143
|
+
|
|
144
|
+
### instance.close
|
|
145
|
+
Closes the session in Redis, making it no longer available to anyone.
|
|
146
|
+
|
|
147
|
+
#### example
|
|
148
|
+
```python
|
|
149
|
+
import memory
|
|
150
|
+
|
|
151
|
+
# Load the session
|
|
152
|
+
session = memory.load(somekey)
|
|
153
|
+
|
|
154
|
+
# Close the session
|
|
155
|
+
session.close()
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### instance.extend
|
|
159
|
+
Extends the TTL of the session by the initial TTL given.
|
|
160
|
+
|
|
161
|
+
#### exmaple
|
|
162
|
+
```python
|
|
163
|
+
import memory
|
|
164
|
+
|
|
165
|
+
# Load the session
|
|
166
|
+
session = memory.load(somekey)
|
|
167
|
+
|
|
168
|
+
# Extend the session
|
|
169
|
+
session.extend()
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### instance.key
|
|
173
|
+
Returns the key of the session.
|
|
174
|
+
|
|
175
|
+
#### example
|
|
176
|
+
```python
|
|
177
|
+
import memory
|
|
178
|
+
|
|
179
|
+
# Create the session
|
|
180
|
+
session = memory.create()
|
|
181
|
+
|
|
182
|
+
# Print the key
|
|
183
|
+
print(session.key())
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### instance.save
|
|
187
|
+
Stores changes in Redis after updates.
|
|
188
|
+
|
|
189
|
+
#### example
|
|
190
|
+
```python
|
|
191
|
+
import memory
|
|
192
|
+
|
|
193
|
+
# Load a session
|
|
194
|
+
session = memory.load(somekey)
|
|
195
|
+
|
|
196
|
+
# Make changes
|
|
197
|
+
session['name'] = 'Samuel'
|
|
198
|
+
|
|
199
|
+
# Save changes
|
|
200
|
+
session.save()
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### instance.update
|
|
204
|
+
Works the same as dict update() so you can store multiple keys at once
|
|
205
|
+
|
|
206
|
+
#### example
|
|
207
|
+
```python
|
|
208
|
+
import memory
|
|
209
|
+
|
|
210
|
+
# Load session
|
|
211
|
+
session = memory.load(somekey)
|
|
212
|
+
|
|
213
|
+
# Update multiple fields
|
|
214
|
+
session.update({
|
|
215
|
+
'name': 'Samuel',
|
|
216
|
+
'phone': '(555) 123-4567'
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
# Save changes
|
|
220
|
+
session.save()
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
[ [top](#memory_oc) / [contents](#contents) ]
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# memory_oc
|
|
2
|
+
[](https://pypi.org/project/memory_oc) 
|
|
3
|
+
|
|
4
|
+
Provides methods for creating and managing sessions in [body_oc](https://pypi.org/project/body-oc/)
|
|
5
|
+
projects.
|
|
6
|
+
|
|
7
|
+
Please see [LICENSE](https://github.com/ouroboroscoding/memory-python/blob/main/LICENSE)
|
|
8
|
+
for further information.
|
|
9
|
+
|
|
10
|
+
See [Releases](https://github.com/ouroboroscoding/memory-python/blob/main/releases.md)
|
|
11
|
+
for changes from release to release.
|
|
12
|
+
|
|
13
|
+
## Contents
|
|
14
|
+
- [Module Install](#module-install)
|
|
15
|
+
- [Configuration](#configuration)
|
|
16
|
+
- [Methods](#methods)
|
|
17
|
+
- [close](#memory-close)
|
|
18
|
+
- [create](#memory-create)
|
|
19
|
+
- [load](#memory-load)
|
|
20
|
+
- [Class](#class)
|
|
21
|
+
- [close](#instance-close)
|
|
22
|
+
- [extend](#instance-extend)
|
|
23
|
+
- [key](#instance-key)
|
|
24
|
+
- [save](#instance-save)
|
|
25
|
+
- [update](#instance-update)
|
|
26
|
+
|
|
27
|
+
## Module Install
|
|
28
|
+
|
|
29
|
+
### Requires
|
|
30
|
+
memory_oc requires python 3.10 or higher
|
|
31
|
+
|
|
32
|
+
### Install via pip
|
|
33
|
+
```bash
|
|
34
|
+
pip install memory_oc
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
[ [top](#memory_oc) / [contents](#contents) ]
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
Memory requires the use of a config_oc config.json file. See [config_oc](https://pypi.org/project/config-oc/)
|
|
41
|
+
for more info.
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"memory": {
|
|
46
|
+
"redis": "session"
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
"redis": {
|
|
50
|
+
"session": {
|
|
51
|
+
"host": "redis.mydomain.com",
|
|
52
|
+
"db": 1
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The `redis` section lists Redis connections by name and details to connect. Then
|
|
59
|
+
`memory.redis` specifies which connection to use to create the sessions on.
|
|
60
|
+
|
|
61
|
+
[ [top](#memory_oc) / [contents](#contents) ]
|
|
62
|
+
|
|
63
|
+
## Methods
|
|
64
|
+
Memory comes with three methods, to [`close`](#close), [`create`](#create), and [`load`](#load) sessions.
|
|
65
|
+
|
|
66
|
+
### close
|
|
67
|
+
Immediately closes and deletes a session from Redis.
|
|
68
|
+
|
|
69
|
+
#### example
|
|
70
|
+
```python
|
|
71
|
+
import memory
|
|
72
|
+
|
|
73
|
+
# Closes the session by key
|
|
74
|
+
memory.close(somekey)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### create
|
|
78
|
+
Creates a new session. Takes 3 optional arguments
|
|
79
|
+
|
|
80
|
+
| Argument | Type | Description |
|
|
81
|
+
| -------- | ---- | ----------- |
|
|
82
|
+
| `key` | str | The key to use to create the session in Redis. |
|
|
83
|
+
| `ttl` | unsigned integer | The time to live in seconds for the session. |
|
|
84
|
+
| `data` | dict | The initial data to be stored in the session. |
|
|
85
|
+
|
|
86
|
+
#### example
|
|
87
|
+
```python
|
|
88
|
+
import memory
|
|
89
|
+
|
|
90
|
+
# Creates a 10 minutes session
|
|
91
|
+
session = memory.create(ttl = 600, data = {
|
|
92
|
+
'email': 'sam@somedomain.com',
|
|
93
|
+
'name': 'Sam'
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
# Stores it in Redis
|
|
97
|
+
session.save()
|
|
98
|
+
|
|
99
|
+
# Returns the generated session key
|
|
100
|
+
return session.key()
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### load
|
|
104
|
+
Loads a session from a passed key.
|
|
105
|
+
|
|
106
|
+
#### example
|
|
107
|
+
```python
|
|
108
|
+
import memory
|
|
109
|
+
|
|
110
|
+
# Loads the session data from Redis
|
|
111
|
+
session = memory.load(somekey)
|
|
112
|
+
|
|
113
|
+
# Change data
|
|
114
|
+
session['name'] = 'Samuel'
|
|
115
|
+
|
|
116
|
+
# Store it in Redis
|
|
117
|
+
session.save()
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
[ [top](#memory_oc) / [contents](#contents) ]
|
|
121
|
+
|
|
122
|
+
## Class
|
|
123
|
+
The class is what is returned from the [create](#create) and
|
|
124
|
+
[load](#load) methods.
|
|
125
|
+
|
|
126
|
+
### instance.close
|
|
127
|
+
Closes the session in Redis, making it no longer available to anyone.
|
|
128
|
+
|
|
129
|
+
#### example
|
|
130
|
+
```python
|
|
131
|
+
import memory
|
|
132
|
+
|
|
133
|
+
# Load the session
|
|
134
|
+
session = memory.load(somekey)
|
|
135
|
+
|
|
136
|
+
# Close the session
|
|
137
|
+
session.close()
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### instance.extend
|
|
141
|
+
Extends the TTL of the session by the initial TTL given.
|
|
142
|
+
|
|
143
|
+
#### exmaple
|
|
144
|
+
```python
|
|
145
|
+
import memory
|
|
146
|
+
|
|
147
|
+
# Load the session
|
|
148
|
+
session = memory.load(somekey)
|
|
149
|
+
|
|
150
|
+
# Extend the session
|
|
151
|
+
session.extend()
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### instance.key
|
|
155
|
+
Returns the key of the session.
|
|
156
|
+
|
|
157
|
+
#### example
|
|
158
|
+
```python
|
|
159
|
+
import memory
|
|
160
|
+
|
|
161
|
+
# Create the session
|
|
162
|
+
session = memory.create()
|
|
163
|
+
|
|
164
|
+
# Print the key
|
|
165
|
+
print(session.key())
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### instance.save
|
|
169
|
+
Stores changes in Redis after updates.
|
|
170
|
+
|
|
171
|
+
#### example
|
|
172
|
+
```python
|
|
173
|
+
import memory
|
|
174
|
+
|
|
175
|
+
# Load a session
|
|
176
|
+
session = memory.load(somekey)
|
|
177
|
+
|
|
178
|
+
# Make changes
|
|
179
|
+
session['name'] = 'Samuel'
|
|
180
|
+
|
|
181
|
+
# Save changes
|
|
182
|
+
session.save()
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### instance.update
|
|
186
|
+
Works the same as dict update() so you can store multiple keys at once
|
|
187
|
+
|
|
188
|
+
#### example
|
|
189
|
+
```python
|
|
190
|
+
import memory
|
|
191
|
+
|
|
192
|
+
# Load session
|
|
193
|
+
session = memory.load(somekey)
|
|
194
|
+
|
|
195
|
+
# Update multiple fields
|
|
196
|
+
session.update({
|
|
197
|
+
'name': 'Samuel',
|
|
198
|
+
'phone': '(555) 123-4567'
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
# Save changes
|
|
202
|
+
session.save()
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
[ [top](#memory_oc) / [contents](#contents) ]
|
|
@@ -15,17 +15,26 @@ __all__ = ['create', 'init', 'load']
|
|
|
15
15
|
|
|
16
16
|
# Ouroboros imports
|
|
17
17
|
from config import config
|
|
18
|
-
|
|
18
|
+
import jobject
|
|
19
19
|
import jsonb
|
|
20
20
|
from nredis import nr
|
|
21
|
+
from strings import random
|
|
22
|
+
from tools import combine
|
|
21
23
|
|
|
22
|
-
#
|
|
23
|
-
import
|
|
24
|
+
# Pip imports
|
|
25
|
+
import json_fix
|
|
24
26
|
|
|
25
27
|
# Open redis connection
|
|
26
28
|
_moRedis = nr(config.memory.redis('session'))
|
|
27
29
|
|
|
28
|
-
def
|
|
30
|
+
def close(key: str):
|
|
31
|
+
"""Close
|
|
32
|
+
|
|
33
|
+
Deletes the session from the cache
|
|
34
|
+
"""
|
|
35
|
+
_moRedis.delete(key)
|
|
36
|
+
|
|
37
|
+
def create(key: str = None, ttl: int = 0, data = None) -> _Memory:
|
|
29
38
|
"""Create
|
|
30
39
|
|
|
31
40
|
Returns a brand new session using the key given, else a UUID is generated
|
|
@@ -38,11 +47,46 @@ def create(key: str = None, ttl: int = 0) -> _Memory:
|
|
|
38
47
|
_Memory
|
|
39
48
|
"""
|
|
40
49
|
|
|
41
|
-
#
|
|
42
|
-
dData =
|
|
50
|
+
# Generate the data to store by adding the TTL
|
|
51
|
+
dData = (
|
|
52
|
+
data is None
|
|
53
|
+
and { '__ttl': ttl }
|
|
54
|
+
or combine(data, { '__ttl': ttl })
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# If we were passed a key
|
|
58
|
+
if key:
|
|
59
|
+
|
|
60
|
+
# If it exists
|
|
61
|
+
if _moRedis.exists(key):
|
|
62
|
+
raise RuntimeError('memory_oc', key, 'key exists')
|
|
63
|
+
|
|
64
|
+
# Set the key
|
|
65
|
+
sKey = key
|
|
66
|
+
|
|
67
|
+
# Else, loop till we get a key that works, which theoretically is always the
|
|
68
|
+
# first time, but on the off chance something breaks, let's have it fully
|
|
69
|
+
# break instead of running forever eating up resources.
|
|
70
|
+
else:
|
|
71
|
+
i = 0
|
|
72
|
+
while True:
|
|
73
|
+
|
|
74
|
+
# Generate a random key
|
|
75
|
+
sKey = 's:%s' % random(32, [ 'aZ', '10', '!*' ])
|
|
76
|
+
|
|
77
|
+
# If it doesn't exist, break out of the loop
|
|
78
|
+
if not _moRedis.exists(sKey):
|
|
79
|
+
break
|
|
80
|
+
|
|
81
|
+
# Increment the count
|
|
82
|
+
i += 1
|
|
83
|
+
if i > 10:
|
|
84
|
+
raise RuntimeError(
|
|
85
|
+
'memory_oc', 'potential infinite loop in create()'
|
|
86
|
+
)
|
|
43
87
|
|
|
44
88
|
# Create a new Memory using the passed key, or a new UUID
|
|
45
|
-
return _Memory(
|
|
89
|
+
return _Memory(sKey, dData)
|
|
46
90
|
|
|
47
91
|
def load(key: str) -> _Memory:
|
|
48
92
|
"""Load
|
|
@@ -78,7 +122,7 @@ class _Memory(object):
|
|
|
78
122
|
object
|
|
79
123
|
"""
|
|
80
124
|
|
|
81
|
-
def __init__(self, key: str, data: dict =
|
|
125
|
+
def __init__(self, key: str, data: dict = None):
|
|
82
126
|
"""Constructor
|
|
83
127
|
|
|
84
128
|
Intialises the instance, which is just setting up the dict
|
|
@@ -91,6 +135,10 @@ class _Memory(object):
|
|
|
91
135
|
_Memory
|
|
92
136
|
"""
|
|
93
137
|
|
|
138
|
+
# If no data passed, init an empty dict
|
|
139
|
+
if data is None:
|
|
140
|
+
data = { }
|
|
141
|
+
|
|
94
142
|
# Store the key and data
|
|
95
143
|
object.__setattr__(self, '__key', key)
|
|
96
144
|
object.__setattr__(self, '__store', jobject(data))
|
|
@@ -115,9 +163,6 @@ class _Memory(object):
|
|
|
115
163
|
|
|
116
164
|
Arguments:
|
|
117
165
|
k (str): The key to remove
|
|
118
|
-
|
|
119
|
-
Returns:
|
|
120
|
-
None
|
|
121
166
|
"""
|
|
122
167
|
del object.__getattribute__(self, '__store')[k]
|
|
123
168
|
|
|
@@ -163,6 +208,19 @@ class _Memory(object):
|
|
|
163
208
|
"""
|
|
164
209
|
return object.__getattribute__(self, '__store').__iter__()
|
|
165
210
|
|
|
211
|
+
def __json__(self):
|
|
212
|
+
"""__json__
|
|
213
|
+
|
|
214
|
+
Returns a dict representation of the session
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
dict
|
|
218
|
+
"""
|
|
219
|
+
return {
|
|
220
|
+
'__key': object.__getattribute__(self, '__key'),
|
|
221
|
+
'__store': object.__getattribute__(self, '__store')
|
|
222
|
+
}
|
|
223
|
+
|
|
166
224
|
def __len__(self):
|
|
167
225
|
"""__len__
|
|
168
226
|
|
|
@@ -209,9 +267,6 @@ class _Memory(object):
|
|
|
209
267
|
"""Close
|
|
210
268
|
|
|
211
269
|
Deletes the session from the cache
|
|
212
|
-
|
|
213
|
-
Returns:
|
|
214
|
-
None
|
|
215
270
|
"""
|
|
216
271
|
_moRedis.delete(object.__getattribute__(self, '__key'))
|
|
217
272
|
|
|
@@ -220,9 +275,6 @@ class _Memory(object):
|
|
|
220
275
|
|
|
221
276
|
Keep the session alive by extending it's expire time by the internally \
|
|
222
277
|
set expire value, or else by the global one set for the module
|
|
223
|
-
|
|
224
|
-
Returns:
|
|
225
|
-
None
|
|
226
278
|
"""
|
|
227
279
|
|
|
228
280
|
# If the expire time is 0, do nothing
|
|
@@ -249,9 +301,6 @@ class _Memory(object):
|
|
|
249
301
|
"""Save
|
|
250
302
|
|
|
251
303
|
Saves the current session data in the cache
|
|
252
|
-
|
|
253
|
-
Returns:
|
|
254
|
-
None
|
|
255
304
|
"""
|
|
256
305
|
|
|
257
306
|
# If we have no expire time, set forever
|
|
@@ -267,4 +316,15 @@ class _Memory(object):
|
|
|
267
316
|
object.__getattribute__(self, '__key'),
|
|
268
317
|
object.__getattribute__(self, '__store')['__ttl'],
|
|
269
318
|
jsonb.encode(object.__getattribute__(self, '__store'))
|
|
270
|
-
)
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
def update(self, other = (), /, **kwargs):
|
|
322
|
+
"""Updated
|
|
323
|
+
|
|
324
|
+
Merge key/value pairs into the session store. Works exactly like dict
|
|
325
|
+
update()
|
|
326
|
+
|
|
327
|
+
Arguments:
|
|
328
|
+
other (dict, list, **kwargs): The additional keys and values to add
|
|
329
|
+
"""
|
|
330
|
+
object.__getattribute__(self, '__store').update(other, **kwargs)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [ "hatchling" ]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "memory_oc"
|
|
7
|
+
version = "1.0.2"
|
|
8
|
+
description = "A session library using redis"
|
|
9
|
+
authors = [
|
|
10
|
+
{name = "Chris Nasr - Ouroboros Coding Inc.", email = "chris@ouroboroscoding.com"}
|
|
11
|
+
]
|
|
12
|
+
maintainers = [
|
|
13
|
+
{name = "Chris Nasr - Ouroboros Coding Inc.", email = "chris@ouroboroscoding.com"}
|
|
14
|
+
]
|
|
15
|
+
license = "MIT"
|
|
16
|
+
readme = "README.md"
|
|
17
|
+
requires-python = ">=3.10"
|
|
18
|
+
dependencies = [
|
|
19
|
+
'jobject>=1.0.4,<1.1',
|
|
20
|
+
'jsonb>=1.0.0,<1.1',
|
|
21
|
+
'json_fix>=1.0.0,<1.1',
|
|
22
|
+
'namedredis>=1.0.2,<1.1',
|
|
23
|
+
'strings-oc>=1.0.7,<1.1'
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Source = "https://github.com/ouroboroscoding/memory-python"
|
|
28
|
+
Tracker = "https://github.com/ouroboroscoding/memory-python/issues"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build]
|
|
31
|
+
packages = [ "memory" ]
|
memory-oc-1.0.0/PKG-INFO
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: memory-oc
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: A session library using redis
|
|
5
|
-
Home-page: https://ouroboroscoding.com/memory/
|
|
6
|
-
Author: Chris Nasr - Ouroboros Coding Inc.
|
|
7
|
-
Author-email: chris@ouroboroscoding.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Project-URL: Documentation, https://ouroboroscoding.com/memory/
|
|
10
|
-
Project-URL: Source, https://github.com/ouroboroscoding/memory-python
|
|
11
|
-
Project-URL: Tracker, https://github.com/ouroboroscoding/memory-python/issues
|
|
12
|
-
Keywords: session,redis
|
|
13
|
-
Platform: UNKNOWN
|
|
14
|
-
Requires-Python: >=3.10
|
|
15
|
-
Description-Content-Type: text/markdown
|
|
16
|
-
|
|
17
|
-
# memory-python
|
|
18
|
-
A python session library using redis
|
|
19
|
-
|
memory-oc-1.0.0/README.md
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: memory-oc
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: A session library using redis
|
|
5
|
-
Home-page: https://ouroboroscoding.com/memory/
|
|
6
|
-
Author: Chris Nasr - Ouroboros Coding Inc.
|
|
7
|
-
Author-email: chris@ouroboroscoding.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Project-URL: Documentation, https://ouroboroscoding.com/memory/
|
|
10
|
-
Project-URL: Source, https://github.com/ouroboroscoding/memory-python
|
|
11
|
-
Project-URL: Tracker, https://github.com/ouroboroscoding/memory-python/issues
|
|
12
|
-
Keywords: session,redis
|
|
13
|
-
Platform: UNKNOWN
|
|
14
|
-
Requires-Python: >=3.10
|
|
15
|
-
Description-Content-Type: text/markdown
|
|
16
|
-
|
|
17
|
-
# memory-python
|
|
18
|
-
A python session library using redis
|
|
19
|
-
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
README.md
|
|
2
|
-
setup.cfg
|
|
3
|
-
setup.py
|
|
4
|
-
memory/__init__.py
|
|
5
|
-
memory/__main__.py
|
|
6
|
-
memory_oc.egg-info/PKG-INFO
|
|
7
|
-
memory_oc.egg-info/SOURCES.txt
|
|
8
|
-
memory_oc.egg-info/dependency_links.txt
|
|
9
|
-
memory_oc.egg-info/requires.txt
|
|
10
|
-
memory_oc.egg-info/top_level.txt
|
|
11
|
-
memory_oc.egg-info/zip-safe
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
memory
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
memory-oc-1.0.0/setup.cfg
DELETED
memory-oc-1.0.0/setup.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
from setuptools import setup
|
|
2
|
-
|
|
3
|
-
with open('README.md', 'r') as oF:
|
|
4
|
-
long_description=oF.read()
|
|
5
|
-
|
|
6
|
-
setup(
|
|
7
|
-
name='memory-oc',
|
|
8
|
-
version='1.0.0',
|
|
9
|
-
description='A session library using redis',
|
|
10
|
-
long_description=long_description,
|
|
11
|
-
long_description_content_type='text/markdown',
|
|
12
|
-
url='https://ouroboroscoding.com/memory/',
|
|
13
|
-
project_urls={
|
|
14
|
-
'Documentation': 'https://ouroboroscoding.com/memory/',
|
|
15
|
-
'Source': 'https://github.com/ouroboroscoding/memory-python',
|
|
16
|
-
'Tracker': 'https://github.com/ouroboroscoding/memory-python/issues'
|
|
17
|
-
},
|
|
18
|
-
keywords=['session','redis'],
|
|
19
|
-
author='Chris Nasr - Ouroboros Coding Inc.',
|
|
20
|
-
author_email='chris@ouroboroscoding.com',
|
|
21
|
-
license='MIT',
|
|
22
|
-
packages=['memory'],
|
|
23
|
-
python_requires='>=3.10',
|
|
24
|
-
install_requires=[
|
|
25
|
-
'jobject>=1.0.2,<1.1',
|
|
26
|
-
'jsonb>=1.0.0,<1.1',
|
|
27
|
-
'namedredis>=1.0.1,<1.1'
|
|
28
|
-
],
|
|
29
|
-
zip_safe=True
|
|
30
|
-
)
|
|
File without changes
|