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
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
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
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
def parse(cls, buf: memoryview, params: Params) \ -> Tuple['UnauthenticateCommand', memoryview]: _, buf = EndLine.parse(buf, params) return cls(), buf
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
def parse(cls, buf: memoryview, params: Params) \ -> Tuple[StartTLSCommand, memoryview]: _, buf = EndLine.parse(buf, params) return cls(), buf
def parse(cls, buf: memoryview, params: Params) \ -> Tuple[UnauthenticateCommand, memoryview]: _, buf = EndLine.parse(buf, params) return cls(), buf
def parse(cls, buf: memoryview, params: Params) \ -> Tuple['StartTLSCommand', memoryview]: _, buf = EndLine.parse(buf, params) return cls(), buf
def parse(cls, buf: memoryview, params: Params) \ -> Tuple[CapabilityCommand, memoryview]: _, buf = EndLine.parse(buf, params) return cls(), buf
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
def parse(cls, buf: memoryview, params: Params) \ -> Tuple['ListScriptsCommand', memoryview]: _, buf = EndLine.parse(buf, params) return cls(), buf
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
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
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
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
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
def parse(cls, buf: memoryview, params: Params) \ -> Tuple[ListScriptsCommand, memoryview]: _, buf = EndLine.parse(buf, params) return cls(), buf
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)
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
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
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
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())
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))
def parse(cls, buf: memoryview, params: Params) \ -> Tuple['CapabilityCommand', memoryview]: _, buf = EndLine.parse(buf, params) return cls(), buf