Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #5
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['UnauthenticateCommand', memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemple #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
Exemple #7
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[StartTLSCommand, memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemple #8
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[UnauthenticateCommand, memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemple #9
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['StartTLSCommand', memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemple #10
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[CapabilityCommand, memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemple #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
Exemple #12
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['ListScriptsCommand', memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #18
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple[ListScriptsCommand, memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf
Exemple #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)
Exemple #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
Exemple #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
Exemple #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
Exemple #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)
Exemple #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())
Exemple #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))
Exemple #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())
Exemple #27
0
 def parse(cls, buf: memoryview, params: Params) \
         -> Tuple['CapabilityCommand', memoryview]:
     _, buf = EndLine.parse(buf, params)
     return cls(), buf