Skip to content

Instantly share code, notes, and snippets.

@nitori
Created March 13, 2016 07:55
Show Gist options
  • Save nitori/3e9dfb6a3aa13801c443 to your computer and use it in GitHub Desktop.
Save nitori/3e9dfb6a3aa13801c443 to your computer and use it in GitHub Desktop.
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