Skip to content

Instantly share code, notes, and snippets.

@FurryHead
Created June 24, 2011 16:58
Show Gist options
  • Save FurryHead/1045197 to your computer and use it in GitHub Desktop.
Save FurryHead/1045197 to your computer and use it in GitHub Desktop.
Class user to parse raw irc user chunk.
class User(str):
def __new__(cls, user):
if getattr(user, "nick", None) is not None:
cls.nick = user.nick
cls.ident = user.ident
cls.host = user.host
else:
if re.match(".+!.+@.+", user):
cls.nick = user.split("!")[0]
cls.ident = user.split("!")[1].split("@")[0]
cls.host = user.split("!")[1].split("@")[1]
else:
cls.nick = user
cls.ident = ""
cls.host = ""
return str.__new__(cls, cls.nick)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment