synapse 2.135.0__py310-none-any.whl → 2.136.0__py310-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.

@@ -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
@@ -88,6 +88,8 @@ class GraphLib(s_stormtypes.Lib):
88
88
  Add a graph projection to the Cortex.
89
89
 
90
90
  Example:
91
+ Add a graph projection named "Test Projection"::
92
+
91
93
  $rules = ({
92
94
  "name": "Test Projection",
93
95
  "desc": "My test projection",
synapse/lib/stormtypes.py CHANGED
@@ -953,7 +953,6 @@ class LibTags(Lib):
953
953
  Normalize and prefix a list of syn:tag:part values so they can be applied.
954
954
 
955
955
  Examples:
956
-
957
956
  Add tag prefixes and then use them to tag nodes::
958
957
 
959
958
  $tags = $lib.tags.prefix($result.tags, vtx.visi)
@@ -4059,6 +4058,7 @@ class Bytes(Prim):
4059
4058
 
4060
4059
  Example:
4061
4060
  Compress bytes with gzip::
4061
+
4062
4062
  $foo = $mybytez.gzip()''',
4063
4063
  'type': {'type': 'function', '_funcname': '_methGzip',
4064
4064
  'returns': {'type': 'bytes', 'desc': 'The gzip compressed bytes.', }}},
@@ -4070,6 +4070,7 @@ class Bytes(Prim):
4070
4070
 
4071
4071
  Example:
4072
4072
  Load bytes to a object::
4073
+
4073
4074
  $foo = $mybytez.json()''',
4074
4075
  'type': {'type': 'function', '_funcname': '_methJsonLoad',
4075
4076
  'args': (
@@ -4103,8 +4104,9 @@ class Bytes(Prim):
4103
4104
  Unpack structures from bytes using python struct.unpack syntax.
4104
4105
 
4105
4106
  Examples:
4106
- # unpack 3 unsigned 16 bit integers in little endian format
4107
- ($x, $y, $z) = $byts.unpack("<HHH")
4107
+ Unpack 3 unsigned 16 bit integers in little endian format::
4108
+
4109
+ ($x, $y, $z) = $byts.unpack("<HHH")
4108
4110
  ''',
4109
4111
  'type': {'type': 'function', '_funcname': 'unpack',
4110
4112
  'args': (
@@ -6338,7 +6340,7 @@ class Layer(Prim):
6338
6340
  formname = await tostr(formname, noneok=True)
6339
6341
 
6340
6342
  if formname is not None and self.runt.snap.core.model.form(formname) is None:
6341
- raise s_exc.NoSuchForm(formname)
6343
+ raise s_exc.NoSuchForm.init(formname)
6342
6344
 
6343
6345
  iden = self.valu.get('iden')
6344
6346
  layr = self.runt.snap.core.getLayer(iden)
@@ -7421,8 +7423,8 @@ class LibUsers(Lib):
7421
7423
  'type': {'type': 'function', '_funcname': '_methUsersAdd',
7422
7424
  'args': (
7423
7425
  {'name': 'name', 'type': 'str', 'desc': 'The name of the user.', },
7424
- {'name': 'passwd', 'type': 'str', 'desc': 'The users password.', 'default': None, },
7425
- {'name': 'email', 'type': 'str', 'desc': 'The users email address.', 'default': None, },
7426
+ {'name': 'passwd', 'type': 'str', 'desc': "The user's password.", 'default': None, },
7427
+ {'name': 'email', 'type': 'str', 'desc': "The user's email address.", 'default': None, },
7426
7428
  {'name': 'iden', 'type': 'str', 'desc': 'The iden to use to create the user.', 'default': None, }
7427
7429
  ),
7428
7430
  'returns': {'type': 'storm:auth:user',
@@ -8183,20 +8185,20 @@ class User(Prim):
8183
8185
  'returns': {'type': 'list',
8184
8186
  'desc': 'A list of ``storm:auth:gates`` that the user has rules for.', }}},
8185
8187
  {'name': 'name', 'desc': '''
8186
- A users name. This can also be used to set a users name.
8188
+ A user's name. This can also be used to set a user's name.
8187
8189
 
8188
8190
  Example:
8189
- Change a users name::
8191
+ Change a user's name::
8190
8192
 
8191
8193
  $user=$lib.auth.users.byname(bob) $user.name=robert
8192
8194
  ''',
8193
8195
  'type': {'type': 'stor', '_storfunc': '_storUserName',
8194
8196
  'returns': {'type': 'str', }}},
8195
8197
  {'name': 'email', 'desc': '''
8196
- A users email. This can also be used to set the users email.
8198
+ A user's email. This can also be used to set the user's email.
8197
8199
 
8198
8200
  Example:
8199
- Change a users email address::
8201
+ Change a user's email address::
8200
8202
 
8201
8203
  $user=$lib.auth.users.byname(bob) $user.email="robert@bobcorp.net"
8202
8204
  ''',
@@ -8491,10 +8493,10 @@ class Role(Prim):
8491
8493
  ),
8492
8494
  'returns': {'type': 'null', }}},
8493
8495
  {'name': 'name', 'desc': '''
8494
- A roles name. This can also be used to set the role name.
8496
+ A role's name. This can also be used to set the role name.
8495
8497
 
8496
8498
  Example:
8497
- Change a roles name::
8499
+ Change a role's name::
8498
8500
 
8499
8501
  $role=$lib.auth.roles.byname(analyst) $role.name=superheroes
8500
8502
  ''',
synapse/lib/types.py CHANGED
@@ -385,7 +385,7 @@ class Bool(Type):
385
385
  return int(bool(valu)), {}
386
386
 
387
387
  def repr(self, valu):
388
- return repr(bool(valu))
388
+ return repr(bool(valu)).lower()
389
389
 
390
390
  class Array(Type):
391
391
 
@@ -1732,6 +1732,9 @@ class Taxonomy(Str):
1732
1732
  def _normPyStr(self, text):
1733
1733
  return self._normPyList(text.strip().strip('.').split('.'))
1734
1734
 
1735
+ def repr(self, norm):
1736
+ return norm.rstrip('.')
1737
+
1735
1738
  class Tag(Str):
1736
1739
 
1737
1740
  def postTypeInit(self):
synapse/lib/version.py CHANGED
@@ -223,6 +223,6 @@ def reqVersion(valu, reqver,
223
223
  ##############################################################################
224
224
  # The following are touched during the release process by bumpversion.
225
225
  # Do not modify these directly.
226
- version = (2, 135, 0)
226
+ version = (2, 136, 0)
227
227
  verstring = '.'.join([str(x) for x in version])
228
- commit = 'b57446b7668e6dcaced257b82fd2bb1a11ece8ce'
228
+ commit = 'dba42be36057d465def6a8f17294aac3677a161e'
@@ -1196,6 +1196,10 @@ class CortexTest(s_t_utils.SynTest):
1196
1196
  self.len(1, await core.nodes('test:int +#foo.bar:score<=30'))
1197
1197
  self.len(1, await core.nodes('test:int +#foo.bar:score>=10'))
1198
1198
  self.len(1, await core.nodes('test:int +#foo.bar:score*range=(10, 30)'))
1199
+ self.len(1, await core.nodes('test:int +#*:score'))
1200
+ self.len(1, await core.nodes('test:int +#foo.*:score'))
1201
+ self.len(1, await core.nodes('$tag=* test:int +#*:score'))
1202
+ self.len(1, await core.nodes('$tag=foo.* test:int +#foo.*:score'))
1199
1203
 
1200
1204
  self.len(0, await core.nodes('test:int -#foo.bar'))
1201
1205
  self.len(0, await core.nodes('test:int -#foo.bar:score'))
@@ -1317,6 +1321,24 @@ class CortexTest(s_t_utils.SynTest):
1317
1321
  with self.raises(s_exc.NoSuchType):
1318
1322
  await core.addTagProp('derp', ('derp', {}), {})
1319
1323
 
1324
+ with self.raises(s_exc.BadTypeValu):
1325
+ await core.nodes("$tag=(foo, bar) test:int#$tag:prop")
1326
+
1327
+ with self.raises(s_exc.BadTypeValu):
1328
+ await core.nodes("$tag=(foo, bar) test:int +#$tag:prop")
1329
+
1330
+ with self.raises(s_exc.BadTypeValu):
1331
+ await core.nodes("$tag=(foo, bar) test:int +#$tag:prop=5")
1332
+
1333
+ with self.raises(s_exc.BadTypeValu):
1334
+ await core.nodes("test:int $tag=(foo, bar) $lib.print(#$tag:prop)")
1335
+
1336
+ with self.raises(s_exc.BadTypeValu):
1337
+ await core.nodes("test:int $tag=(foo, bar) [ +#$tag:prop=foo ]")
1338
+
1339
+ with self.raises(s_exc.BadTypeValu):
1340
+ await core.nodes("test:int $tag=(foo, bar) [ -#$tag:prop ]")
1341
+
1320
1342
  # Ensure that the tagprops persist
1321
1343
  async with self.getTestCore(dirn=dirn) as core:
1322
1344
  # Ensure we can still work with a tagprop, after restart, that was
@@ -1496,7 +1518,7 @@ class CortexTest(s_t_utils.SynTest):
1496
1518
  self.eq(set(nodes[0].tags.keys()), {'foo', 'foo.v'})
1497
1519
 
1498
1520
  # Cannot norm a list of tag parts directly when making tags on a node
1499
- with self.raises(AttributeError):
1521
+ with self.raises(s_exc.BadTypeValu):
1500
1522
  await wcore.nodes("$foo=(('foo', 'bar.baz'),) [test:int=2 +#$foo]")
1501
1523
 
1502
1524
  # Can set a list of tags directly
@@ -1508,8 +1530,20 @@ class CortexTest(s_t_utils.SynTest):
1508
1530
  self.len(1, nodes)
1509
1531
  self.eq(set(nodes[0].tags.keys()), {'foo', 'bar', 'bar.baz'})
1510
1532
 
1511
- with self.raises(TypeError):
1512
- await wcore.nodes('$foo=$lib.set("foo", "bar") [test:int=5 +#$foo]')
1533
+ nodes = await wcore.nodes('$foo=$lib.set("foo", "bar") [test:int=5 +#$foo]')
1534
+ self.len(1, nodes)
1535
+ self.eq(set(nodes[0].tags.keys()), {'foo', 'bar'})
1536
+
1537
+ await self.asyncraises(s_exc.BadTypeValu, wcore.nodes("$tag='' #$tag"))
1538
+ await self.asyncraises(s_exc.BadTypeValu, wcore.nodes("$tag='' #$tag=2020"))
1539
+ await self.asyncraises(s_exc.BadTypeValu, wcore.nodes("$tag=$lib.null #foo.$tag"))
1540
+ await self.asyncraises(s_exc.BadTypeValu, wcore.nodes("$tag=(foo, bar) #$tag"))
1541
+ await self.asyncraises(s_exc.BadTypeValu, wcore.nodes("$tag=(foo, bar) ##$tag"))
1542
+ await self.asyncraises(s_exc.BadTypeValu, wcore.nodes("$tag=(foo, bar) inet:fqdn#$tag"))
1543
+ await self.asyncraises(s_exc.BadTypeValu, wcore.nodes("test:int $tag=$lib.null +#foo.$tag"))
1544
+ await self.asyncraises(s_exc.BadTypeValu, wcore.nodes("test:int $tag=(foo, bar) $lib.print(#$tag)"))
1545
+ await self.asyncraises(s_exc.BadTypeValu, wcore.nodes("test:int $tag=(foo, bar) +#$tag"))
1546
+ await self.asyncraises(s_exc.BadTypeValu, wcore.nodes("test:int $tag=(foo, bar) +#$tag=2020"))
1513
1547
 
1514
1548
  async def test_base_types1(self):
1515
1549
 
@@ -4907,7 +4941,7 @@ class CortexBasicTest(s_t_utils.SynTest):
4907
4941
  pode = podes[0]
4908
4942
  self.true(s_node.tagged(pode, '#foo'))
4909
4943
 
4910
- mesgs = await core.stormlist('$var="" test:str=foo [+?#$var=2019] $lib.print(#$var)')
4944
+ mesgs = await core.stormlist('$var="" test:str=foo [+?#$var=2019]')
4911
4945
  podes = [m[1] for m in mesgs if m[0] == 'node']
4912
4946
  self.len(1, podes)
4913
4947
  pode = podes[0]