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.

synapse/data/__init__.py CHANGED
@@ -29,5 +29,9 @@ def getJSON(name):
29
29
  with s_datfile.openDatFile(f'synapse.data/{name}.json') as fd:
30
30
  return s_json.load(fd)
31
31
 
32
+ def getLark(name):
33
+ with s_datfile.openDatFile(f'synapse.data.lark/{name}.lark') as larkf:
34
+ return larkf.read().decode()
35
+
32
36
  def path(*names):
33
37
  return s_common.genpath(dirname, *names)
File without changes
@@ -0,0 +1,8 @@
1
+ UNQUOTED_CHAR: /(?!\r|\n|\\"|\\\\)./
2
+ QUOTED_SPECIALS: "\"" | "\\"
3
+
4
+ QUOTED_CHAR: /(?!\r|\n|\\|\")./
5
+ quoted: "\"" (QUOTED_CHAR | "\\" QUOTED_SPECIALS)* "\""
6
+ unquoted: UNQUOTED_CHAR+
7
+ _string: quoted | unquoted
8
+ input: (_string " ")* _string
synapse/exc.py CHANGED
@@ -216,6 +216,8 @@ class DupEdgeType(SynErr):
216
216
 
217
217
  class FileExists(SynErr): pass
218
218
 
219
+ class ImapError(SynErr): pass
220
+
219
221
  class InconsistentStorage(SynErr):
220
222
  '''
221
223
  Stored persistent data is inconsistent
synapse/lib/json.py CHANGED
@@ -88,12 +88,13 @@ def _dumps(obj, sort_keys=False, indent=False, default=None, newline=False):
88
88
  mesg = 'Object of type bytes is not JSON serializable'
89
89
  raise s_exc.MustBeJsonSafe(mesg=mesg)
90
90
 
91
- # Raw strings have to be double-quoted. This is because the default behavior for `yyjson.Document`
92
- # is to attempt to parse the string as a serialized JSON string into objects, so we escape string
93
- # values so we can get the JSON encoded string as output.
94
91
  if isinstance(obj, str) and obj not in ('null', 'true', 'false'):
95
- # TODO in 3xx convert this into obj = f'''"{obj.replace('"', '\\"')}"'''
96
- obj = ''.join(('"', obj.replace('"', '\\"'), '"'))
92
+ # Raw strings have to be double-quoted. This is because the default behavior for `yyjson.Document` is to attempt
93
+ # to parse the string as a serialized JSON string into objects. Instead of trying to manually escape the string,
94
+ # we wrap it in a list, serialize it, and then strip off the leading/trailing [] so we can get the JSON encoded
95
+ # string as output.
96
+ doc = yyjson.Document([obj], default=default, flags=rflags)
97
+ return doc.dumps(flags=wflags)[1:-1].encode()
97
98
 
98
99
  doc = yyjson.Document(obj, default=default, flags=rflags)
99
100
  return doc.dumps(flags=wflags).encode()
synapse/lib/link.py CHANGED
@@ -18,34 +18,6 @@ import synapse.lib.msgpack as s_msgpack
18
18
  READSIZE = 16 * s_const.mebibyte
19
19
  MAXWRITE = 64 * s_const.mebibyte
20
20
 
21
- async def connect(host, port, ssl=None, hostname=None, linkinfo=None):
22
- '''
23
- Async connect and return a Link().
24
- '''
25
- info = {'host': host, 'port': port, 'ssl': ssl, 'hostname': hostname, 'tls': bool(ssl)}
26
- if linkinfo is not None:
27
- info.update(linkinfo)
28
-
29
- ssl = info.get('ssl')
30
- hostname = info.get('hostname')
31
-
32
- reader, writer = await asyncio.open_connection(host, port, ssl=ssl, server_hostname=hostname)
33
- return await Link.anit(reader, writer, info=info)
34
-
35
- async def listen(host, port, onlink, ssl=None):
36
- '''
37
- Listen on the given host/port and fire onlink(Link).
38
-
39
- Returns a server object that contains the listening sockets
40
- '''
41
- async def onconn(reader, writer):
42
- info = {'tls': bool(ssl)}
43
- link = await Link.anit(reader, writer, info=info)
44
- link.schedCoro(onlink(link))
45
-
46
- server = await asyncio.start_server(onconn, host=host, port=port, ssl=ssl)
47
- return server
48
-
49
21
  async def unixlisten(path, onlink):
50
22
  '''
51
23
  Start an PF_UNIX server listening on the given path.
@@ -247,30 +219,9 @@ class Link(s_base.Base):
247
219
  offs = 0
248
220
  size = len(byts)
249
221
 
250
- async with self._txlock:
251
-
252
- while offs < size:
253
-
254
- self.writer.write(byts[offs:offs + MAXWRITE])
255
- offs += MAXWRITE
256
-
257
- await self.writer.drain()
258
-
259
- async def tx(self, mesg):
260
- '''
261
- Async transmit routine which will wait for writer drain().
262
- '''
263
- if self.isfini:
264
- raise s_exc.IsFini()
265
-
266
- offs = 0
267
- byts = s_msgpack.en(mesg)
268
- size = len(byts)
269
-
270
222
  async with self._txlock:
271
223
 
272
224
  try:
273
-
274
225
  while offs < size:
275
226
 
276
227
  self.writer.write(byts[offs:offs + MAXWRITE])
@@ -287,6 +238,16 @@ class Link(s_base.Base):
287
238
 
288
239
  raise
289
240
 
241
+ async def tx(self, mesg):
242
+ '''
243
+ Async transmit routine which will wait for writer drain().
244
+ '''
245
+ if self.isfini:
246
+ raise s_exc.IsFini()
247
+
248
+ byts = await self.pack(mesg)
249
+ await self.send(byts)
250
+
290
251
  def txfini(self):
291
252
  self.sock.shutdown(1)
292
253
 
@@ -353,6 +314,44 @@ class Link(s_base.Base):
353
314
 
354
315
  def feed(self, byts):
355
316
  '''
356
- Used by Plex() to unpack bytes.
317
+ Used by rx() to unpack messages from bytes.
357
318
  '''
358
319
  return self.unpk.feed(byts)
320
+
321
+ async def pack(self, mesg):
322
+ '''
323
+ Used by tx() to pack messages into bytes
324
+ '''
325
+ return s_msgpack.en(mesg)
326
+
327
+ async def connect(host, port, ssl=None, hostname=None, linkinfo=None, linkcls=Link):
328
+ '''
329
+ Async connect and return a <linkcls>.
330
+ '''
331
+ assert issubclass(linkcls, Link)
332
+
333
+ info = {'host': host, 'port': port, 'ssl': ssl, 'hostname': hostname, 'tls': bool(ssl)}
334
+ if linkinfo is not None:
335
+ info.update(linkinfo)
336
+
337
+ ssl = info.get('ssl')
338
+ hostname = info.get('hostname')
339
+
340
+ reader, writer = await asyncio.open_connection(host, port, ssl=ssl, server_hostname=hostname)
341
+ return await linkcls.anit(reader, writer, info=info)
342
+
343
+ async def listen(host, port, onlink, ssl=None, linkcls=Link):
344
+ '''
345
+ Listen on the given host/port and fire onlink(<linkcls>).
346
+
347
+ Returns a server object that contains the listening sockets
348
+ '''
349
+ assert issubclass(linkcls, Link)
350
+
351
+ async def onconn(reader, writer):
352
+ info = {'tls': bool(ssl)}
353
+ link = await linkcls.anit(reader, writer, info=info)
354
+ link.schedCoro(onlink(link))
355
+
356
+ server = await asyncio.start_server(onconn, host=host, port=port, ssl=ssl)
357
+ return server
synapse/lib/parser.py CHANGED
@@ -6,16 +6,16 @@ import lark # type: ignore
6
6
  import regex # type: ignore
7
7
 
8
8
  import synapse.exc as s_exc
9
+ import synapse.data as s_data
9
10
  import synapse.common as s_common
10
11
 
11
12
  import synapse.lib.ast as s_ast
12
13
  import synapse.lib.coro as s_coro
13
14
  import synapse.lib.cache as s_cache
14
- import synapse.lib.datfile as s_datfile
15
15
 
16
16
  # TL;DR: *rules* are the internal nodes of an abstract syntax tree (AST), *terminals* are the leaves
17
17
 
18
- # Note: this file is coupled strongly to synapse/lib/storm.lark. Any changes to that file will probably require
18
+ # Note: this file is coupled strongly to synapse/data/lark/storm.lark. Any changes to that file will probably require
19
19
  # changes here
20
20
 
21
21
  # For easier-to-understand syntax errors
@@ -475,9 +475,7 @@ class AstConverter(lark.Transformer):
475
475
  kids[0].reverseLift(astinfo)
476
476
  return kids[0]
477
477
 
478
- with s_datfile.openDatFile('synapse.lib/storm.lark') as larkf:
479
- _grammar = larkf.read().decode()
480
-
478
+ _grammar = s_data.getLark('storm')
481
479
  LarkParser = lark.Lark(_grammar, regex=True, start=['query', 'lookup', 'cmdrargs', 'evalvalu', 'search'],
482
480
  maybe_placeholders=False, propagate_positions=True, parser='lalr')
483
481
 
synapse/lib/storm.py CHANGED
@@ -5796,6 +5796,7 @@ class IntersectCmd(Cmd):
5796
5796
  it:mitre:attack:group*in=(G0006, G0007) | intersect { -> it:mitre:attack:technique }
5797
5797
  '''
5798
5798
  name = 'intersect'
5799
+ readonly = True
5799
5800
 
5800
5801
  def getArgParser(self):
5801
5802
  pars = Cmd.getArgParser(self)