Exemplo n.º 1
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['HaveSpaceCommand', memoryview]:
     script_name, after = cls._parse_script_name(buf, params)
     if not script_name:
         raise NotParseable(buf)
     size, buf = Number.parse(after, params)
     _, buf = EndLine.parse(buf, params)
     return cls(script_name, size.value), buf
Exemplo n.º 2
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[HaveSpaceCommand, memoryview]:
     script_name, after = cls._parse_script_name(buf, params)
     if not script_name:
         raise NotParseable(buf)
     size, buf = Number.parse(after, params)
     _, buf = EndLine.parse(buf, params)
     return cls(script_name, size.value), buf
Exemplo n.º 3
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['NoOpCommand', memoryview]:
     whitespace = cls._whitespace_length(buf)
     tag: Optional[bytes] = None
     if whitespace > 0:
         buf = buf[whitespace:]
         try:
             tag_obj, buf = String.parse(buf, params)
         except NotParseable:
             pass
         else:
             tag = tag_obj.value
     _, buf = EndLine.parse(buf, params)
     return cls(tag), buf
Exemplo n.º 4
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[NoOpCommand, memoryview]:
     whitespace = cls._whitespace_length(buf)
     tag: Optional[bytes] = None
     if whitespace > 0:
         buf = buf[whitespace:]
         try:
             tag_obj, buf = String.parse(buf, params)
         except NotParseable:
             pass
         else:
             tag = tag_obj.value
     _, buf = EndLine.parse(buf, params)
     return cls(tag), buf
Exemplo n.º 5
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['UnauthenticateCommand', memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemplo n.º 6
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[PutScriptCommand, memoryview]:
     script_name, buf = cls._parse_script_name(buf, params)
     script_data, buf = String.parse(buf, params)
     _, buf = EndLine.parse(buf, params)
     return cls(script_name, script_data.value), buf
Exemplo n.º 7
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[StartTLSCommand, memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemplo n.º 8
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[UnauthenticateCommand, memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemplo n.º 9
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['StartTLSCommand', memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemplo n.º 10
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[CapabilityCommand, memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemplo n.º 11
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[CheckScriptCommand, memoryview]:
     script_data, buf = String.parse(buf, params)
     _, buf = EndLine.parse(buf, params)
     return cls(script_data.value), buf
Exemplo n.º 12
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['ListScriptsCommand', memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemplo n.º 13
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['CheckScriptCommand', memoryview]:
     script_data, buf = String.parse(buf, params)
     _, buf = EndLine.parse(buf, params)
     return cls(script_data.value), buf
Exemplo n.º 14
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[DeleteScriptCommand, memoryview]:
     script_name, buf = cls._parse_script_name(buf, params)
     _, buf = EndLine.parse(buf, params)
     return cls(script_name), buf
Exemplo n.º 15
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['RenameScriptCommand', memoryview]:
     old_script_name, buf = cls._parse_script_name(buf, params)
     new_script_name, buf = cls._parse_script_name(buf, params)
     _, buf = EndLine.parse(buf, params)
     return cls(old_script_name, new_script_name), buf
Exemplo n.º 16
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['DeleteScriptCommand', memoryview]:
     script_name, buf = cls._parse_script_name(buf, params)
     _, buf = EndLine.parse(buf, params)
     return cls(script_name), buf
Exemplo n.º 17
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['SetActiveCommand', memoryview]:
     script_name, buf = cls._parse_script_name(buf, params, True)
     _, buf = EndLine.parse(buf, params)
     return cls(script_name or None), buf
Exemplo n.º 18
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[ListScriptsCommand, memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemplo n.º 19
0
 def test_parse_no_cr(self):
     ret, buf = EndLine.parse(b'  \n', Params())
     self.assertIsInstance(ret, EndLine)
     self.assertEqual(2, ret.preceding_spaces)
     self.assertFalse(ret.carriage_return)
Exemplo n.º 20
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[SetActiveCommand, memoryview]:
     script_name, buf = cls._parse_script_name(buf, params, True)
     _, buf = EndLine.parse(buf, params)
     return cls(script_name or None), buf
Exemplo n.º 21
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['PutScriptCommand', memoryview]:
     script_name, buf = cls._parse_script_name(buf, params)
     script_data, buf = String.parse(buf, params)
     _, buf = EndLine.parse(buf, params)
     return cls(script_name, script_data.value), buf
Exemplo n.º 22
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[RenameScriptCommand, memoryview]:
     old_script_name, buf = cls._parse_script_name(buf, params)
     new_script_name, buf = cls._parse_script_name(buf, params)
     _, buf = EndLine.parse(buf, params)
     return cls(old_script_name, new_script_name), buf
Exemplo n.º 23
0
 def test_parse_no_cr(self):
     ret, buf = EndLine.parse(b'  \n', Params())
     self.assertIsInstance(ret, EndLine)
     self.assertEqual(2, ret.preceding_spaces)
     self.assertFalse(ret.carriage_return)
Exemplo n.º 24
0
 def test_parse_failure(self):
     with self.assertRaises(NotParseable):
         EndLine.parse(b'  \r', Params())
     with self.assertRaises(NotParseable):
         EndLine.parse(b' test \r\n', Params())
Exemplo n.º 25
0
 def test_bytes(self):
     endl1 = EndLine(4, True)
     self.assertEqual(b'    \r\n', bytes(endl1))
     endl2 = EndLine(0, False)
     self.assertEqual(b'\n', bytes(endl2))
Exemplo n.º 26
0
 def test_parse_failure(self):
     with self.assertRaises(NotParseable):
         EndLine.parse(b'  \r', Params())
     with self.assertRaises(NotParseable):
         EndLine.parse(b' test \r\n', Params())
Exemplo n.º 27
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['CapabilityCommand', memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf