synapse 2.219.0__py311-none-any.whl → 2.220.0__py311-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.

@@ -1,9 +1,9 @@
1
1
  import lark # type: ignore
2
2
 
3
3
  import synapse.exc as s_exc
4
+ import synapse.data as s_data
4
5
 
5
6
  import synapse.lib.parser as s_parser
6
- import synapse.lib.datfile as s_datfile
7
7
  import synapse.lib.grammar as s_grammar
8
8
 
9
9
  import synapse.tests.utils as s_t_utils
@@ -1414,9 +1414,7 @@ class GrammarTest(s_t_utils.SynTest):
1414
1414
  '''
1415
1415
  Validates that we have no grammar ambiguities
1416
1416
  '''
1417
- with s_datfile.openDatFile('synapse.lib/storm.lark') as larkf:
1418
- grammar = larkf.read().decode()
1419
-
1417
+ grammar = s_data.getLark('storm')
1420
1418
  parser = lark.Lark(grammar, start='query', debug=True, regex=True, parser='lalr',
1421
1419
  keep_all_tokens=True, maybe_placeholders=False,
1422
1420
  propagate_positions=True)
@@ -125,6 +125,35 @@ class JsonTest(s_test.SynTest):
125
125
 
126
126
  self.eq(valu, s_json.loads(s_json.dumps(valu)))
127
127
 
128
+ async def test_lib_json_control_strings(self):
129
+ valus = [
130
+ 'line1"line2',
131
+ 'line1/line2',
132
+ 'line1\\line2',
133
+ 'line1\bline2',
134
+ 'line1\fline2',
135
+ 'line1\nline2',
136
+ 'line1\rline2',
137
+ 'line1\tline2',
138
+ 'line1\u0009line2',
139
+ 'line1\u1000line2',
140
+ 'line1\u2000line2',
141
+ 'line1\u3000line2',
142
+ ]
143
+
144
+ with self.getLoggerStream('synapse.lib.json') as stream:
145
+ async with self.getTestCore() as core:
146
+ for valu in valus:
147
+ q = '$lib.print($valu) $lib.print($lib.json.save($valu))'
148
+ msgs = await core.stormlist(q, opts={'vars': {'valu': valu}})
149
+ self.stormHasNoWarnErr(msgs)
150
+
151
+ self.eq(s_json.loads(s_json.dumps(valu)), valu)
152
+
153
+ stream.seek(0)
154
+ data = stream.read()
155
+ self.notin('fallback JSON', data)
156
+
128
157
  async def test_jsload(self):
129
158
  with self.getTestDir() as dirn:
130
159
  with s_common.genfile(dirn, 'jsload.json') as fp:
@@ -732,13 +732,17 @@ class StormTest(s_t_utils.SynTest):
732
732
  [(ou:org=* :names=(foo, baz))]
733
733
  [(ou:org=* :names=(foo, hehe))]
734
734
  ''')
735
- nodes = await core.nodes('ou:org | intersect { -> ou:name }')
735
+ nodes = await core.nodes('ou:org | intersect { -> ou:name }', opts={'readonly': True})
736
736
  self.len(1, nodes)
737
737
  self.eq(nodes[0].ndef[1], 'foo')
738
738
 
739
739
  msgs = await core.stormlist('ou:org $foo=$node.value() | intersect $foo')
740
740
  self.stormIsInErr('intersect arguments must be runtsafe', msgs)
741
741
 
742
+ with self.raises(s_exc.IsReadOnly) as exc:
743
+ await core.nodes('ou:org | intersect { [ou:org=*] }', opts={'readonly': True})
744
+ self.eq(exc.exception.get('mesg'), 'Storm runtime is in readonly mode, cannot create or edit nodes and other graph data.')
745
+
742
746
  async def test_lib_storm_trycatch(self):
743
747
 
744
748
  async with self.getTestCore() as core: