Created
March 13, 2016 07:55
-
-
Save nitori/3e9dfb6a3aa13801c443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Message: | |
def __init__(self, command, params, trailing, prefix=None, raw_line=None): | |
self.prefix = prefix | |
self.command = command.upper() | |
self.params = params | |
self.trailing = trailing | |
self._raw_line = raw_line | |
@property | |
def all_params(self): | |
if self.trailing is not None: | |
return self.params + [self.trailing] | |
return self.params | |
@classmethod | |
def from_line(cls, line): | |
raw_line = line | |
prefix = None | |
if line.startswith(':'): | |
prefix, line = line[1:].split(None, 1) | |
command, line = line.split(None, 1) | |
if ' :' in line: | |
params, trailing = line.split(' :', 1) | |
else: | |
params, trailing = line, None | |
params = params.split() | |
return cls(command, params, trailing, prefix=prefix, raw_line=raw_line) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment