synapse 2.134.0__py38-none-any.whl → 2.136.0__py38-none-any.whl
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.
Potentially problematic release.
This version of synapse might be problematic. Click here for more details.
- synapse/axon.py +10 -2
- synapse/cortex.py +43 -29
- synapse/lib/ast.py +106 -48
- synapse/lib/cell.py +13 -5
- synapse/lib/layer.py +13 -1
- synapse/lib/parser.py +8 -40
- synapse/lib/storm.lark +25 -25
- synapse/lib/storm.py +4 -2
- synapse/lib/storm_format.py +6 -4
- synapse/lib/stormlib/auth.py +25 -3
- synapse/lib/stormlib/compression.py +176 -0
- synapse/lib/stormlib/graph.py +2 -0
- synapse/lib/stormtypes.py +77 -31
- synapse/lib/types.py +4 -1
- synapse/lib/version.py +2 -2
- synapse/lib/view.py +4 -1
- synapse/tests/test_axon.py +8 -2
- synapse/tests/test_cortex.py +38 -4
- synapse/tests/test_lib_grammar.py +64 -64
- synapse/tests/test_lib_httpapi.py +53 -1
- synapse/tests/test_lib_layer.py +20 -0
- synapse/tests/test_lib_rstorm.py +1 -1
- synapse/tests/test_lib_storm.py +40 -5
- synapse/tests/test_lib_stormlib_auth.py +16 -3
- synapse/tests/test_lib_stormlib_compression.py +61 -0
- synapse/tests/test_lib_stormlib_model.py +1 -1
- synapse/tests/test_lib_stormtypes.py +59 -6
- synapse/tests/test_lib_trigger.py +1 -1
- synapse/tests/test_lib_types.py +4 -2
- {synapse-2.134.0.dist-info → synapse-2.136.0.dist-info}/METADATA +4 -5
- {synapse-2.134.0.dist-info → synapse-2.136.0.dist-info}/RECORD +34 -32
- {synapse-2.134.0.dist-info → synapse-2.136.0.dist-info}/LICENSE +0 -0
- {synapse-2.134.0.dist-info → synapse-2.136.0.dist-info}/WHEEL +0 -0
- {synapse-2.134.0.dist-info → synapse-2.136.0.dist-info}/top_level.txt +0 -0
synapse/lib/storm.lark
CHANGED
|
@@ -123,10 +123,10 @@ opervarlist: varlist "=" _valu
|
|
|
123
123
|
|
|
124
124
|
// Pivots
|
|
125
125
|
_formpivot: formpivot_pivottotags | formpivot_jointags | formpivot_pivotout | formpivot_
|
|
126
|
-
formpivot_pivottotags: _RIGHTPIVOT (ALLTAGS |
|
|
127
|
-
formpivot_jointags: _RIGHTJOIN (ALLTAGS |
|
|
126
|
+
formpivot_pivottotags: _RIGHTPIVOT (ALLTAGS | tagmatch)
|
|
127
|
+
formpivot_jointags: _RIGHTJOIN (ALLTAGS | tagmatch)
|
|
128
128
|
// The special symbol that indicates to pivot to syn:tag nodes
|
|
129
|
-
ALLTAGS.
|
|
129
|
+
ALLTAGS.3: /#(?=\/[\/\*]|\s|$|\})/
|
|
130
130
|
|
|
131
131
|
formpivot_pivotout: _RIGHTPIVOT "*"
|
|
132
132
|
formpivot_: _RIGHTPIVOT ABSPROP
|
|
@@ -194,8 +194,6 @@ lifttagtag:(_HASH | _HASHSPACE) tagname [_cmpr _valu]
|
|
|
194
194
|
liftbytag: (tagname | tagnamewithspace) [_cmpr _valu]
|
|
195
195
|
liftbytagprop: (tagprop | tagpropwithspace) [_cmpr _valu]
|
|
196
196
|
liftbyformtagprop: formtagprop [_cmpr _valu]
|
|
197
|
-
tagname: _tagmatch
|
|
198
|
-
tagnamewithspace: _tagmatchwithspace -> tagname
|
|
199
197
|
tagprop: tagname _COLONNOSPACE (BASEPROP | _varvalu)
|
|
200
198
|
tagpropwithspace: tagnamewithspace _COLONNOSPACE (BASEPROP | _varvalu) -> tagprop
|
|
201
199
|
formtagprop: ((PROPS | UNIVNAME) | _DEREF _varvalu) tagname _COLONNOSPACE (BASEPROP | _varvalu)
|
|
@@ -228,16 +226,20 @@ EQNOSPACE: /(?<!\s)=(?!\s)/
|
|
|
228
226
|
cmdrargs: _cmdrargv (EQNOSPACE? _cmdrargv)*
|
|
229
227
|
_cmdrargv: baresubquery | DOUBLEQUOTEDSTRING | SINGLEQUOTEDSTRING | CMDRTOKN | CMDOPT (EQNOSPACE (CMDRTOKN | SINGLEQUOTEDSTRING | DOUBLEQUOTEDSTRING | baresubquery))?
|
|
230
228
|
|
|
231
|
-
// A tag with either a variable reference or
|
|
232
|
-
|
|
229
|
+
// A tag with either a variable reference or tag name segments without asterisks
|
|
230
|
+
tagname: _HASH (_varvalu | _tagsegs)
|
|
231
|
+
tagnamewithspace: _HASHSPACE (_varvalu | _tagsegs) -> tagname
|
|
233
232
|
_HASH.2: /(?<!\s)#/
|
|
234
|
-
|
|
235
|
-
_tagmatchwithspace: _HASHSPACE (_varvalu | TAGMATCH)
|
|
236
233
|
_HASHSPACE.2: /(?<=\s)#/
|
|
234
|
+
_tagsegs: TAGSEGNOVAR ( "." (TAGSEGNOVAR | "$" varvalue))*
|
|
235
|
+
TAGSEGNOVAR: /[\w]+/
|
|
237
236
|
|
|
238
237
|
// A tag name with asterisks or $var as segment after the first segment
|
|
239
|
-
|
|
240
|
-
|
|
238
|
+
tagmatch: (_MATCHHASH | _MATCHHASHSPACE) (_varvalu | _wildtagsegs)
|
|
239
|
+
_MATCHHASH.3: /(?<!\s)#/
|
|
240
|
+
_MATCHHASHSPACE.3: /(?<=\s)#/
|
|
241
|
+
_wildtagsegs: WILDTAGSEGNOVAR ( "." (WILDTAGSEGNOVAR | "$" varvalue))*
|
|
242
|
+
WILDTAGSEGNOVAR: /[\w*]+/
|
|
241
243
|
|
|
242
244
|
// A comparison operator
|
|
243
245
|
_cmpr: "*" BYNAME | CMPR | CMPROTHER | EQSPACE | EQNOSPACE | TRYSET | SETTAGOPER
|
|
@@ -260,9 +262,8 @@ _basevalu: _argvalu | baresubquery
|
|
|
260
262
|
_valu: _basevalu | NONQUOTEWORD
|
|
261
263
|
|
|
262
264
|
evalvalu: _valu
|
|
263
|
-
exprdict: "{" ((_exprvalu | VARTOKN) ":" (_exprvalu | VARTOKN) ("," (_exprvalu | VARTOKN) ":" (_exprvalu | VARTOKN))* ","? )? "}"
|
|
265
|
+
exprdict: "{" ((_exprvalu | VARTOKN) (":" | _EXPRCOLONNOSPACE) (_exprvalu | VARTOKN) ("," (_exprvalu | VARTOKN) (":" | _EXPRCOLONNOSPACE) (_exprvalu | VARTOKN))* ","? )? "}"
|
|
264
266
|
exprlist: "[" ((_exprvalu | VARTOKN) ("," (_exprvalu | VARTOKN))* ","? )? "]"
|
|
265
|
-
|
|
266
267
|
// Just like _valu, but doesn't allow valu lists or unquoted strings or queries
|
|
267
268
|
_exprvalu: NUMBER | HEXNUMBER | BOOL | exprlist | exprdict | _exprvarvalu | exprrelpropvalu
|
|
268
269
|
| exprunivpropvalu | exprtagvalu | exprtagpropvalu | TRIPLEQUOTEDSTRING | DOUBLEQUOTEDSTRING
|
|
@@ -286,18 +287,17 @@ EXPRUNIVNAME.2: /(?<=^|[\s\|\{\(\[+=-])\.[a-z_][a-z0-9_]*([:.][a-z0-9_]+)*/
|
|
|
286
287
|
|
|
287
288
|
exprtagvalu: exprtagname -> tagvalu
|
|
288
289
|
| exprtagnamewithspace -> tagvalu
|
|
289
|
-
exprtagname: _exprtagmatch -> tagname
|
|
290
|
-
_exprtagmatch: _EXPRHASH (_varvalu | TAGMATCH)
|
|
291
|
-
_EXPRHASH.2: /(?<!\s)#/
|
|
292
290
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
291
|
+
exprtagname: _HASH (_exprvarvalu | _exprtagsegs) -> tagname
|
|
292
|
+
exprtagnamewithspace: _HASHSPACE (_exprvarvalu | _exprtagsegs) -> tagname
|
|
293
|
+
_exprtagsegs: EXPRTAGSEGNOVAR ( "." (EXPRTAGSEGNOVAR | "$" exprvarvalue))*
|
|
294
|
+
EXPRTAGSEGNOVAR: /[\w]+/
|
|
296
295
|
|
|
297
296
|
exprtagpropvalu: exprtagprop -> tagpropvalu
|
|
298
297
|
| exprtagpropwithspace -> tagpropvalu
|
|
299
|
-
exprtagprop: exprtagname
|
|
300
|
-
exprtagpropwithspace: exprtagnamewithspace
|
|
298
|
+
exprtagprop: exprtagname _EXPRCOLONNOSPACE (BASEPROP | _exprvarvalu) -> tagprop
|
|
299
|
+
exprtagpropwithspace: exprtagnamewithspace _EXPRCOLONNOSPACE (BASEPROP | _exprvarvalu) -> tagprop
|
|
300
|
+
_EXPRCOLONNOSPACE.2: /(?<!\s):/
|
|
301
301
|
|
|
302
302
|
_exprvarvalu: "$" _exprvarvaluatom
|
|
303
303
|
_exprvarvaluatom: exprvarvalue | exprvarderef | exprfunccall
|
|
@@ -372,11 +372,11 @@ relpropvalue: relprop | univprop
|
|
|
372
372
|
abspropcond: ABSPROPNOUNIV _cmpr _valu
|
|
373
373
|
hasabspropcond: ABSPROPNOUNIV
|
|
374
374
|
|
|
375
|
-
tagpropcond:
|
|
376
|
-
hastagpropcond: (
|
|
375
|
+
tagpropcond: tagmatch _COLONNOSPACE (BASEPROP | _varvalu) _cmpr _valu
|
|
376
|
+
hastagpropcond: tagmatch _COLONNOSPACE (BASEPROP | _varvalu)
|
|
377
377
|
|
|
378
|
-
tagvalucond:
|
|
379
|
-
tagcond:
|
|
378
|
+
tagvalucond: tagmatch _cmpr _valu
|
|
379
|
+
tagcond: tagmatch
|
|
380
380
|
|
|
381
381
|
condsubq: "{" query "}" [ _cmpr _valu]
|
|
382
382
|
arraycond: relprop _ARRAYCONDSTART _safe_cmpr _valu "]"
|
synapse/lib/storm.py
CHANGED
|
@@ -180,6 +180,7 @@ permdef_schema = {
|
|
|
180
180
|
'perm': {'type': 'array', 'items': {'type': 'string'}},
|
|
181
181
|
'desc': {'type': 'string'},
|
|
182
182
|
'gate': {'type': 'string'},
|
|
183
|
+
'ex': {'type': 'string'}, # Example string
|
|
183
184
|
'workflowconfig': {'type': 'boolean'},
|
|
184
185
|
'default': {'type': 'boolean', 'default': False},
|
|
185
186
|
},
|
|
@@ -4194,7 +4195,7 @@ class DelNodeCmd(Cmd):
|
|
|
4194
4195
|
delbytes = await s_stormtypes.tobool(self.opts.delbytes)
|
|
4195
4196
|
|
|
4196
4197
|
if force:
|
|
4197
|
-
if runt.user is not None and not runt.
|
|
4198
|
+
if runt.user is not None and not runt.isAdmin():
|
|
4198
4199
|
mesg = '--force requires admin privs.'
|
|
4199
4200
|
raise s_exc.AuthDeny(mesg=mesg, user=self.runt.user.iden, username=self.runt.user.name)
|
|
4200
4201
|
|
|
@@ -5765,7 +5766,8 @@ class RunAsCmd(Cmd):
|
|
|
5765
5766
|
return pars
|
|
5766
5767
|
|
|
5767
5768
|
async def execStormCmd(self, runt, genr):
|
|
5768
|
-
|
|
5769
|
+
|
|
5770
|
+
if not runt.isAdmin():
|
|
5769
5771
|
mesg = 'The runas command requires admin privileges.'
|
|
5770
5772
|
raise s_exc.AuthDeny(mesg=mesg, user=self.runt.user.iden, username=self.runt.user.name)
|
|
5771
5773
|
|
synapse/lib/storm_format.py
CHANGED
|
@@ -39,6 +39,7 @@ TerminalPygMap = {
|
|
|
39
39
|
'EXPRNEG': p_t.Operator,
|
|
40
40
|
'EXPRPLUS': p_t.Operator,
|
|
41
41
|
'EXPRPOW': p_t.Operator,
|
|
42
|
+
'EXPRTAGSEGNOVAR': p_t.Name,
|
|
42
43
|
'EXPRTIMES': p_t.Operator,
|
|
43
44
|
'FOR': p_t.Keyword,
|
|
44
45
|
'FORMATSTRING': p_t.Literal.String,
|
|
@@ -67,7 +68,7 @@ TerminalPygMap = {
|
|
|
67
68
|
'SETTAGOPER': p_t.Operator,
|
|
68
69
|
'SINGLEQUOTEDSTRING': p_t.Literal.String,
|
|
69
70
|
'SWITCH': p_t.Keyword,
|
|
70
|
-
'
|
|
71
|
+
'TAGSEGNOVAR': p_t.Name,
|
|
71
72
|
'TRIPLEQUOTEDSTRING': p_t.Literal.String,
|
|
72
73
|
'TRYSET': p_t.Operator,
|
|
73
74
|
'TRYSETMINUS': p_t.Operator,
|
|
@@ -80,6 +81,7 @@ TerminalPygMap = {
|
|
|
80
81
|
'WHILE': p_t.Keyword,
|
|
81
82
|
'WHITETOKN': p_t.Literal.String,
|
|
82
83
|
'WILDCARD': p_t.Name,
|
|
84
|
+
'WILDTAGSEGNOVAR': p_t.Name,
|
|
83
85
|
'YIELD': p_t.Keyword,
|
|
84
86
|
'_ARRAYCONDSTART': p_t.Punctuation,
|
|
85
87
|
'_COLONDOLLAR': p_t.Punctuation,
|
|
@@ -94,20 +96,20 @@ TerminalPygMap = {
|
|
|
94
96
|
'_ELSE': p_t.Keyword,
|
|
95
97
|
'_EMBEDQUERYSTART': p_t.Punctuation,
|
|
96
98
|
'_EMIT': p_t.Keyword,
|
|
99
|
+
'_EXPRCOLONNOSPACE': p_t.Punctuation,
|
|
97
100
|
'_FINI': p_t.Keyword,
|
|
98
101
|
'_HASH': p_t.Punctuation,
|
|
99
|
-
'_EXPRHASH': p_t.Punctuation,
|
|
100
102
|
'_HASHSPACE': p_t.Punctuation,
|
|
101
|
-
'_EXPRHASHSPACE': p_t.Punctuation,
|
|
102
103
|
'_INIT': p_t.Keyword,
|
|
103
104
|
'_LEFTJOIN': p_t.Punctuation,
|
|
104
105
|
'_LEFTPIVOT': p_t.Punctuation,
|
|
105
106
|
'_LPARNOSPACE': p_t.Punctuation,
|
|
107
|
+
'_MATCHHASH': p_t.Punctuation,
|
|
108
|
+
'_MATCHHASHSPACE': p_t.Punctuation,
|
|
106
109
|
'_RETURN': p_t.Keyword,
|
|
107
110
|
'_RIGHTJOIN': p_t.Punctuation,
|
|
108
111
|
'_RIGHTPIVOT': p_t.Punctuation,
|
|
109
112
|
'_STOP': p_t.Keyword,
|
|
110
|
-
'_TAGSEGNOVAR': p_t.Name,
|
|
111
113
|
'_WALKNPIVON1': p_t.Punctuation,
|
|
112
114
|
'_WALKNPIVON2': p_t.Punctuation,
|
|
113
115
|
'$END': p_t.Punctuation,
|
synapse/lib/stormlib/auth.py
CHANGED
|
@@ -203,7 +203,7 @@ stormcmds = (
|
|
|
203
203
|
auth.user.addrule visi "!foo.bar.baz"
|
|
204
204
|
|
|
205
205
|
// add an allow rule to the user "visi" for permission "baz" at the first index.
|
|
206
|
-
auth.user.addrule visi baz --
|
|
206
|
+
auth.user.addrule visi baz --index 0
|
|
207
207
|
''',
|
|
208
208
|
'cmdargs': (
|
|
209
209
|
('name', {'type': 'str', 'help': 'The name of the user.'}),
|
|
@@ -275,7 +275,7 @@ stormcmds = (
|
|
|
275
275
|
auth.role.addrule ninjas "!foo.bar.baz"
|
|
276
276
|
|
|
277
277
|
// add an allow rule to the role "ninjas" for permission "baz" at the first index.
|
|
278
|
-
auth.role.addrule ninjas baz --
|
|
278
|
+
auth.role.addrule ninjas baz --index 0
|
|
279
279
|
''',
|
|
280
280
|
'cmdargs': (
|
|
281
281
|
('name', {'type': 'str', 'help': 'The name of the role.'}),
|
|
@@ -343,10 +343,14 @@ stormcmds = (
|
|
|
343
343
|
// Grant the role "ninjas" to the user "visi"
|
|
344
344
|
auth.user.grant visi ninjas
|
|
345
345
|
|
|
346
|
+
// Grant the role "ninjas" to the user "visi" at the first index.
|
|
347
|
+
auth.user.grant visi ninjas --index 0
|
|
348
|
+
|
|
346
349
|
''',
|
|
347
350
|
'cmdargs': (
|
|
348
351
|
('username', {'type': 'str', 'help': 'The name of the user.'}),
|
|
349
352
|
('rolename', {'type': 'str', 'help': 'The name of the role.'}),
|
|
353
|
+
('--index', {'type': 'int', 'help': 'Specify the role location as a 0 based index.', 'default': None}),
|
|
350
354
|
),
|
|
351
355
|
'storm': '''
|
|
352
356
|
$user = $lib.auth.users.byname($cmdopts.username)
|
|
@@ -356,7 +360,7 @@ stormcmds = (
|
|
|
356
360
|
if (not $role) { $lib.exit(`No role named: {$cmdopts.rolename}`) }
|
|
357
361
|
|
|
358
362
|
$lib.print(`Granting role {$role.name} to user {$user.name}.`)
|
|
359
|
-
$user.grant($role.iden)
|
|
363
|
+
$user.grant($role.iden, indx=$cmdopts.index)
|
|
360
364
|
''',
|
|
361
365
|
},
|
|
362
366
|
{
|
|
@@ -555,4 +559,22 @@ stormcmds = (
|
|
|
555
559
|
}
|
|
556
560
|
'''
|
|
557
561
|
},
|
|
562
|
+
{
|
|
563
|
+
'name': 'auth.perms.list',
|
|
564
|
+
'descr': 'Display a list of the current permissions defined within the Cortex.',
|
|
565
|
+
'cmdargs': (),
|
|
566
|
+
'storm': '''
|
|
567
|
+
|
|
568
|
+
for $pdef in $lib.auth.getPermDefs() {
|
|
569
|
+
$perm = $lib.str.join(".", $pdef.perm)
|
|
570
|
+
|
|
571
|
+
$lib.print($perm)
|
|
572
|
+
$lib.print(` {$pdef.desc}`)
|
|
573
|
+
$lib.print(` gate: {$pdef.gate}`)
|
|
574
|
+
$lib.print(` default: {$pdef.default}`)
|
|
575
|
+
if $pdef.ex { $lib.print(` example: {$pdef.ex}`) }
|
|
576
|
+
$lib.print('')
|
|
577
|
+
}
|
|
578
|
+
'''
|
|
579
|
+
},
|
|
558
580
|
)
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import bz2
|
|
2
|
+
import gzip
|
|
3
|
+
import zlib
|
|
4
|
+
|
|
5
|
+
import synapse.exc as s_exc
|
|
6
|
+
import synapse.common as s_common
|
|
7
|
+
|
|
8
|
+
import synapse.lib.stormtypes as s_stormtypes
|
|
9
|
+
|
|
10
|
+
@s_stormtypes.registry.registerLib
|
|
11
|
+
class Bzip2Lib(s_stormtypes.Lib):
|
|
12
|
+
'''
|
|
13
|
+
A Storm library which implements helpers for bzip2 compression.
|
|
14
|
+
'''
|
|
15
|
+
_storm_locals = (
|
|
16
|
+
{'name': 'en', 'desc': '''
|
|
17
|
+
Compress bytes using bzip2 and return them.
|
|
18
|
+
|
|
19
|
+
Example:
|
|
20
|
+
Compress bytes with bzip2::
|
|
21
|
+
|
|
22
|
+
$foo = $lib.compression.bzip2.en($mybytez)''',
|
|
23
|
+
'type': {'type': 'function', '_funcname': 'en',
|
|
24
|
+
'args': (
|
|
25
|
+
{'name': 'valu', 'type': 'bytes', 'desc': 'The bytes to be compressed.'},
|
|
26
|
+
),
|
|
27
|
+
'returns': {'type': 'bytes', 'desc': 'The bzip2 compressed bytes.'}}},
|
|
28
|
+
{'name': 'un', 'desc': '''
|
|
29
|
+
Decompress bytes using bzip2 and return them.
|
|
30
|
+
|
|
31
|
+
Example:
|
|
32
|
+
Decompress bytes with bzip2::
|
|
33
|
+
|
|
34
|
+
$foo = $lib.compression.bzip2.un($mybytez)''',
|
|
35
|
+
'type': {'type': 'function', '_funcname': 'un',
|
|
36
|
+
'args': (
|
|
37
|
+
{'name': 'valu', 'type': 'bytes', 'desc': 'The bytes to be decompressed.'},
|
|
38
|
+
),
|
|
39
|
+
'returns': {'type': 'bytes', 'desc': 'Decompressed bytes.'}}},
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
_storm_lib_path = ('compression', 'bzip2')
|
|
43
|
+
|
|
44
|
+
def getObjLocals(self):
|
|
45
|
+
return {
|
|
46
|
+
'en': self.en,
|
|
47
|
+
'un': self.un,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async def en(self, valu):
|
|
51
|
+
valu = await s_stormtypes.toprim(valu)
|
|
52
|
+
try:
|
|
53
|
+
return bz2.compress(valu)
|
|
54
|
+
except Exception as e:
|
|
55
|
+
mesg = f'Error during bzip2 compression - {str(e)}: {repr(valu)[:256]}'
|
|
56
|
+
raise s_exc.StormRuntimeError(mesg=mesg) from None
|
|
57
|
+
|
|
58
|
+
async def un(self, valu):
|
|
59
|
+
valu = await s_stormtypes.toprim(valu)
|
|
60
|
+
try:
|
|
61
|
+
return bz2.decompress(valu)
|
|
62
|
+
except Exception as e:
|
|
63
|
+
mesg = f'Error during bzip2 decompression - {str(e)}: {repr(valu)[:256]}'
|
|
64
|
+
raise s_exc.StormRuntimeError(mesg=mesg) from None
|
|
65
|
+
|
|
66
|
+
@s_stormtypes.registry.registerLib
|
|
67
|
+
class GzipLib(s_stormtypes.Lib):
|
|
68
|
+
'''
|
|
69
|
+
A Storm library which implements helpers for gzip compression.
|
|
70
|
+
'''
|
|
71
|
+
_storm_locals = (
|
|
72
|
+
{'name': 'en', 'desc': '''
|
|
73
|
+
Compress bytes using gzip and return them.
|
|
74
|
+
|
|
75
|
+
Example:
|
|
76
|
+
Compress bytes with gzip::
|
|
77
|
+
|
|
78
|
+
$foo = $lib.compression.gzip.en($mybytez)''',
|
|
79
|
+
'type': {'type': 'function', '_funcname': 'en',
|
|
80
|
+
'args': (
|
|
81
|
+
{'name': 'valu', 'type': 'bytes', 'desc': 'The bytes to be compressed.'},
|
|
82
|
+
),
|
|
83
|
+
'returns': {'type': 'bytes', 'desc': 'The gzip compressed bytes.'}}},
|
|
84
|
+
{'name': 'un', 'desc': '''
|
|
85
|
+
Decompress bytes using gzip and return them.
|
|
86
|
+
|
|
87
|
+
Example:
|
|
88
|
+
Decompress bytes with gzip::
|
|
89
|
+
|
|
90
|
+
$foo = $lib.compression.gzip.un($mybytez)''',
|
|
91
|
+
'type': {'type': 'function', '_funcname': 'un',
|
|
92
|
+
'args': (
|
|
93
|
+
{'name': 'valu', 'type': 'bytes', 'desc': 'The bytes to be decompressed.'},
|
|
94
|
+
),
|
|
95
|
+
'returns': {'type': 'bytes', 'desc': 'Decompressed bytes.'}}},
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
_storm_lib_path = ('compression', 'gzip')
|
|
99
|
+
|
|
100
|
+
def getObjLocals(self):
|
|
101
|
+
return {
|
|
102
|
+
'en': self.en,
|
|
103
|
+
'un': self.un,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async def en(self, valu):
|
|
107
|
+
valu = await s_stormtypes.toprim(valu)
|
|
108
|
+
try:
|
|
109
|
+
return gzip.compress(valu)
|
|
110
|
+
except Exception as e:
|
|
111
|
+
mesg = f'Error during gzip compression - {str(e)}: {repr(valu)[:256]}'
|
|
112
|
+
raise s_exc.StormRuntimeError(mesg=mesg) from None
|
|
113
|
+
|
|
114
|
+
async def un(self, valu):
|
|
115
|
+
valu = await s_stormtypes.toprim(valu)
|
|
116
|
+
try:
|
|
117
|
+
return gzip.decompress(valu)
|
|
118
|
+
except Exception as e:
|
|
119
|
+
mesg = f'Error during gzip decompression - {str(e)}: {repr(valu)[:256]}'
|
|
120
|
+
raise s_exc.StormRuntimeError(mesg=mesg) from None
|
|
121
|
+
|
|
122
|
+
@s_stormtypes.registry.registerLib
|
|
123
|
+
class ZlibLib(s_stormtypes.Lib):
|
|
124
|
+
'''
|
|
125
|
+
A Storm library which implements helpers for zlib compression.
|
|
126
|
+
'''
|
|
127
|
+
_storm_locals = (
|
|
128
|
+
{'name': 'en', 'desc': '''
|
|
129
|
+
Compress bytes using zlib and return them.
|
|
130
|
+
|
|
131
|
+
Example:
|
|
132
|
+
Compress bytes with zlib::
|
|
133
|
+
|
|
134
|
+
$foo = $lib.compression.zlib.en($mybytez)''',
|
|
135
|
+
'type': {'type': 'function', '_funcname': 'en',
|
|
136
|
+
'args': (
|
|
137
|
+
{'name': 'valu', 'type': 'bytes', 'desc': 'The bytes to be compressed.'},
|
|
138
|
+
),
|
|
139
|
+
'returns': {'type': 'bytes', 'desc': 'The zlib compressed bytes.'}}},
|
|
140
|
+
{'name': 'un', 'desc': '''
|
|
141
|
+
Decompress bytes using zlib and return them.
|
|
142
|
+
|
|
143
|
+
Example:
|
|
144
|
+
Decompress bytes with zlib::
|
|
145
|
+
|
|
146
|
+
$foo = $lib.compression.zlib.un($mybytez)''',
|
|
147
|
+
'type': {'type': 'function', '_funcname': 'un',
|
|
148
|
+
'args': (
|
|
149
|
+
{'name': 'valu', 'type': 'bytes', 'desc': 'The bytes to be decompressed.'},
|
|
150
|
+
),
|
|
151
|
+
'returns': {'type': 'bytes', 'desc': 'Decompressed bytes.'}}},
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
_storm_lib_path = ('compression', 'zlib')
|
|
155
|
+
|
|
156
|
+
def getObjLocals(self):
|
|
157
|
+
return {
|
|
158
|
+
'en': self.en,
|
|
159
|
+
'un': self.un,
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async def en(self, valu):
|
|
163
|
+
valu = await s_stormtypes.toprim(valu)
|
|
164
|
+
try:
|
|
165
|
+
return zlib.compress(valu)
|
|
166
|
+
except Exception as e:
|
|
167
|
+
mesg = f'Error during zlib compression - {str(e)}: {repr(valu)[:256]}'
|
|
168
|
+
raise s_exc.StormRuntimeError(mesg=mesg) from None
|
|
169
|
+
|
|
170
|
+
async def un(self, valu):
|
|
171
|
+
valu = await s_stormtypes.toprim(valu)
|
|
172
|
+
try:
|
|
173
|
+
return zlib.decompress(valu)
|
|
174
|
+
except Exception as e:
|
|
175
|
+
mesg = f'Error during zlib decompression - {str(e)}: {repr(valu)[:256]}'
|
|
176
|
+
raise s_exc.StormRuntimeError(mesg=mesg) from None
|
synapse/lib/stormlib/graph.py
CHANGED