repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
Shizmob/pydle
pydle/features/ircv3/metadata.py
MetadataSupport.on_raw_765
async def on_raw_765(self, message): """ Invalid metadata target. """ target, targetmeta = self._parse_user(message.params[0]) if target not in self._pending['metadata']: return if target in self.users: self._sync_user(target, targetmeta) self._metadata_queue.remove(target) del self._metadata_info[target] future = self._pending['metadata'].pop(target) future.set_result(None)
python
async def on_raw_765(self, message): """ Invalid metadata target. """ target, targetmeta = self._parse_user(message.params[0]) if target not in self._pending['metadata']: return if target in self.users: self._sync_user(target, targetmeta) self._metadata_queue.remove(target) del self._metadata_info[target] future = self._pending['metadata'].pop(target) future.set_result(None)
[ "async", "def", "on_raw_765", "(", "self", ",", "message", ")", ":", "target", ",", "targetmeta", "=", "self", ".", "_parse_user", "(", "message", ".", "params", "[", "0", "]", ")", "if", "target", "not", "in", "self", ".", "_pending", "[", "'metadata'...
Invalid metadata target.
[ "Invalid", "metadata", "target", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/metadata.py#L108-L121
train
23,800
Shizmob/pydle
pydle/connection.py
Connection.connect
async def connect(self): """ Connect to target. """ self.tls_context = None if self.tls: self.tls_context = self.create_tls_context() (self.reader, self.writer) = await asyncio.open_connection( host=self.hostname, port=self.port, local_addr=self.source_address, ssl=self.tls_context, loop=self.eventloop )
python
async def connect(self): """ Connect to target. """ self.tls_context = None if self.tls: self.tls_context = self.create_tls_context() (self.reader, self.writer) = await asyncio.open_connection( host=self.hostname, port=self.port, local_addr=self.source_address, ssl=self.tls_context, loop=self.eventloop )
[ "async", "def", "connect", "(", "self", ")", ":", "self", ".", "tls_context", "=", "None", "if", "self", ".", "tls", ":", "self", ".", "tls_context", "=", "self", ".", "create_tls_context", "(", ")", "(", "self", ".", "reader", ",", "self", ".", "wri...
Connect to target.
[ "Connect", "to", "target", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/connection.py#L41-L54
train
23,801
Shizmob/pydle
pydle/connection.py
Connection.create_tls_context
def create_tls_context(self): """ Transform our regular socket into a TLS socket. """ # Create context manually, as we're going to set our own options. tls_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) # Load client/server certificate. if self.tls_certificate_file: tls_context.load_cert_chain(self.tls_certificate_file, self.tls_certificate_keyfile, password=self.tls_certificate_password) # Set some relevant options: # - No server should use SSLv2 or SSLv3 any more, they are outdated and full of security holes. (RFC6176, RFC7568) # - Disable compression in order to counter the CRIME attack. (https://en.wikipedia.org/wiki/CRIME_%28security_exploit%29) # - Disable session resumption to maintain perfect forward secrecy. (https://timtaubert.de/blog/2014/11/the-sad-state-of-server-side-tls-session-resumption-implementations/) for opt in ['NO_SSLv2', 'NO_SSLv3', 'NO_COMPRESSION', 'NO_TICKET']: if hasattr(ssl, 'OP_' + opt): tls_context.options |= getattr(ssl, 'OP_' + opt) # Set TLS verification options. if self.tls_verify: # Set our custom verification callback, if the library supports it. tls_context.set_servername_callback(self.verify_tls) # Load certificate verification paths. tls_context.set_default_verify_paths() if sys.platform in DEFAULT_CA_PATHS and path.isdir(DEFAULT_CA_PATHS[sys.platform]): tls_context.load_verify_locations(capath=DEFAULT_CA_PATHS[sys.platform]) # If we want to verify the TLS connection, we first need a certicate. # Check this certificate and its entire chain, if possible, against revocation lists. tls_context.verify_mode = ssl.CERT_REQUIRED tls_context.verify_flags = ssl.VERIFY_CRL_CHECK_CHAIN return tls_context
python
def create_tls_context(self): """ Transform our regular socket into a TLS socket. """ # Create context manually, as we're going to set our own options. tls_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) # Load client/server certificate. if self.tls_certificate_file: tls_context.load_cert_chain(self.tls_certificate_file, self.tls_certificate_keyfile, password=self.tls_certificate_password) # Set some relevant options: # - No server should use SSLv2 or SSLv3 any more, they are outdated and full of security holes. (RFC6176, RFC7568) # - Disable compression in order to counter the CRIME attack. (https://en.wikipedia.org/wiki/CRIME_%28security_exploit%29) # - Disable session resumption to maintain perfect forward secrecy. (https://timtaubert.de/blog/2014/11/the-sad-state-of-server-side-tls-session-resumption-implementations/) for opt in ['NO_SSLv2', 'NO_SSLv3', 'NO_COMPRESSION', 'NO_TICKET']: if hasattr(ssl, 'OP_' + opt): tls_context.options |= getattr(ssl, 'OP_' + opt) # Set TLS verification options. if self.tls_verify: # Set our custom verification callback, if the library supports it. tls_context.set_servername_callback(self.verify_tls) # Load certificate verification paths. tls_context.set_default_verify_paths() if sys.platform in DEFAULT_CA_PATHS and path.isdir(DEFAULT_CA_PATHS[sys.platform]): tls_context.load_verify_locations(capath=DEFAULT_CA_PATHS[sys.platform]) # If we want to verify the TLS connection, we first need a certicate. # Check this certificate and its entire chain, if possible, against revocation lists. tls_context.verify_mode = ssl.CERT_REQUIRED tls_context.verify_flags = ssl.VERIFY_CRL_CHECK_CHAIN return tls_context
[ "def", "create_tls_context", "(", "self", ")", ":", "# Create context manually, as we're going to set our own options.", "tls_context", "=", "ssl", ".", "SSLContext", "(", "ssl", ".", "PROTOCOL_SSLv23", ")", "# Load client/server certificate.", "if", "self", ".", "tls_certi...
Transform our regular socket into a TLS socket.
[ "Transform", "our", "regular", "socket", "into", "a", "TLS", "socket", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/connection.py#L56-L89
train
23,802
Shizmob/pydle
pydle/connection.py
Connection.disconnect
async def disconnect(self): """ Disconnect from target. """ if not self.connected: return self.writer.close() self.reader = None self.writer = None
python
async def disconnect(self): """ Disconnect from target. """ if not self.connected: return self.writer.close() self.reader = None self.writer = None
[ "async", "def", "disconnect", "(", "self", ")", ":", "if", "not", "self", ".", "connected", ":", "return", "self", ".", "writer", ".", "close", "(", ")", "self", ".", "reader", "=", "None", "self", ".", "writer", "=", "None" ]
Disconnect from target.
[ "Disconnect", "from", "target", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/connection.py#L107-L114
train
23,803
Shizmob/pydle
pydle/connection.py
Connection.send
async def send(self, data): """ Add data to send queue. """ self.writer.write(data) await self.writer.drain()
python
async def send(self, data): """ Add data to send queue. """ self.writer.write(data) await self.writer.drain()
[ "async", "def", "send", "(", "self", ",", "data", ")", ":", "self", ".", "writer", ".", "write", "(", "data", ")", "await", "self", ".", "writer", ".", "drain", "(", ")" ]
Add data to send queue.
[ "Add", "data", "to", "send", "queue", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/connection.py#L125-L128
train
23,804
Shizmob/pydle
pydle/protocol.py
identifierify
def identifierify(name): """ Clean up name so it works for a Python identifier. """ name = name.lower() name = re.sub('[^a-z0-9]', '_', name) return name
python
def identifierify(name): """ Clean up name so it works for a Python identifier. """ name = name.lower() name = re.sub('[^a-z0-9]', '_', name) return name
[ "def", "identifierify", "(", "name", ")", ":", "name", "=", "name", ".", "lower", "(", ")", "name", "=", "re", ".", "sub", "(", "'[^a-z0-9]'", ",", "'_'", ",", "name", ")", "return", "name" ]
Clean up name so it works for a Python identifier.
[ "Clean", "up", "name", "so", "it", "works", "for", "a", "Python", "identifier", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/protocol.py#L40-L44
train
23,805
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support._register
async def _register(self): """ Perform IRC connection registration. """ if self.registered: return self._registration_attempts += 1 # Don't throttle during registration, most ircds don't care for flooding during registration, # and it might speed it up significantly. self.connection.throttle = False # Password first. if self.password: await self.rawmsg('PASS', self.password) # Then nickname... await self.set_nickname(self._attempt_nicknames.pop(0)) # And now for the rest of the user information. await self.rawmsg('USER', self.username, '0', '*', self.realname)
python
async def _register(self): """ Perform IRC connection registration. """ if self.registered: return self._registration_attempts += 1 # Don't throttle during registration, most ircds don't care for flooding during registration, # and it might speed it up significantly. self.connection.throttle = False # Password first. if self.password: await self.rawmsg('PASS', self.password) # Then nickname... await self.set_nickname(self._attempt_nicknames.pop(0)) # And now for the rest of the user information. await self.rawmsg('USER', self.username, '0', '*', self.realname)
[ "async", "def", "_register", "(", "self", ")", ":", "if", "self", ".", "registered", ":", "return", "self", ".", "_registration_attempts", "+=", "1", "# Don't throttle during registration, most ircds don't care for flooding during registration,", "# and it might speed it up sig...
Perform IRC connection registration.
[ "Perform", "IRC", "connection", "registration", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L199-L216
train
23,806
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support._registration_completed
async def _registration_completed(self, message): """ We're connected and registered. Receive proper nickname and emit fake NICK message. """ if not self.registered: # Re-enable throttling. self.registered = True self.connection.throttle = True target = message.params[0] fakemsg = self._create_message('NICK', target, source=self.nickname) await self.on_raw_nick(fakemsg)
python
async def _registration_completed(self, message): """ We're connected and registered. Receive proper nickname and emit fake NICK message. """ if not self.registered: # Re-enable throttling. self.registered = True self.connection.throttle = True target = message.params[0] fakemsg = self._create_message('NICK', target, source=self.nickname) await self.on_raw_nick(fakemsg)
[ "async", "def", "_registration_completed", "(", "self", ",", "message", ")", ":", "if", "not", "self", ".", "registered", ":", "# Re-enable throttling.", "self", ".", "registered", "=", "True", "self", ".", "connection", ".", "throttle", "=", "True", "target",...
We're connected and registered. Receive proper nickname and emit fake NICK message.
[ "We", "re", "connected", "and", "registered", ".", "Receive", "proper", "nickname", "and", "emit", "fake", "NICK", "message", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L218-L227
train
23,807
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support._has_message
def _has_message(self): """ Whether or not we have messages available for processing. """ sep = protocol.MINIMAL_LINE_SEPARATOR.encode(self.encoding) return sep in self._receive_buffer
python
def _has_message(self): """ Whether or not we have messages available for processing. """ sep = protocol.MINIMAL_LINE_SEPARATOR.encode(self.encoding) return sep in self._receive_buffer
[ "def", "_has_message", "(", "self", ")", ":", "sep", "=", "protocol", ".", "MINIMAL_LINE_SEPARATOR", ".", "encode", "(", "self", ".", "encoding", ")", "return", "sep", "in", "self", ".", "_receive_buffer" ]
Whether or not we have messages available for processing.
[ "Whether", "or", "not", "we", "have", "messages", "available", "for", "processing", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L231-L234
train
23,808
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.join
async def join(self, channel, password=None): """ Join channel, optionally with password. """ if self.in_channel(channel): raise AlreadyInChannel(channel) if password: await self.rawmsg('JOIN', channel, password) else: await self.rawmsg('JOIN', channel)
python
async def join(self, channel, password=None): """ Join channel, optionally with password. """ if self.in_channel(channel): raise AlreadyInChannel(channel) if password: await self.rawmsg('JOIN', channel, password) else: await self.rawmsg('JOIN', channel)
[ "async", "def", "join", "(", "self", ",", "channel", ",", "password", "=", "None", ")", ":", "if", "self", ".", "in_channel", "(", "channel", ")", ":", "raise", "AlreadyInChannel", "(", "channel", ")", "if", "password", ":", "await", "self", ".", "rawm...
Join channel, optionally with password.
[ "Join", "channel", "optionally", "with", "password", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L254-L262
train
23,809
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.part
async def part(self, channel, message=None): """ Leave channel, optionally with message. """ if not self.in_channel(channel): raise NotInChannel(channel) # Message seems to be an extension to the spec. if message: await self.rawmsg('PART', channel, message) else: await self.rawmsg('PART', channel)
python
async def part(self, channel, message=None): """ Leave channel, optionally with message. """ if not self.in_channel(channel): raise NotInChannel(channel) # Message seems to be an extension to the spec. if message: await self.rawmsg('PART', channel, message) else: await self.rawmsg('PART', channel)
[ "async", "def", "part", "(", "self", ",", "channel", ",", "message", "=", "None", ")", ":", "if", "not", "self", ".", "in_channel", "(", "channel", ")", ":", "raise", "NotInChannel", "(", "channel", ")", "# Message seems to be an extension to the spec.", "if",...
Leave channel, optionally with message.
[ "Leave", "channel", "optionally", "with", "message", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L264-L273
train
23,810
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.kick
async def kick(self, channel, target, reason=None): """ Kick user from channel. """ if not self.in_channel(channel): raise NotInChannel(channel) if reason: await self.rawmsg('KICK', channel, target, reason) else: await self.rawmsg('KICK', channel, target)
python
async def kick(self, channel, target, reason=None): """ Kick user from channel. """ if not self.in_channel(channel): raise NotInChannel(channel) if reason: await self.rawmsg('KICK', channel, target, reason) else: await self.rawmsg('KICK', channel, target)
[ "async", "def", "kick", "(", "self", ",", "channel", ",", "target", ",", "reason", "=", "None", ")", ":", "if", "not", "self", ".", "in_channel", "(", "channel", ")", ":", "raise", "NotInChannel", "(", "channel", ")", "if", "reason", ":", "await", "s...
Kick user from channel.
[ "Kick", "user", "from", "channel", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L275-L283
train
23,811
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.unban
async def unban(self, channel, target, range=0): """ Unban user from channel. Target can be either a user or a host. See ban documentation for the range parameter. """ if target in self.users: host = self.users[target]['hostname'] else: host = target host = self._format_host_range(host, range) mask = self._format_host_mask('*', '*', host) await self.rawmsg('MODE', channel, '-b', mask)
python
async def unban(self, channel, target, range=0): """ Unban user from channel. Target can be either a user or a host. See ban documentation for the range parameter. """ if target in self.users: host = self.users[target]['hostname'] else: host = target host = self._format_host_range(host, range) mask = self._format_host_mask('*', '*', host) await self.rawmsg('MODE', channel, '-b', mask)
[ "async", "def", "unban", "(", "self", ",", "channel", ",", "target", ",", "range", "=", "0", ")", ":", "if", "target", "in", "self", ".", "users", ":", "host", "=", "self", ".", "users", "[", "target", "]", "[", "'hostname'", "]", "else", ":", "h...
Unban user from channel. Target can be either a user or a host. See ban documentation for the range parameter.
[ "Unban", "user", "from", "channel", ".", "Target", "can", "be", "either", "a", "user", "or", "a", "host", ".", "See", "ban", "documentation", "for", "the", "range", "parameter", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L301-L313
train
23,812
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.kickban
async def kickban(self, channel, target, reason=None, range=0): """ Kick and ban user from channel. """ await self.ban(channel, target, range) await self.kick(channel, target, reason)
python
async def kickban(self, channel, target, reason=None, range=0): """ Kick and ban user from channel. """ await self.ban(channel, target, range) await self.kick(channel, target, reason)
[ "async", "def", "kickban", "(", "self", ",", "channel", ",", "target", ",", "reason", "=", "None", ",", "range", "=", "0", ")", ":", "await", "self", ".", "ban", "(", "channel", ",", "target", ",", "range", ")", "await", "self", ".", "kick", "(", ...
Kick and ban user from channel.
[ "Kick", "and", "ban", "user", "from", "channel", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L315-L320
train
23,813
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.quit
async def quit(self, message=None): """ Quit network. """ if message is None: message = self.DEFAULT_QUIT_MESSAGE await self.rawmsg('QUIT', message) await self.disconnect(expected=True)
python
async def quit(self, message=None): """ Quit network. """ if message is None: message = self.DEFAULT_QUIT_MESSAGE await self.rawmsg('QUIT', message) await self.disconnect(expected=True)
[ "async", "def", "quit", "(", "self", ",", "message", "=", "None", ")", ":", "if", "message", "is", "None", ":", "message", "=", "self", ".", "DEFAULT_QUIT_MESSAGE", "await", "self", ".", "rawmsg", "(", "'QUIT'", ",", "message", ")", "await", "self", "....
Quit network.
[ "Quit", "network", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L322-L328
train
23,814
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.cycle
async def cycle(self, channel): """ Rejoin channel. """ if not self.in_channel(channel): raise NotInChannel(channel) password = self.channels[channel]['password'] await self.part(channel) await self.join(channel, password)
python
async def cycle(self, channel): """ Rejoin channel. """ if not self.in_channel(channel): raise NotInChannel(channel) password = self.channels[channel]['password'] await self.part(channel) await self.join(channel, password)
[ "async", "def", "cycle", "(", "self", ",", "channel", ")", ":", "if", "not", "self", ".", "in_channel", "(", "channel", ")", ":", "raise", "NotInChannel", "(", "channel", ")", "password", "=", "self", ".", "channels", "[", "channel", "]", "[", "'passwo...
Rejoin channel.
[ "Rejoin", "channel", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L330-L337
train
23,815
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.message
async def message(self, target, message): """ Message channel or user. """ hostmask = self._format_user_mask(self.nickname) # Leeway. chunklen = protocol.MESSAGE_LENGTH_LIMIT - len( '{hostmask} PRIVMSG {target} :'.format(hostmask=hostmask, target=target)) - 25 for line in message.replace('\r', '').split('\n'): for chunk in chunkify(line, chunklen): # Some IRC servers respond with "412 Bot :No text to send" on empty messages. await self.rawmsg('PRIVMSG', target, chunk or ' ')
python
async def message(self, target, message): """ Message channel or user. """ hostmask = self._format_user_mask(self.nickname) # Leeway. chunklen = protocol.MESSAGE_LENGTH_LIMIT - len( '{hostmask} PRIVMSG {target} :'.format(hostmask=hostmask, target=target)) - 25 for line in message.replace('\r', '').split('\n'): for chunk in chunkify(line, chunklen): # Some IRC servers respond with "412 Bot :No text to send" on empty messages. await self.rawmsg('PRIVMSG', target, chunk or ' ')
[ "async", "def", "message", "(", "self", ",", "target", ",", "message", ")", ":", "hostmask", "=", "self", ".", "_format_user_mask", "(", "self", ".", "nickname", ")", "# Leeway.", "chunklen", "=", "protocol", ".", "MESSAGE_LENGTH_LIMIT", "-", "len", "(", "...
Message channel or user.
[ "Message", "channel", "or", "user", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L339-L349
train
23,816
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.set_topic
async def set_topic(self, channel, topic): """ Set topic on channel. Users should only rely on the topic actually being changed when receiving an on_topic_change callback. """ if not self.is_channel(channel): raise ValueError('Not a channel: {}'.format(channel)) elif not self.in_channel(channel): raise NotInChannel(channel) await self.rawmsg('TOPIC', channel, topic)
python
async def set_topic(self, channel, topic): """ Set topic on channel. Users should only rely on the topic actually being changed when receiving an on_topic_change callback. """ if not self.is_channel(channel): raise ValueError('Not a channel: {}'.format(channel)) elif not self.in_channel(channel): raise NotInChannel(channel) await self.rawmsg('TOPIC', channel, topic)
[ "async", "def", "set_topic", "(", "self", ",", "channel", ",", "topic", ")", ":", "if", "not", "self", ".", "is_channel", "(", "channel", ")", ":", "raise", "ValueError", "(", "'Not a channel: {}'", ".", "format", "(", "channel", ")", ")", "elif", "not",...
Set topic on channel. Users should only rely on the topic actually being changed when receiving an on_topic_change callback.
[ "Set", "topic", "on", "channel", ".", "Users", "should", "only", "rely", "on", "the", "topic", "actually", "being", "changed", "when", "receiving", "an", "on_topic_change", "callback", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L372-L382
train
23,817
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_error
async def on_raw_error(self, message): """ Server encountered an error and will now close the connection. """ error = protocol.ServerError(' '.join(message.params)) await self.on_data_error(error)
python
async def on_raw_error(self, message): """ Server encountered an error and will now close the connection. """ error = protocol.ServerError(' '.join(message.params)) await self.on_data_error(error)
[ "async", "def", "on_raw_error", "(", "self", ",", "message", ")", ":", "error", "=", "protocol", ".", "ServerError", "(", "' '", ".", "join", "(", "message", ".", "params", ")", ")", "await", "self", ".", "on_data_error", "(", "error", ")" ]
Server encountered an error and will now close the connection.
[ "Server", "encountered", "an", "error", "and", "will", "now", "close", "the", "connection", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L539-L542
train
23,818
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_invite
async def on_raw_invite(self, message): """ INVITE command. """ nick, metadata = self._parse_user(message.source) self._sync_user(nick, metadata) target, channel = message.params target, metadata = self._parse_user(target) if self.is_same_nick(self.nickname, target): await self.on_invite(channel, nick) else: await self.on_user_invite(target, channel, nick)
python
async def on_raw_invite(self, message): """ INVITE command. """ nick, metadata = self._parse_user(message.source) self._sync_user(nick, metadata) target, channel = message.params target, metadata = self._parse_user(target) if self.is_same_nick(self.nickname, target): await self.on_invite(channel, nick) else: await self.on_user_invite(target, channel, nick)
[ "async", "def", "on_raw_invite", "(", "self", ",", "message", ")", ":", "nick", ",", "metadata", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "self", ".", "_sync_user", "(", "nick", ",", "metadata", ")", "target", ",", "channel", ...
INVITE command.
[ "INVITE", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L544-L555
train
23,819
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_join
async def on_raw_join(self, message): """ JOIN command. """ nick, metadata = self._parse_user(message.source) self._sync_user(nick, metadata) channels = message.params[0].split(',') if self.is_same_nick(self.nickname, nick): # Add to our channel list, we joined here. for channel in channels: if not self.in_channel(channel): self._create_channel(channel) # Request channel mode from IRCd. await self.rawmsg('MODE', channel) else: # Add user to channel user list. for channel in channels: if self.in_channel(channel): self.channels[channel]['users'].add(nick) for channel in channels: await self.on_join(channel, nick)
python
async def on_raw_join(self, message): """ JOIN command. """ nick, metadata = self._parse_user(message.source) self._sync_user(nick, metadata) channels = message.params[0].split(',') if self.is_same_nick(self.nickname, nick): # Add to our channel list, we joined here. for channel in channels: if not self.in_channel(channel): self._create_channel(channel) # Request channel mode from IRCd. await self.rawmsg('MODE', channel) else: # Add user to channel user list. for channel in channels: if self.in_channel(channel): self.channels[channel]['users'].add(nick) for channel in channels: await self.on_join(channel, nick)
[ "async", "def", "on_raw_join", "(", "self", ",", "message", ")", ":", "nick", ",", "metadata", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "self", ".", "_sync_user", "(", "nick", ",", "metadata", ")", "channels", "=", "message", ...
JOIN command.
[ "JOIN", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L557-L578
train
23,820
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_kick
async def on_raw_kick(self, message): """ KICK command. """ kicker, kickermeta = self._parse_user(message.source) self._sync_user(kicker, kickermeta) if len(message.params) > 2: channels, targets, reason = message.params else: channels, targets = message.params reason = None channels = channels.split(',') targets = targets.split(',') for channel, target in itertools.product(channels, targets): target, targetmeta = self._parse_user(target) self._sync_user(target, targetmeta) if self.is_same_nick(target, self.nickname): self._destroy_channel(channel) else: # Update nick list on channel. if self.in_channel(channel): self._destroy_user(target, channel) await self.on_kick(channel, target, kicker, reason)
python
async def on_raw_kick(self, message): """ KICK command. """ kicker, kickermeta = self._parse_user(message.source) self._sync_user(kicker, kickermeta) if len(message.params) > 2: channels, targets, reason = message.params else: channels, targets = message.params reason = None channels = channels.split(',') targets = targets.split(',') for channel, target in itertools.product(channels, targets): target, targetmeta = self._parse_user(target) self._sync_user(target, targetmeta) if self.is_same_nick(target, self.nickname): self._destroy_channel(channel) else: # Update nick list on channel. if self.in_channel(channel): self._destroy_user(target, channel) await self.on_kick(channel, target, kicker, reason)
[ "async", "def", "on_raw_kick", "(", "self", ",", "message", ")", ":", "kicker", ",", "kickermeta", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "self", ".", "_sync_user", "(", "kicker", ",", "kickermeta", ")", "if", "len", "(", ...
KICK command.
[ "KICK", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L580-L605
train
23,821
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_kill
async def on_raw_kill(self, message): """ KILL command. """ by, bymeta = self._parse_user(message.source) target, targetmeta = self._parse_user(message.params[0]) reason = message.params[1] self._sync_user(target, targetmeta) if by in self.users: self._sync_user(by, bymeta) await self.on_kill(target, by, reason) if self.is_same_nick(self.nickname, target): await self.disconnect(expected=False) else: self._destroy_user(target)
python
async def on_raw_kill(self, message): """ KILL command. """ by, bymeta = self._parse_user(message.source) target, targetmeta = self._parse_user(message.params[0]) reason = message.params[1] self._sync_user(target, targetmeta) if by in self.users: self._sync_user(by, bymeta) await self.on_kill(target, by, reason) if self.is_same_nick(self.nickname, target): await self.disconnect(expected=False) else: self._destroy_user(target)
[ "async", "def", "on_raw_kill", "(", "self", ",", "message", ")", ":", "by", ",", "bymeta", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "target", ",", "targetmeta", "=", "self", ".", "_parse_user", "(", "message", ".", "params", ...
KILL command.
[ "KILL", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L607-L621
train
23,822
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_mode
async def on_raw_mode(self, message): """ MODE command. """ nick, metadata = self._parse_user(message.source) target, modes = message.params[0], message.params[1:] self._sync_user(nick, metadata) if self.is_channel(target): if self.in_channel(target): # Parse modes. self.channels[target]['modes'] = self._parse_channel_modes(target, modes) await self.on_mode_change(target, modes, nick) else: target, targetmeta = self._parse_user(target) self._sync_user(target, targetmeta) # Update own modes. if self.is_same_nick(self.nickname, nick): self._mode = self._parse_user_modes(nick, modes, current=self._mode) await self.on_user_mode_change(modes)
python
async def on_raw_mode(self, message): """ MODE command. """ nick, metadata = self._parse_user(message.source) target, modes = message.params[0], message.params[1:] self._sync_user(nick, metadata) if self.is_channel(target): if self.in_channel(target): # Parse modes. self.channels[target]['modes'] = self._parse_channel_modes(target, modes) await self.on_mode_change(target, modes, nick) else: target, targetmeta = self._parse_user(target) self._sync_user(target, targetmeta) # Update own modes. if self.is_same_nick(self.nickname, nick): self._mode = self._parse_user_modes(nick, modes, current=self._mode) await self.on_user_mode_change(modes)
[ "async", "def", "on_raw_mode", "(", "self", ",", "message", ")", ":", "nick", ",", "metadata", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "target", ",", "modes", "=", "message", ".", "params", "[", "0", "]", ",", "message", ...
MODE command.
[ "MODE", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L623-L643
train
23,823
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_nick
async def on_raw_nick(self, message): """ NICK command. """ nick, metadata = self._parse_user(message.source) new = message.params[0] self._sync_user(nick, metadata) # Acknowledgement of nickname change: set it internally, too. # Alternatively, we were force nick-changed. Nothing much we can do about it. if self.is_same_nick(self.nickname, nick): self.nickname = new # Go through all user lists and replace. self._rename_user(nick, new) # Call handler. await self.on_nick_change(nick, new)
python
async def on_raw_nick(self, message): """ NICK command. """ nick, metadata = self._parse_user(message.source) new = message.params[0] self._sync_user(nick, metadata) # Acknowledgement of nickname change: set it internally, too. # Alternatively, we were force nick-changed. Nothing much we can do about it. if self.is_same_nick(self.nickname, nick): self.nickname = new # Go through all user lists and replace. self._rename_user(nick, new) # Call handler. await self.on_nick_change(nick, new)
[ "async", "def", "on_raw_nick", "(", "self", ",", "message", ")", ":", "nick", ",", "metadata", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "new", "=", "message", ".", "params", "[", "0", "]", "self", ".", "_sync_user", "(", "...
NICK command.
[ "NICK", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L645-L660
train
23,824
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_notice
async def on_raw_notice(self, message): """ NOTICE command. """ nick, metadata = self._parse_user(message.source) target, message = message.params self._sync_user(nick, metadata) await self.on_notice(target, nick, message) if self.is_channel(target): await self.on_channel_notice(target, nick, message) else: await self.on_private_notice(target, nick, message)
python
async def on_raw_notice(self, message): """ NOTICE command. """ nick, metadata = self._parse_user(message.source) target, message = message.params self._sync_user(nick, metadata) await self.on_notice(target, nick, message) if self.is_channel(target): await self.on_channel_notice(target, nick, message) else: await self.on_private_notice(target, nick, message)
[ "async", "def", "on_raw_notice", "(", "self", ",", "message", ")", ":", "nick", ",", "metadata", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "target", ",", "message", "=", "message", ".", "params", "self", ".", "_sync_user", "(",...
NOTICE command.
[ "NOTICE", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L662-L673
train
23,825
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_part
async def on_raw_part(self, message): """ PART command. """ nick, metadata = self._parse_user(message.source) channels = message.params[0].split(',') if len(message.params) > 1: reason = message.params[1] else: reason = None self._sync_user(nick, metadata) if self.is_same_nick(self.nickname, nick): # We left the channel. Remove from channel list. :( for channel in channels: if self.in_channel(channel): self._destroy_channel(channel) await self.on_part(channel, nick, reason) else: # Someone else left. Remove them. for channel in channels: self._destroy_user(nick, channel) await self.on_part(channel, nick, reason)
python
async def on_raw_part(self, message): """ PART command. """ nick, metadata = self._parse_user(message.source) channels = message.params[0].split(',') if len(message.params) > 1: reason = message.params[1] else: reason = None self._sync_user(nick, metadata) if self.is_same_nick(self.nickname, nick): # We left the channel. Remove from channel list. :( for channel in channels: if self.in_channel(channel): self._destroy_channel(channel) await self.on_part(channel, nick, reason) else: # Someone else left. Remove them. for channel in channels: self._destroy_user(nick, channel) await self.on_part(channel, nick, reason)
[ "async", "def", "on_raw_part", "(", "self", ",", "message", ")", ":", "nick", ",", "metadata", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "channels", "=", "message", ".", "params", "[", "0", "]", ".", "split", "(", "','", ")...
PART command.
[ "PART", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L675-L695
train
23,826
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_privmsg
async def on_raw_privmsg(self, message): """ PRIVMSG command. """ nick, metadata = self._parse_user(message.source) target, message = message.params self._sync_user(nick, metadata) await self.on_message(target, nick, message) if self.is_channel(target): await self.on_channel_message(target, nick, message) else: await self.on_private_message(target, nick, message)
python
async def on_raw_privmsg(self, message): """ PRIVMSG command. """ nick, metadata = self._parse_user(message.source) target, message = message.params self._sync_user(nick, metadata) await self.on_message(target, nick, message) if self.is_channel(target): await self.on_channel_message(target, nick, message) else: await self.on_private_message(target, nick, message)
[ "async", "def", "on_raw_privmsg", "(", "self", ",", "message", ")", ":", "nick", ",", "metadata", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "target", ",", "message", "=", "message", ".", "params", "self", ".", "_sync_user", "("...
PRIVMSG command.
[ "PRIVMSG", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L702-L713
train
23,827
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_quit
async def on_raw_quit(self, message): """ QUIT command. """ nick, metadata = self._parse_user(message.source) self._sync_user(nick, metadata) if message.params: reason = message.params[0] else: reason = None await self.on_quit(nick, reason) # Remove user from database. if not self.is_same_nick(self.nickname, nick): self._destroy_user(nick) # Else, we quit. elif self.connected: await self.disconnect(expected=True)
python
async def on_raw_quit(self, message): """ QUIT command. """ nick, metadata = self._parse_user(message.source) self._sync_user(nick, metadata) if message.params: reason = message.params[0] else: reason = None await self.on_quit(nick, reason) # Remove user from database. if not self.is_same_nick(self.nickname, nick): self._destroy_user(nick) # Else, we quit. elif self.connected: await self.disconnect(expected=True)
[ "async", "def", "on_raw_quit", "(", "self", ",", "message", ")", ":", "nick", ",", "metadata", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "self", ".", "_sync_user", "(", "nick", ",", "metadata", ")", "if", "message", ".", "par...
QUIT command.
[ "QUIT", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L715-L731
train
23,828
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_topic
async def on_raw_topic(self, message): """ TOPIC command. """ setter, settermeta = self._parse_user(message.source) target, topic = message.params self._sync_user(setter, settermeta) # Update topic in our own channel list. if self.in_channel(target): self.channels[target]['topic'] = topic self.channels[target]['topic_by'] = setter self.channels[target]['topic_set'] = datetime.datetime.now() await self.on_topic_change(target, topic, setter)
python
async def on_raw_topic(self, message): """ TOPIC command. """ setter, settermeta = self._parse_user(message.source) target, topic = message.params self._sync_user(setter, settermeta) # Update topic in our own channel list. if self.in_channel(target): self.channels[target]['topic'] = topic self.channels[target]['topic_by'] = setter self.channels[target]['topic_set'] = datetime.datetime.now() await self.on_topic_change(target, topic, setter)
[ "async", "def", "on_raw_topic", "(", "self", ",", "message", ")", ":", "setter", ",", "settermeta", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "target", ",", "topic", "=", "message", ".", "params", "self", ".", "_sync_user", "("...
TOPIC command.
[ "TOPIC", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L733-L746
train
23,829
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_004
async def on_raw_004(self, message): """ Basic server information. """ target, hostname, ircd, user_modes, channel_modes = message.params[:5] # Set valid channel and user modes. self._channel_modes = set(channel_modes) self._user_modes = set(user_modes)
python
async def on_raw_004(self, message): """ Basic server information. """ target, hostname, ircd, user_modes, channel_modes = message.params[:5] # Set valid channel and user modes. self._channel_modes = set(channel_modes) self._user_modes = set(user_modes)
[ "async", "def", "on_raw_004", "(", "self", ",", "message", ")", ":", "target", ",", "hostname", ",", "ircd", ",", "user_modes", ",", "channel_modes", "=", "message", ".", "params", "[", ":", "5", "]", "# Set valid channel and user modes.", "self", ".", "_cha...
Basic server information.
[ "Basic", "server", "information", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L757-L763
train
23,830
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_301
async def on_raw_301(self, message): """ User is away. """ target, nickname, message = message.params info = { 'away': True, 'away_message': message } if nickname in self.users: self._sync_user(nickname, info) if nickname in self._pending['whois']: self._whois_info[nickname].update(info)
python
async def on_raw_301(self, message): """ User is away. """ target, nickname, message = message.params info = { 'away': True, 'away_message': message } if nickname in self.users: self._sync_user(nickname, info) if nickname in self._pending['whois']: self._whois_info[nickname].update(info)
[ "async", "def", "on_raw_301", "(", "self", ",", "message", ")", ":", "target", ",", "nickname", ",", "message", "=", "message", ".", "params", "info", "=", "{", "'away'", ":", "True", ",", "'away_message'", ":", "message", "}", "if", "nickname", "in", ...
User is away.
[ "User", "is", "away", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L776-L787
train
23,831
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_311
async def on_raw_311(self, message): """ WHOIS user info. """ target, nickname, username, hostname, _, realname = message.params info = { 'username': username, 'hostname': hostname, 'realname': realname } self._sync_user(nickname, info) if nickname in self._pending['whois']: self._whois_info[nickname].update(info)
python
async def on_raw_311(self, message): """ WHOIS user info. """ target, nickname, username, hostname, _, realname = message.params info = { 'username': username, 'hostname': hostname, 'realname': realname } self._sync_user(nickname, info) if nickname in self._pending['whois']: self._whois_info[nickname].update(info)
[ "async", "def", "on_raw_311", "(", "self", ",", "message", ")", ":", "target", ",", "nickname", ",", "username", ",", "hostname", ",", "_", ",", "realname", "=", "message", ".", "params", "info", "=", "{", "'username'", ":", "username", ",", "'hostname'"...
WHOIS user info.
[ "WHOIS", "user", "info", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L789-L800
train
23,832
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_312
async def on_raw_312(self, message): """ WHOIS server info. """ target, nickname, server, serverinfo = message.params info = { 'server': server, 'server_info': serverinfo } if nickname in self._pending['whois']: self._whois_info[nickname].update(info) if nickname in self._pending['whowas']: self._whowas_info[nickname].update(info)
python
async def on_raw_312(self, message): """ WHOIS server info. """ target, nickname, server, serverinfo = message.params info = { 'server': server, 'server_info': serverinfo } if nickname in self._pending['whois']: self._whois_info[nickname].update(info) if nickname in self._pending['whowas']: self._whowas_info[nickname].update(info)
[ "async", "def", "on_raw_312", "(", "self", ",", "message", ")", ":", "target", ",", "nickname", ",", "server", ",", "serverinfo", "=", "message", ".", "params", "info", "=", "{", "'server'", ":", "server", ",", "'server_info'", ":", "serverinfo", "}", "i...
WHOIS server info.
[ "WHOIS", "server", "info", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L802-L813
train
23,833
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_313
async def on_raw_313(self, message): """ WHOIS operator info. """ target, nickname = message.params[:2] info = { 'oper': True } if nickname in self._pending['whois']: self._whois_info[nickname].update(info)
python
async def on_raw_313(self, message): """ WHOIS operator info. """ target, nickname = message.params[:2] info = { 'oper': True } if nickname in self._pending['whois']: self._whois_info[nickname].update(info)
[ "async", "def", "on_raw_313", "(", "self", ",", "message", ")", ":", "target", ",", "nickname", "=", "message", ".", "params", "[", ":", "2", "]", "info", "=", "{", "'oper'", ":", "True", "}", "if", "nickname", "in", "self", ".", "_pending", "[", "...
WHOIS operator info.
[ "WHOIS", "operator", "info", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L815-L823
train
23,834
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_314
async def on_raw_314(self, message): """ WHOWAS user info. """ target, nickname, username, hostname, _, realname = message.params info = { 'username': username, 'hostname': hostname, 'realname': realname } if nickname in self._pending['whowas']: self._whowas_info[nickname].update(info)
python
async def on_raw_314(self, message): """ WHOWAS user info. """ target, nickname, username, hostname, _, realname = message.params info = { 'username': username, 'hostname': hostname, 'realname': realname } if nickname in self._pending['whowas']: self._whowas_info[nickname].update(info)
[ "async", "def", "on_raw_314", "(", "self", ",", "message", ")", ":", "target", ",", "nickname", ",", "username", ",", "hostname", ",", "_", ",", "realname", "=", "message", ".", "params", "info", "=", "{", "'username'", ":", "username", ",", "'hostname'"...
WHOWAS user info.
[ "WHOWAS", "user", "info", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L825-L835
train
23,835
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_317
async def on_raw_317(self, message): """ WHOIS idle time. """ target, nickname, idle_time = message.params[:3] info = { 'idle': int(idle_time), } if nickname in self._pending['whois']: self._whois_info[nickname].update(info)
python
async def on_raw_317(self, message): """ WHOIS idle time. """ target, nickname, idle_time = message.params[:3] info = { 'idle': int(idle_time), } if nickname in self._pending['whois']: self._whois_info[nickname].update(info)
[ "async", "def", "on_raw_317", "(", "self", ",", "message", ")", ":", "target", ",", "nickname", ",", "idle_time", "=", "message", ".", "params", "[", ":", "3", "]", "info", "=", "{", "'idle'", ":", "int", "(", "idle_time", ")", ",", "}", "if", "nic...
WHOIS idle time.
[ "WHOIS", "idle", "time", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L839-L847
train
23,836
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_319
async def on_raw_319(self, message): """ WHOIS active channels. """ target, nickname, channels = message.params[:3] channels = {channel.lstrip() for channel in channels.strip().split(' ')} info = { 'channels': channels } if nickname in self._pending['whois']: self._whois_info[nickname].update(info)
python
async def on_raw_319(self, message): """ WHOIS active channels. """ target, nickname, channels = message.params[:3] channels = {channel.lstrip() for channel in channels.strip().split(' ')} info = { 'channels': channels } if nickname in self._pending['whois']: self._whois_info[nickname].update(info)
[ "async", "def", "on_raw_319", "(", "self", ",", "message", ")", ":", "target", ",", "nickname", ",", "channels", "=", "message", ".", "params", "[", ":", "3", "]", "channels", "=", "{", "channel", ".", "lstrip", "(", ")", "for", "channel", "in", "cha...
WHOIS active channels.
[ "WHOIS", "active", "channels", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L858-L867
train
23,837
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_324
async def on_raw_324(self, message): """ Channel mode. """ target, channel = message.params[:2] modes = message.params[2:] if not self.in_channel(channel): return self.channels[channel]['modes'] = self._parse_channel_modes(channel, modes)
python
async def on_raw_324(self, message): """ Channel mode. """ target, channel = message.params[:2] modes = message.params[2:] if not self.in_channel(channel): return self.channels[channel]['modes'] = self._parse_channel_modes(channel, modes)
[ "async", "def", "on_raw_324", "(", "self", ",", "message", ")", ":", "target", ",", "channel", "=", "message", ".", "params", "[", ":", "2", "]", "modes", "=", "message", ".", "params", "[", "2", ":", "]", "if", "not", "self", ".", "in_channel", "(...
Channel mode.
[ "Channel", "mode", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L869-L876
train
23,838
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_329
async def on_raw_329(self, message): """ Channel creation time. """ target, channel, timestamp = message.params if not self.in_channel(channel): return self.channels[channel]['created'] = datetime.datetime.fromtimestamp(int(timestamp))
python
async def on_raw_329(self, message): """ Channel creation time. """ target, channel, timestamp = message.params if not self.in_channel(channel): return self.channels[channel]['created'] = datetime.datetime.fromtimestamp(int(timestamp))
[ "async", "def", "on_raw_329", "(", "self", ",", "message", ")", ":", "target", ",", "channel", ",", "timestamp", "=", "message", ".", "params", "if", "not", "self", ".", "in_channel", "(", "channel", ")", ":", "return", "self", ".", "channels", "[", "c...
Channel creation time.
[ "Channel", "creation", "time", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L878-L884
train
23,839
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_332
async def on_raw_332(self, message): """ Current topic on channel join. """ target, channel, topic = message.params if not self.in_channel(channel): return self.channels[channel]['topic'] = topic
python
async def on_raw_332(self, message): """ Current topic on channel join. """ target, channel, topic = message.params if not self.in_channel(channel): return self.channels[channel]['topic'] = topic
[ "async", "def", "on_raw_332", "(", "self", ",", "message", ")", ":", "target", ",", "channel", ",", "topic", "=", "message", ".", "params", "if", "not", "self", ".", "in_channel", "(", "channel", ")", ":", "return", "self", ".", "channels", "[", "chann...
Current topic on channel join.
[ "Current", "topic", "on", "channel", "join", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L886-L892
train
23,840
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_333
async def on_raw_333(self, message): """ Topic setter and time on channel join. """ target, channel, setter, timestamp = message.params if not self.in_channel(channel): return # No need to sync user since this is most likely outdated info. self.channels[channel]['topic_by'] = self._parse_user(setter)[0] self.channels[channel]['topic_set'] = datetime.datetime.fromtimestamp(int(timestamp))
python
async def on_raw_333(self, message): """ Topic setter and time on channel join. """ target, channel, setter, timestamp = message.params if not self.in_channel(channel): return # No need to sync user since this is most likely outdated info. self.channels[channel]['topic_by'] = self._parse_user(setter)[0] self.channels[channel]['topic_set'] = datetime.datetime.fromtimestamp(int(timestamp))
[ "async", "def", "on_raw_333", "(", "self", ",", "message", ")", ":", "target", ",", "channel", ",", "setter", ",", "timestamp", "=", "message", ".", "params", "if", "not", "self", ".", "in_channel", "(", "channel", ")", ":", "return", "# No need to sync us...
Topic setter and time on channel join.
[ "Topic", "setter", "and", "time", "on", "channel", "join", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L894-L902
train
23,841
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_375
async def on_raw_375(self, message): """ Start message of the day. """ await self._registration_completed(message) self.motd = message.params[1] + '\n'
python
async def on_raw_375(self, message): """ Start message of the day. """ await self._registration_completed(message) self.motd = message.params[1] + '\n'
[ "async", "def", "on_raw_375", "(", "self", ",", "message", ")", ":", "await", "self", ".", "_registration_completed", "(", "message", ")", "self", ".", "motd", "=", "message", ".", "params", "[", "1", "]", "+", "'\\n'" ]
Start message of the day.
[ "Start", "message", "of", "the", "day", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L944-L947
train
23,842
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_422
async def on_raw_422(self, message): """ MOTD is missing. """ await self._registration_completed(message) self.motd = None await self.on_connect()
python
async def on_raw_422(self, message): """ MOTD is missing. """ await self._registration_completed(message) self.motd = None await self.on_connect()
[ "async", "def", "on_raw_422", "(", "self", ",", "message", ")", ":", "await", "self", ".", "_registration_completed", "(", "message", ")", "self", ".", "motd", "=", "None", "await", "self", ".", "on_connect", "(", ")" ]
MOTD is missing.
[ "MOTD", "is", "missing", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L974-L978
train
23,843
Shizmob/pydle
pydle/features/rfc1459/client.py
RFC1459Support.on_raw_433
async def on_raw_433(self, message): """ Nickname in use. """ if not self.registered: self._registration_attempts += 1 # Attempt to set new nickname. if self._attempt_nicknames: await self.set_nickname(self._attempt_nicknames.pop(0)) else: await self.set_nickname( self._nicknames[0] + '_' * (self._registration_attempts - len(self._nicknames)))
python
async def on_raw_433(self, message): """ Nickname in use. """ if not self.registered: self._registration_attempts += 1 # Attempt to set new nickname. if self._attempt_nicknames: await self.set_nickname(self._attempt_nicknames.pop(0)) else: await self.set_nickname( self._nicknames[0] + '_' * (self._registration_attempts - len(self._nicknames)))
[ "async", "def", "on_raw_433", "(", "self", ",", "message", ")", ":", "if", "not", "self", ".", "registered", ":", "self", ".", "_registration_attempts", "+=", "1", "# Attempt to set new nickname.", "if", "self", ".", "_attempt_nicknames", ":", "await", "self", ...
Nickname in use.
[ "Nickname", "in", "use", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/client.py#L990-L999
train
23,844
Shizmob/pydle
pydle/features/tls.py
TLSSupport.connect
async def connect(self, hostname=None, port=None, tls=False, **kwargs): """ Connect to a server, optionally over TLS. See pydle.features.RFC1459Support.connect for misc parameters. """ if not port: if tls: port = DEFAULT_TLS_PORT else: port = rfc1459.protocol.DEFAULT_PORT return await super().connect(hostname, port, tls=tls, **kwargs)
python
async def connect(self, hostname=None, port=None, tls=False, **kwargs): """ Connect to a server, optionally over TLS. See pydle.features.RFC1459Support.connect for misc parameters. """ if not port: if tls: port = DEFAULT_TLS_PORT else: port = rfc1459.protocol.DEFAULT_PORT return await super().connect(hostname, port, tls=tls, **kwargs)
[ "async", "def", "connect", "(", "self", ",", "hostname", "=", "None", ",", "port", "=", "None", ",", "tls", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "port", ":", "if", "tls", ":", "port", "=", "DEFAULT_TLS_PORT", "else", ":", ...
Connect to a server, optionally over TLS. See pydle.features.RFC1459Support.connect for misc parameters.
[ "Connect", "to", "a", "server", "optionally", "over", "TLS", ".", "See", "pydle", ".", "features", ".", "RFC1459Support", ".", "connect", "for", "misc", "parameters", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/tls.py#L28-L35
train
23,845
Shizmob/pydle
pydle/features/tls.py
TLSSupport._connect
async def _connect(self, hostname, port, reconnect=False, password=None, encoding=pydle.protocol.DEFAULT_ENCODING, channels=[], tls=False, tls_verify=False, source_address=None): """ Connect to IRC server, optionally over TLS. """ self.password = password # Create connection if we can't reuse it. if not reconnect: self._autojoin_channels = channels self.connection = connection.Connection(hostname, port, source_address=source_address, tls=tls, tls_verify=tls_verify, tls_certificate_file=self.tls_client_cert, tls_certificate_keyfile=self.tls_client_cert_key, tls_certificate_password=self.tls_client_cert_password, eventloop=self.eventloop) self.encoding = encoding # Connect. await self.connection.connect()
python
async def _connect(self, hostname, port, reconnect=False, password=None, encoding=pydle.protocol.DEFAULT_ENCODING, channels=[], tls=False, tls_verify=False, source_address=None): """ Connect to IRC server, optionally over TLS. """ self.password = password # Create connection if we can't reuse it. if not reconnect: self._autojoin_channels = channels self.connection = connection.Connection(hostname, port, source_address=source_address, tls=tls, tls_verify=tls_verify, tls_certificate_file=self.tls_client_cert, tls_certificate_keyfile=self.tls_client_cert_key, tls_certificate_password=self.tls_client_cert_password, eventloop=self.eventloop) self.encoding = encoding # Connect. await self.connection.connect()
[ "async", "def", "_connect", "(", "self", ",", "hostname", ",", "port", ",", "reconnect", "=", "False", ",", "password", "=", "None", ",", "encoding", "=", "pydle", ".", "protocol", ".", "DEFAULT_ENCODING", ",", "channels", "=", "[", "]", ",", "tls", "=...
Connect to IRC server, optionally over TLS.
[ "Connect", "to", "IRC", "server", "optionally", "over", "TLS", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/tls.py#L37-L54
train
23,846
Shizmob/pydle
pydle/client.py
BasicClient._reset_attributes
def _reset_attributes(self): """ Reset attributes. """ # Record-keeping. self.channels = {} self.users = {} # Low-level data stuff. self._receive_buffer = b'' self._pending = {} self._handler_top_level = False self._ping_checker_handle = None # Misc. self.logger = logging.getLogger(__name__) # Public connection attributes. self.nickname = DEFAULT_NICKNAME self.network = None
python
def _reset_attributes(self): """ Reset attributes. """ # Record-keeping. self.channels = {} self.users = {} # Low-level data stuff. self._receive_buffer = b'' self._pending = {} self._handler_top_level = False self._ping_checker_handle = None # Misc. self.logger = logging.getLogger(__name__) # Public connection attributes. self.nickname = DEFAULT_NICKNAME self.network = None
[ "def", "_reset_attributes", "(", "self", ")", ":", "# Record-keeping.", "self", ".", "channels", "=", "{", "}", "self", ".", "users", "=", "{", "}", "# Low-level data stuff.", "self", ".", "_receive_buffer", "=", "b''", "self", ".", "_pending", "=", "{", "...
Reset attributes.
[ "Reset", "attributes", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L59-L76
train
23,847
Shizmob/pydle
pydle/client.py
BasicClient._reset_connection_attributes
def _reset_connection_attributes(self): """ Reset connection attributes. """ self.connection = None self.encoding = None self._autojoin_channels = [] self._reconnect_attempts = 0
python
def _reset_connection_attributes(self): """ Reset connection attributes. """ self.connection = None self.encoding = None self._autojoin_channels = [] self._reconnect_attempts = 0
[ "def", "_reset_connection_attributes", "(", "self", ")", ":", "self", ".", "connection", "=", "None", "self", ".", "encoding", "=", "None", "self", ".", "_autojoin_channels", "=", "[", "]", "self", ".", "_reconnect_attempts", "=", "0" ]
Reset connection attributes.
[ "Reset", "connection", "attributes", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L78-L83
train
23,848
Shizmob/pydle
pydle/client.py
BasicClient.run
def run(self, *args, **kwargs): """ Connect and run bot in event loop. """ self.eventloop.run_until_complete(self.connect(*args, **kwargs)) try: self.eventloop.run_forever() finally: self.eventloop.stop()
python
def run(self, *args, **kwargs): """ Connect and run bot in event loop. """ self.eventloop.run_until_complete(self.connect(*args, **kwargs)) try: self.eventloop.run_forever() finally: self.eventloop.stop()
[ "def", "run", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "eventloop", ".", "run_until_complete", "(", "self", ".", "connect", "(", "*", "args", ",", "*", "*", "kwargs", ")", ")", "try", ":", "self", ".", "event...
Connect and run bot in event loop.
[ "Connect", "and", "run", "bot", "in", "event", "loop", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L87-L93
train
23,849
Shizmob/pydle
pydle/client.py
BasicClient.connect
async def connect(self, hostname=None, port=None, reconnect=False, **kwargs): """ Connect to IRC server. """ if (not hostname or not port) and not reconnect: raise ValueError('Have to specify hostname and port if not reconnecting.') # Disconnect from current connection. if self.connected: await self.disconnect(expected=True) # Reset attributes and connect. if not reconnect: self._reset_connection_attributes() await self._connect(hostname=hostname, port=port, reconnect=reconnect, **kwargs) # Set logger name. if self.server_tag: self.logger = logging.getLogger(self.__class__.__name__ + ':' + self.server_tag) self.eventloop.create_task(self.handle_forever())
python
async def connect(self, hostname=None, port=None, reconnect=False, **kwargs): """ Connect to IRC server. """ if (not hostname or not port) and not reconnect: raise ValueError('Have to specify hostname and port if not reconnecting.') # Disconnect from current connection. if self.connected: await self.disconnect(expected=True) # Reset attributes and connect. if not reconnect: self._reset_connection_attributes() await self._connect(hostname=hostname, port=port, reconnect=reconnect, **kwargs) # Set logger name. if self.server_tag: self.logger = logging.getLogger(self.__class__.__name__ + ':' + self.server_tag) self.eventloop.create_task(self.handle_forever())
[ "async", "def", "connect", "(", "self", ",", "hostname", "=", "None", ",", "port", "=", "None", ",", "reconnect", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "(", "not", "hostname", "or", "not", "port", ")", "and", "not", "reconnect", ":...
Connect to IRC server.
[ "Connect", "to", "IRC", "server", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L95-L113
train
23,850
Shizmob/pydle
pydle/client.py
BasicClient._connect
async def _connect(self, hostname, port, reconnect=False, channels=[], encoding=protocol.DEFAULT_ENCODING, source_address=None): """ Connect to IRC host. """ # Create connection if we can't reuse it. if not reconnect or not self.connection: self._autojoin_channels = channels self.connection = connection.Connection(hostname, port, source_address=source_address, eventloop=self.eventloop) self.encoding = encoding # Connect. await self.connection.connect()
python
async def _connect(self, hostname, port, reconnect=False, channels=[], encoding=protocol.DEFAULT_ENCODING, source_address=None): """ Connect to IRC host. """ # Create connection if we can't reuse it. if not reconnect or not self.connection: self._autojoin_channels = channels self.connection = connection.Connection(hostname, port, source_address=source_address, eventloop=self.eventloop) self.encoding = encoding # Connect. await self.connection.connect()
[ "async", "def", "_connect", "(", "self", ",", "hostname", ",", "port", ",", "reconnect", "=", "False", ",", "channels", "=", "[", "]", ",", "encoding", "=", "protocol", ".", "DEFAULT_ENCODING", ",", "source_address", "=", "None", ")", ":", "# Create connec...
Connect to IRC host.
[ "Connect", "to", "IRC", "host", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L139-L150
train
23,851
Shizmob/pydle
pydle/client.py
BasicClient._reconnect_delay
def _reconnect_delay(self): """ Calculate reconnection delay. """ if self.RECONNECT_ON_ERROR and self.RECONNECT_DELAYED: if self._reconnect_attempts >= len(self.RECONNECT_DELAYS): return self.RECONNECT_DELAYS[-1] else: return self.RECONNECT_DELAYS[self._reconnect_attempts] else: return 0
python
def _reconnect_delay(self): """ Calculate reconnection delay. """ if self.RECONNECT_ON_ERROR and self.RECONNECT_DELAYED: if self._reconnect_attempts >= len(self.RECONNECT_DELAYS): return self.RECONNECT_DELAYS[-1] else: return self.RECONNECT_DELAYS[self._reconnect_attempts] else: return 0
[ "def", "_reconnect_delay", "(", "self", ")", ":", "if", "self", ".", "RECONNECT_ON_ERROR", "and", "self", ".", "RECONNECT_DELAYED", ":", "if", "self", ".", "_reconnect_attempts", ">=", "len", "(", "self", ".", "RECONNECT_DELAYS", ")", ":", "return", "self", ...
Calculate reconnection delay.
[ "Calculate", "reconnection", "delay", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L152-L160
train
23,852
Shizmob/pydle
pydle/client.py
BasicClient._perform_ping_timeout
async def _perform_ping_timeout(self, delay: int): """ Handle timeout gracefully. Args: delay (int): delay before raising the timeout (in seconds) """ # pause for delay seconds await sleep(delay) # then continue error = TimeoutError( 'Ping timeout: no data received from server in {timeout} seconds.'.format( timeout=self.PING_TIMEOUT)) await self.on_data_error(error)
python
async def _perform_ping_timeout(self, delay: int): """ Handle timeout gracefully. Args: delay (int): delay before raising the timeout (in seconds) """ # pause for delay seconds await sleep(delay) # then continue error = TimeoutError( 'Ping timeout: no data received from server in {timeout} seconds.'.format( timeout=self.PING_TIMEOUT)) await self.on_data_error(error)
[ "async", "def", "_perform_ping_timeout", "(", "self", ",", "delay", ":", "int", ")", ":", "# pause for delay seconds", "await", "sleep", "(", "delay", ")", "# then continue", "error", "=", "TimeoutError", "(", "'Ping timeout: no data received from server in {timeout} seco...
Handle timeout gracefully. Args: delay (int): delay before raising the timeout (in seconds)
[ "Handle", "timeout", "gracefully", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L162-L175
train
23,853
Shizmob/pydle
pydle/client.py
BasicClient.rawmsg
async def rawmsg(self, command, *args, **kwargs): """ Send raw message. """ message = str(self._create_message(command, *args, **kwargs)) await self._send(message)
python
async def rawmsg(self, command, *args, **kwargs): """ Send raw message. """ message = str(self._create_message(command, *args, **kwargs)) await self._send(message)
[ "async", "def", "rawmsg", "(", "self", ",", "command", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "message", "=", "str", "(", "self", ".", "_create_message", "(", "command", ",", "*", "args", ",", "*", "*", "kwargs", ")", ")", "await", ...
Send raw message.
[ "Send", "raw", "message", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L311-L314
train
23,854
Shizmob/pydle
pydle/client.py
BasicClient.handle_forever
async def handle_forever(self): """ Handle data forever. """ while self.connected: data = await self.connection.recv() if not data: if self.connected: await self.disconnect(expected=False) break await self.on_data(data)
python
async def handle_forever(self): """ Handle data forever. """ while self.connected: data = await self.connection.recv() if not data: if self.connected: await self.disconnect(expected=False) break await self.on_data(data)
[ "async", "def", "handle_forever", "(", "self", ")", ":", "while", "self", ".", "connected", ":", "data", "=", "await", "self", ".", "connection", ".", "recv", "(", ")", "if", "not", "data", ":", "if", "self", ".", "connected", ":", "await", "self", "...
Handle data forever.
[ "Handle", "data", "forever", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L365-L373
train
23,855
Shizmob/pydle
pydle/client.py
BasicClient.on_data_error
async def on_data_error(self, exception): """ Handle error. """ self.logger.error('Encountered error on socket.', exc_info=(type(exception), exception, None)) await self.disconnect(expected=False)
python
async def on_data_error(self, exception): """ Handle error. """ self.logger.error('Encountered error on socket.', exc_info=(type(exception), exception, None)) await self.disconnect(expected=False)
[ "async", "def", "on_data_error", "(", "self", ",", "exception", ")", ":", "self", ".", "logger", ".", "error", "(", "'Encountered error on socket.'", ",", "exc_info", "=", "(", "type", "(", "exception", ")", ",", "exception", ",", "None", ")", ")", "await"...
Handle error.
[ "Handle", "error", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L394-L398
train
23,856
Shizmob/pydle
pydle/client.py
BasicClient.on_raw
async def on_raw(self, message): """ Handle a single message. """ self.logger.debug('<< %s', message._raw) if not message._valid: self.logger.warning('Encountered strictly invalid IRC message from server: %s', message._raw) if isinstance(message.command, int): cmd = str(message.command).zfill(3) else: cmd = message.command # Invoke dispatcher, if we have one. method = 'on_raw_' + cmd.lower() try: # Set _top_level so __getattr__() can decide whether to return on_unknown or _ignored for unknown handlers. # The reason for this is that features can always call super().on_raw_* safely and thus don't need to care for other features, # while unknown messages for which no handlers exist at all are still logged. self._handler_top_level = True handler = getattr(self, method) self._handler_top_level = False await handler(message) except: self.logger.exception('Failed to execute %s handler.', method)
python
async def on_raw(self, message): """ Handle a single message. """ self.logger.debug('<< %s', message._raw) if not message._valid: self.logger.warning('Encountered strictly invalid IRC message from server: %s', message._raw) if isinstance(message.command, int): cmd = str(message.command).zfill(3) else: cmd = message.command # Invoke dispatcher, if we have one. method = 'on_raw_' + cmd.lower() try: # Set _top_level so __getattr__() can decide whether to return on_unknown or _ignored for unknown handlers. # The reason for this is that features can always call super().on_raw_* safely and thus don't need to care for other features, # while unknown messages for which no handlers exist at all are still logged. self._handler_top_level = True handler = getattr(self, method) self._handler_top_level = False await handler(message) except: self.logger.exception('Failed to execute %s handler.', method)
[ "async", "def", "on_raw", "(", "self", ",", "message", ")", ":", "self", ".", "logger", ".", "debug", "(", "'<< %s'", ",", "message", ".", "_raw", ")", "if", "not", "message", ".", "_valid", ":", "self", ".", "logger", ".", "warning", "(", "'Encounte...
Handle a single message.
[ "Handle", "a", "single", "message", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L400-L424
train
23,857
Shizmob/pydle
pydle/client.py
BasicClient.on_unknown
async def on_unknown(self, message): """ Unknown command. """ self.logger.warning('Unknown command: [%s] %s %s', message.source, message.command, message.params)
python
async def on_unknown(self, message): """ Unknown command. """ self.logger.warning('Unknown command: [%s] %s %s', message.source, message.command, message.params)
[ "async", "def", "on_unknown", "(", "self", ",", "message", ")", ":", "self", ".", "logger", ".", "warning", "(", "'Unknown command: [%s] %s %s'", ",", "message", ".", "source", ",", "message", ".", "command", ",", "message", ".", "params", ")" ]
Unknown command.
[ "Unknown", "command", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L426-L429
train
23,858
Shizmob/pydle
pydle/client.py
ClientPool.connect
def connect(self, client: BasicClient, *args, **kwargs): """ Add client to pool. """ self.clients.add(client) self.connect_args[client] = (args, kwargs) # hack the clients event loop to use the pools own event loop client.eventloop = self.eventloop
python
def connect(self, client: BasicClient, *args, **kwargs): """ Add client to pool. """ self.clients.add(client) self.connect_args[client] = (args, kwargs) # hack the clients event loop to use the pools own event loop client.eventloop = self.eventloop
[ "def", "connect", "(", "self", ",", "client", ":", "BasicClient", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "clients", ".", "add", "(", "client", ")", "self", ".", "connect_args", "[", "client", "]", "=", "(", "args", ",", ...
Add client to pool.
[ "Add", "client", "to", "pool", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L460-L465
train
23,859
Shizmob/pydle
pydle/client.py
ClientPool.disconnect
def disconnect(self, client): """ Remove client from pool. """ self.clients.remove(client) del self.connect_args[client] client.disconnect()
python
def disconnect(self, client): """ Remove client from pool. """ self.clients.remove(client) del self.connect_args[client] client.disconnect()
[ "def", "disconnect", "(", "self", ",", "client", ")", ":", "self", ".", "clients", ".", "remove", "(", "client", ")", "del", "self", ".", "connect_args", "[", "client", "]", "client", ".", "disconnect", "(", ")" ]
Remove client from pool.
[ "Remove", "client", "from", "pool", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/client.py#L468-L472
train
23,860
Shizmob/pydle
pydle/features/rfc1459/parsing.py
normalize
def normalize(input, case_mapping=protocol.DEFAULT_CASE_MAPPING): """ Normalize input according to case mapping. """ if case_mapping not in protocol.CASE_MAPPINGS: raise pydle.protocol.ProtocolViolation('Unknown case mapping ({})'.format(case_mapping)) input = input.lower() if case_mapping in ('rfc1459', 'rfc1459-strict'): input = input.replace('{', '[').replace('}', ']').replace('|', '\\') if case_mapping == 'rfc1459': input = input.replace('~', '^') return input
python
def normalize(input, case_mapping=protocol.DEFAULT_CASE_MAPPING): """ Normalize input according to case mapping. """ if case_mapping not in protocol.CASE_MAPPINGS: raise pydle.protocol.ProtocolViolation('Unknown case mapping ({})'.format(case_mapping)) input = input.lower() if case_mapping in ('rfc1459', 'rfc1459-strict'): input = input.replace('{', '[').replace('}', ']').replace('|', '\\') if case_mapping == 'rfc1459': input = input.replace('~', '^') return input
[ "def", "normalize", "(", "input", ",", "case_mapping", "=", "protocol", ".", "DEFAULT_CASE_MAPPING", ")", ":", "if", "case_mapping", "not", "in", "protocol", ".", "CASE_MAPPINGS", ":", "raise", "pydle", ".", "protocol", ".", "ProtocolViolation", "(", "'Unknown c...
Normalize input according to case mapping.
[ "Normalize", "input", "according", "to", "case", "mapping", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/parsing.py#L134-L146
train
23,861
Shizmob/pydle
pydle/features/rfc1459/parsing.py
parse_user
def parse_user(raw): """ Parse nick(!user(@host)?)? structure. """ nick = raw user = None host = None # Attempt to extract host. if protocol.HOST_SEPARATOR in raw: raw, host = raw.split(protocol.HOST_SEPARATOR) # Attempt to extract user. if protocol.USER_SEPARATOR in raw: nick, user = raw.split(protocol.USER_SEPARATOR) return nick, user, host
python
def parse_user(raw): """ Parse nick(!user(@host)?)? structure. """ nick = raw user = None host = None # Attempt to extract host. if protocol.HOST_SEPARATOR in raw: raw, host = raw.split(protocol.HOST_SEPARATOR) # Attempt to extract user. if protocol.USER_SEPARATOR in raw: nick, user = raw.split(protocol.USER_SEPARATOR) return nick, user, host
[ "def", "parse_user", "(", "raw", ")", ":", "nick", "=", "raw", "user", "=", "None", "host", "=", "None", "# Attempt to extract host.", "if", "protocol", ".", "HOST_SEPARATOR", "in", "raw", ":", "raw", ",", "host", "=", "raw", ".", "split", "(", "protocol...
Parse nick(!user(@host)?)? structure.
[ "Parse", "nick", "(", "!user", "(" ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/parsing.py#L184-L197
train
23,862
Shizmob/pydle
pydle/features/rfc1459/parsing.py
RFC1459Message.parse
def parse(cls, line, encoding=pydle.protocol.DEFAULT_ENCODING): """ Parse given line into IRC message structure. Returns a Message. """ valid = True # Decode message. try: message = line.decode(encoding) except UnicodeDecodeError: # Try our fallback encoding. message = line.decode(pydle.protocol.FALLBACK_ENCODING) # Sanity check for message length. if len(message) > protocol.MESSAGE_LENGTH_LIMIT: valid = False # Strip message separator. if message.endswith(protocol.LINE_SEPARATOR): message = message[:-len(protocol.LINE_SEPARATOR)] elif message.endswith(protocol.MINIMAL_LINE_SEPARATOR): message = message[:-len(protocol.MINIMAL_LINE_SEPARATOR)] # Sanity check for forbidden characters. if any(ch in message for ch in protocol.FORBIDDEN_CHARACTERS): valid = False # Extract message sections. # Format: (:source)? command parameter* if message.startswith(':'): parts = protocol.ARGUMENT_SEPARATOR.split(message[1:], 2) else: parts = [ None ] + protocol.ARGUMENT_SEPARATOR.split(message, 1) if len(parts) == 3: source, command, raw_params = parts elif len(parts) == 2: source, command = parts raw_params = '' else: raise pydle.protocol.ProtocolViolation('Improper IRC message format: not enough elements.', message=message) # Sanity check for command. if not protocol.COMMAND_PATTERN.match(command): valid = False # Extract parameters properly. # Format: (word|:sentence)* # Only parameter is a 'trailing' sentence. if raw_params.startswith(protocol.TRAILING_PREFIX): params = [ raw_params[len(protocol.TRAILING_PREFIX):] ] # We have a sentence in our parameters. elif ' ' + protocol.TRAILING_PREFIX in raw_params: index = raw_params.find(' ' + protocol.TRAILING_PREFIX) # Get all single-word parameters. params = protocol.ARGUMENT_SEPARATOR.split(raw_params[:index].rstrip(' ')) # Extract last parameter as sentence params.append(raw_params[index + len(protocol.TRAILING_PREFIX) + 1:]) # We have some parameters, but no sentences. elif raw_params: params = protocol.ARGUMENT_SEPARATOR.split(raw_params) # No parameters. else: params = [] # Commands can be either [a-zA-Z]+ or [0-9]+. # In the former case, force it to uppercase. # In the latter case (a numeric command), try to represent it as such. try: command = int(command) except ValueError: command = command.upper() # Return parsed message. return RFC1459Message(command, params, source=source, _valid=valid, _raw=message)
python
def parse(cls, line, encoding=pydle.protocol.DEFAULT_ENCODING): """ Parse given line into IRC message structure. Returns a Message. """ valid = True # Decode message. try: message = line.decode(encoding) except UnicodeDecodeError: # Try our fallback encoding. message = line.decode(pydle.protocol.FALLBACK_ENCODING) # Sanity check for message length. if len(message) > protocol.MESSAGE_LENGTH_LIMIT: valid = False # Strip message separator. if message.endswith(protocol.LINE_SEPARATOR): message = message[:-len(protocol.LINE_SEPARATOR)] elif message.endswith(protocol.MINIMAL_LINE_SEPARATOR): message = message[:-len(protocol.MINIMAL_LINE_SEPARATOR)] # Sanity check for forbidden characters. if any(ch in message for ch in protocol.FORBIDDEN_CHARACTERS): valid = False # Extract message sections. # Format: (:source)? command parameter* if message.startswith(':'): parts = protocol.ARGUMENT_SEPARATOR.split(message[1:], 2) else: parts = [ None ] + protocol.ARGUMENT_SEPARATOR.split(message, 1) if len(parts) == 3: source, command, raw_params = parts elif len(parts) == 2: source, command = parts raw_params = '' else: raise pydle.protocol.ProtocolViolation('Improper IRC message format: not enough elements.', message=message) # Sanity check for command. if not protocol.COMMAND_PATTERN.match(command): valid = False # Extract parameters properly. # Format: (word|:sentence)* # Only parameter is a 'trailing' sentence. if raw_params.startswith(protocol.TRAILING_PREFIX): params = [ raw_params[len(protocol.TRAILING_PREFIX):] ] # We have a sentence in our parameters. elif ' ' + protocol.TRAILING_PREFIX in raw_params: index = raw_params.find(' ' + protocol.TRAILING_PREFIX) # Get all single-word parameters. params = protocol.ARGUMENT_SEPARATOR.split(raw_params[:index].rstrip(' ')) # Extract last parameter as sentence params.append(raw_params[index + len(protocol.TRAILING_PREFIX) + 1:]) # We have some parameters, but no sentences. elif raw_params: params = protocol.ARGUMENT_SEPARATOR.split(raw_params) # No parameters. else: params = [] # Commands can be either [a-zA-Z]+ or [0-9]+. # In the former case, force it to uppercase. # In the latter case (a numeric command), try to represent it as such. try: command = int(command) except ValueError: command = command.upper() # Return parsed message. return RFC1459Message(command, params, source=source, _valid=valid, _raw=message)
[ "def", "parse", "(", "cls", ",", "line", ",", "encoding", "=", "pydle", ".", "protocol", ".", "DEFAULT_ENCODING", ")", ":", "valid", "=", "True", "# Decode message.", "try", ":", "message", "=", "line", ".", "decode", "(", "encoding", ")", "except", "Uni...
Parse given line into IRC message structure. Returns a Message.
[ "Parse", "given", "line", "into", "IRC", "message", "structure", ".", "Returns", "a", "Message", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/parsing.py#L18-L95
train
23,863
Shizmob/pydle
pydle/features/rfc1459/parsing.py
RFC1459Message.construct
def construct(self, force=False): """ Construct a raw IRC message. """ # Sanity check for command. command = str(self.command) if not protocol.COMMAND_PATTERN.match(command) and not force: raise pydle.protocol.ProtocolViolation('The constructed command does not follow the command pattern ({pat})'.format(pat=protocol.COMMAND_PATTERN.pattern), message=command) message = command.upper() # Add parameters. if not self.params: message += ' ' for idx, param in enumerate(self.params): # Trailing parameter? if not param or ' ' in param or param[0] == ':': if idx + 1 < len(self.params) and not force: raise pydle.protocol.ProtocolViolation('Only the final parameter of an IRC message can be trailing and thus contain spaces, or start with a colon.', message=param) message += ' ' + protocol.TRAILING_PREFIX + param # Regular parameter. else: message += ' ' + param # Prepend source. if self.source: message = ':' + self.source + ' ' + message # Sanity check for characters. if any(ch in message for ch in protocol.FORBIDDEN_CHARACTERS) and not force: raise pydle.protocol.ProtocolViolation('The constructed message contains forbidden characters ({chs}).'.format(chs=', '.join(protocol.FORBIDDEN_CHARACTERS)), message=message) # Sanity check for length. message += protocol.LINE_SEPARATOR if len(message) > protocol.MESSAGE_LENGTH_LIMIT and not force: raise pydle.protocol.ProtocolViolation('The constructed message is too long. ({len} > {maxlen})'.format(len=len(message), maxlen=protocol.MESSAGE_LENGTH_LIMIT), message=message) return message
python
def construct(self, force=False): """ Construct a raw IRC message. """ # Sanity check for command. command = str(self.command) if not protocol.COMMAND_PATTERN.match(command) and not force: raise pydle.protocol.ProtocolViolation('The constructed command does not follow the command pattern ({pat})'.format(pat=protocol.COMMAND_PATTERN.pattern), message=command) message = command.upper() # Add parameters. if not self.params: message += ' ' for idx, param in enumerate(self.params): # Trailing parameter? if not param or ' ' in param or param[0] == ':': if idx + 1 < len(self.params) and not force: raise pydle.protocol.ProtocolViolation('Only the final parameter of an IRC message can be trailing and thus contain spaces, or start with a colon.', message=param) message += ' ' + protocol.TRAILING_PREFIX + param # Regular parameter. else: message += ' ' + param # Prepend source. if self.source: message = ':' + self.source + ' ' + message # Sanity check for characters. if any(ch in message for ch in protocol.FORBIDDEN_CHARACTERS) and not force: raise pydle.protocol.ProtocolViolation('The constructed message contains forbidden characters ({chs}).'.format(chs=', '.join(protocol.FORBIDDEN_CHARACTERS)), message=message) # Sanity check for length. message += protocol.LINE_SEPARATOR if len(message) > protocol.MESSAGE_LENGTH_LIMIT and not force: raise pydle.protocol.ProtocolViolation('The constructed message is too long. ({len} > {maxlen})'.format(len=len(message), maxlen=protocol.MESSAGE_LENGTH_LIMIT), message=message) return message
[ "def", "construct", "(", "self", ",", "force", "=", "False", ")", ":", "# Sanity check for command.", "command", "=", "str", "(", "self", ".", "command", ")", "if", "not", "protocol", ".", "COMMAND_PATTERN", ".", "match", "(", "command", ")", "and", "not",...
Construct a raw IRC message.
[ "Construct", "a", "raw", "IRC", "message", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/rfc1459/parsing.py#L97-L131
train
23,864
Shizmob/pydle
pydle/__init__.py
featurize
def featurize(*features): """ Put features into proper MRO order. """ from functools import cmp_to_key def compare_subclass(left, right): if issubclass(left, right): return -1 elif issubclass(right, left): return 1 return 0 sorted_features = sorted(features, key=cmp_to_key(compare_subclass)) name = 'FeaturizedClient[{features}]'.format( features=', '.join(feature.__name__ for feature in sorted_features)) return type(name, tuple(sorted_features), {})
python
def featurize(*features): """ Put features into proper MRO order. """ from functools import cmp_to_key def compare_subclass(left, right): if issubclass(left, right): return -1 elif issubclass(right, left): return 1 return 0 sorted_features = sorted(features, key=cmp_to_key(compare_subclass)) name = 'FeaturizedClient[{features}]'.format( features=', '.join(feature.__name__ for feature in sorted_features)) return type(name, tuple(sorted_features), {})
[ "def", "featurize", "(", "*", "features", ")", ":", "from", "functools", "import", "cmp_to_key", "def", "compare_subclass", "(", "left", ",", "right", ")", ":", "if", "issubclass", "(", "left", ",", "right", ")", ":", "return", "-", "1", "elif", "issubcl...
Put features into proper MRO order.
[ "Put", "features", "into", "proper", "MRO", "order", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/__init__.py#L16-L30
train
23,865
Shizmob/pydle
pydle/features/whox.py
WHOXSupport.on_raw_join
async def on_raw_join(self, message): """ Override JOIN to send WHOX. """ await super().on_raw_join(message) nick, metadata = self._parse_user(message.source) channels = message.params[0].split(',') if self.is_same_nick(self.nickname, nick): # We joined. if 'WHOX' in self._isupport and self._isupport['WHOX']: # Get more relevant channel info thanks to WHOX. await self.rawmsg('WHO', ','.join(channels), '%tnurha,{id}'.format(id=WHOX_IDENTIFIER)) else: # Find account name of person. pass
python
async def on_raw_join(self, message): """ Override JOIN to send WHOX. """ await super().on_raw_join(message) nick, metadata = self._parse_user(message.source) channels = message.params[0].split(',') if self.is_same_nick(self.nickname, nick): # We joined. if 'WHOX' in self._isupport and self._isupport['WHOX']: # Get more relevant channel info thanks to WHOX. await self.rawmsg('WHO', ','.join(channels), '%tnurha,{id}'.format(id=WHOX_IDENTIFIER)) else: # Find account name of person. pass
[ "async", "def", "on_raw_join", "(", "self", ",", "message", ")", ":", "await", "super", "(", ")", ".", "on_raw_join", "(", "message", ")", "nick", ",", "metadata", "=", "self", ".", "_parse_user", "(", "message", ".", "source", ")", "channels", "=", "m...
Override JOIN to send WHOX.
[ "Override", "JOIN", "to", "send", "WHOX", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/whox.py#L13-L26
train
23,866
Shizmob/pydle
pydle/features/whox.py
WHOXSupport.on_raw_354
async def on_raw_354(self, message): """ WHOX results have arrived. """ # Is the message for us? target, identifier = message.params[:2] if identifier != WHOX_IDENTIFIER: return # Great. Extract relevant information. metadata = { 'nickname': message.params[4], 'username': message.params[2], 'realname': message.params[6], 'hostname': message.params[3], } if message.params[5] != NO_ACCOUNT: metadata['identified'] = True metadata['account'] = message.params[5] self._sync_user(metadata['nickname'], metadata)
python
async def on_raw_354(self, message): """ WHOX results have arrived. """ # Is the message for us? target, identifier = message.params[:2] if identifier != WHOX_IDENTIFIER: return # Great. Extract relevant information. metadata = { 'nickname': message.params[4], 'username': message.params[2], 'realname': message.params[6], 'hostname': message.params[3], } if message.params[5] != NO_ACCOUNT: metadata['identified'] = True metadata['account'] = message.params[5] self._sync_user(metadata['nickname'], metadata)
[ "async", "def", "on_raw_354", "(", "self", ",", "message", ")", ":", "# Is the message for us?", "target", ",", "identifier", "=", "message", ".", "params", "[", ":", "2", "]", "if", "identifier", "!=", "WHOX_IDENTIFIER", ":", "return", "# Great. Extract relevan...
WHOX results have arrived.
[ "WHOX", "results", "have", "arrived", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/whox.py#L33-L51
train
23,867
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport._create_channel
def _create_channel(self, channel): """ Create channel with optional ban and invite exception lists. """ super()._create_channel(channel) if 'EXCEPTS' in self._isupport: self.channels[channel]['exceptlist'] = None if 'INVEX' in self._isupport: self.channels[channel]['inviteexceptlist'] = None
python
def _create_channel(self, channel): """ Create channel with optional ban and invite exception lists. """ super()._create_channel(channel) if 'EXCEPTS' in self._isupport: self.channels[channel]['exceptlist'] = None if 'INVEX' in self._isupport: self.channels[channel]['inviteexceptlist'] = None
[ "def", "_create_channel", "(", "self", ",", "channel", ")", ":", "super", "(", ")", ".", "_create_channel", "(", "channel", ")", "if", "'EXCEPTS'", "in", "self", ".", "_isupport", ":", "self", ".", "channels", "[", "channel", "]", "[", "'exceptlist'", "]...
Create channel with optional ban and invite exception lists.
[ "Create", "channel", "with", "optional", "ban", "and", "invite", "exception", "lists", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L27-L33
train
23,868
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_raw_005
async def on_raw_005(self, message): """ ISUPPORT indication. """ isupport = {} # Parse response. # Strip target (first argument) and 'are supported by this server' (last argument). for feature in message.params[1:-1]: if feature.startswith(FEATURE_DISABLED_PREFIX): value = False elif '=' in feature: feature, value = feature.split('=', 1) else: value = True isupport[feature.upper()] = value # Update internal dict first. self._isupport.update(isupport) # And have callbacks update other internals. for entry, value in isupport.items(): if value != False: # A value of True technically means there was no value supplied; correct this for callbacks. if value == True: value = None method = 'on_isupport_' + pydle.protocol.identifierify(entry) if hasattr(self, method): await getattr(self, method)(value)
python
async def on_raw_005(self, message): """ ISUPPORT indication. """ isupport = {} # Parse response. # Strip target (first argument) and 'are supported by this server' (last argument). for feature in message.params[1:-1]: if feature.startswith(FEATURE_DISABLED_PREFIX): value = False elif '=' in feature: feature, value = feature.split('=', 1) else: value = True isupport[feature.upper()] = value # Update internal dict first. self._isupport.update(isupport) # And have callbacks update other internals. for entry, value in isupport.items(): if value != False: # A value of True technically means there was no value supplied; correct this for callbacks. if value == True: value = None method = 'on_isupport_' + pydle.protocol.identifierify(entry) if hasattr(self, method): await getattr(self, method)(value)
[ "async", "def", "on_raw_005", "(", "self", ",", "message", ")", ":", "isupport", "=", "{", "}", "# Parse response.", "# Strip target (first argument) and 'are supported by this server' (last argument).", "for", "feature", "in", "message", ".", "params", "[", "1", ":", ...
ISUPPORT indication.
[ "ISUPPORT", "indication", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L38-L65
train
23,869
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_casemapping
async def on_isupport_casemapping(self, value): """ IRC case mapping for nickname and channel name comparisons. """ if value in rfc1459.protocol.CASE_MAPPINGS: self._case_mapping = value self.channels = rfc1459.parsing.NormalizingDict(self.channels, case_mapping=value) self.users = rfc1459.parsing.NormalizingDict(self.users, case_mapping=value)
python
async def on_isupport_casemapping(self, value): """ IRC case mapping for nickname and channel name comparisons. """ if value in rfc1459.protocol.CASE_MAPPINGS: self._case_mapping = value self.channels = rfc1459.parsing.NormalizingDict(self.channels, case_mapping=value) self.users = rfc1459.parsing.NormalizingDict(self.users, case_mapping=value)
[ "async", "def", "on_isupport_casemapping", "(", "self", ",", "value", ")", ":", "if", "value", "in", "rfc1459", ".", "protocol", ".", "CASE_MAPPINGS", ":", "self", ".", "_case_mapping", "=", "value", "self", ".", "channels", "=", "rfc1459", ".", "parsing", ...
IRC case mapping for nickname and channel name comparisons.
[ "IRC", "case", "mapping", "for", "nickname", "and", "channel", "name", "comparisons", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L74-L79
train
23,870
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_chanlimit
async def on_isupport_chanlimit(self, value): """ Simultaneous channel limits for user. """ self._channel_limits = {} for entry in value.split(','): types, limit = entry.split(':') # Assign limit to channel type group and add lookup entry for type. self._channel_limits[frozenset(types)] = int(limit) for prefix in types: self._channel_limit_groups[prefix] = frozenset(types)
python
async def on_isupport_chanlimit(self, value): """ Simultaneous channel limits for user. """ self._channel_limits = {} for entry in value.split(','): types, limit = entry.split(':') # Assign limit to channel type group and add lookup entry for type. self._channel_limits[frozenset(types)] = int(limit) for prefix in types: self._channel_limit_groups[prefix] = frozenset(types)
[ "async", "def", "on_isupport_chanlimit", "(", "self", ",", "value", ")", ":", "self", ".", "_channel_limits", "=", "{", "}", "for", "entry", "in", "value", ".", "split", "(", "','", ")", ":", "types", ",", "limit", "=", "entry", ".", "split", "(", "'...
Simultaneous channel limits for user.
[ "Simultaneous", "channel", "limits", "for", "user", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L85-L95
train
23,871
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_chanmodes
async def on_isupport_chanmodes(self, value): """ Valid channel modes and their behaviour. """ list, param, param_set, noparams = [ set(modes) for modes in value.split(',')[:4] ] self._channel_modes.update(set(value.replace(',', ''))) # The reason we have to do it like this is because other ISUPPORTs (e.g. PREFIX) may update these values as well. if not rfc1459.protocol.BEHAVIOUR_LIST in self._channel_modes_behaviour: self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_LIST] = set() self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_LIST].update(list) if not rfc1459.protocol.BEHAVIOUR_PARAMETER in self._channel_modes_behaviour: self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER] = set() self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER].update(param) if not rfc1459.protocol.BEHAVIOUR_PARAMETER_ON_SET in self._channel_modes_behaviour: self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER_ON_SET] = set() self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER_ON_SET].update(param_set) if not rfc1459.protocol.BEHAVIOUR_NO_PARAMETER in self._channel_modes_behaviour: self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_NO_PARAMETER] = set() self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_NO_PARAMETER].update(noparams)
python
async def on_isupport_chanmodes(self, value): """ Valid channel modes and their behaviour. """ list, param, param_set, noparams = [ set(modes) for modes in value.split(',')[:4] ] self._channel_modes.update(set(value.replace(',', ''))) # The reason we have to do it like this is because other ISUPPORTs (e.g. PREFIX) may update these values as well. if not rfc1459.protocol.BEHAVIOUR_LIST in self._channel_modes_behaviour: self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_LIST] = set() self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_LIST].update(list) if not rfc1459.protocol.BEHAVIOUR_PARAMETER in self._channel_modes_behaviour: self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER] = set() self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER].update(param) if not rfc1459.protocol.BEHAVIOUR_PARAMETER_ON_SET in self._channel_modes_behaviour: self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER_ON_SET] = set() self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER_ON_SET].update(param_set) if not rfc1459.protocol.BEHAVIOUR_NO_PARAMETER in self._channel_modes_behaviour: self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_NO_PARAMETER] = set() self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_NO_PARAMETER].update(noparams)
[ "async", "def", "on_isupport_chanmodes", "(", "self", ",", "value", ")", ":", "list", ",", "param", ",", "param_set", ",", "noparams", "=", "[", "set", "(", "modes", ")", "for", "modes", "in", "value", ".", "split", "(", "','", ")", "[", ":", "4", ...
Valid channel modes and their behaviour.
[ "Valid", "channel", "modes", "and", "their", "behaviour", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L97-L117
train
23,872
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_excepts
async def on_isupport_excepts(self, value): """ Server allows ban exceptions. """ if not value: value = BAN_EXCEPT_MODE self._channel_modes.add(value) self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_LIST].add(value)
python
async def on_isupport_excepts(self, value): """ Server allows ban exceptions. """ if not value: value = BAN_EXCEPT_MODE self._channel_modes.add(value) self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_LIST].add(value)
[ "async", "def", "on_isupport_excepts", "(", "self", ",", "value", ")", ":", "if", "not", "value", ":", "value", "=", "BAN_EXCEPT_MODE", "self", ".", "_channel_modes", ".", "add", "(", "value", ")", "self", ".", "_channel_modes_behaviour", "[", "rfc1459", "."...
Server allows ban exceptions.
[ "Server", "allows", "ban", "exceptions", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L125-L130
train
23,873
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_extban
async def on_isupport_extban(self, value): """ Extended ban prefixes. """ self._extban_prefix, types = value.split(',') self._extban_types = set(types)
python
async def on_isupport_extban(self, value): """ Extended ban prefixes. """ self._extban_prefix, types = value.split(',') self._extban_types = set(types)
[ "async", "def", "on_isupport_extban", "(", "self", ",", "value", ")", ":", "self", ".", "_extban_prefix", ",", "types", "=", "value", ".", "split", "(", "','", ")", "self", ".", "_extban_types", "=", "set", "(", "types", ")" ]
Extended ban prefixes.
[ "Extended", "ban", "prefixes", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L132-L135
train
23,874
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_invex
async def on_isupport_invex(self, value): """ Server allows invite exceptions. """ if not value: value = INVITE_EXCEPT_MODE self._channel_modes.add(value) self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_LIST].add(value)
python
async def on_isupport_invex(self, value): """ Server allows invite exceptions. """ if not value: value = INVITE_EXCEPT_MODE self._channel_modes.add(value) self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_LIST].add(value)
[ "async", "def", "on_isupport_invex", "(", "self", ",", "value", ")", ":", "if", "not", "value", ":", "value", "=", "INVITE_EXCEPT_MODE", "self", ".", "_channel_modes", ".", "add", "(", "value", ")", "self", ".", "_channel_modes_behaviour", "[", "rfc1459", "....
Server allows invite exceptions.
[ "Server", "allows", "invite", "exceptions", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L137-L142
train
23,875
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_maxbans
async def on_isupport_maxbans(self, value): """ Maximum entries in ban list. Replaced by MAXLIST. """ if 'MAXLIST' not in self._isupport: if not self._list_limits: self._list_limits = {} self._list_limits['b'] = int(value)
python
async def on_isupport_maxbans(self, value): """ Maximum entries in ban list. Replaced by MAXLIST. """ if 'MAXLIST' not in self._isupport: if not self._list_limits: self._list_limits = {} self._list_limits['b'] = int(value)
[ "async", "def", "on_isupport_maxbans", "(", "self", ",", "value", ")", ":", "if", "'MAXLIST'", "not", "in", "self", ".", "_isupport", ":", "if", "not", "self", ".", "_list_limits", ":", "self", ".", "_list_limits", "=", "{", "}", "self", ".", "_list_limi...
Maximum entries in ban list. Replaced by MAXLIST.
[ "Maximum", "entries", "in", "ban", "list", ".", "Replaced", "by", "MAXLIST", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L144-L149
train
23,876
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_maxchannels
async def on_isupport_maxchannels(self, value): """ Old version of CHANLIMIT. """ if 'CHANTYPES' in self._isupport and 'CHANLIMIT' not in self._isupport: self._channel_limits = {} prefixes = self._isupport['CHANTYPES'] # Assume the limit is for all types of channels. Make a single group for all types. self._channel_limits[frozenset(prefixes)] = int(value) for prefix in prefixes: self._channel_limit_groups[prefix] = frozenset(prefixes)
python
async def on_isupport_maxchannels(self, value): """ Old version of CHANLIMIT. """ if 'CHANTYPES' in self._isupport and 'CHANLIMIT' not in self._isupport: self._channel_limits = {} prefixes = self._isupport['CHANTYPES'] # Assume the limit is for all types of channels. Make a single group for all types. self._channel_limits[frozenset(prefixes)] = int(value) for prefix in prefixes: self._channel_limit_groups[prefix] = frozenset(prefixes)
[ "async", "def", "on_isupport_maxchannels", "(", "self", ",", "value", ")", ":", "if", "'CHANTYPES'", "in", "self", ".", "_isupport", "and", "'CHANLIMIT'", "not", "in", "self", ".", "_isupport", ":", "self", ".", "_channel_limits", "=", "{", "}", "prefixes", ...
Old version of CHANLIMIT.
[ "Old", "version", "of", "CHANLIMIT", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L151-L160
train
23,877
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_maxlist
async def on_isupport_maxlist(self, value): """ Limits on channel modes involving lists. """ self._list_limits = {} for entry in value.split(','): modes, limit = entry.split(':') # Assign limit to mode group and add lookup entry for mode. self._list_limits[frozenset(modes)] = int(limit) for mode in modes: self._list_limit_groups[mode] = frozenset(modes)
python
async def on_isupport_maxlist(self, value): """ Limits on channel modes involving lists. """ self._list_limits = {} for entry in value.split(','): modes, limit = entry.split(':') # Assign limit to mode group and add lookup entry for mode. self._list_limits[frozenset(modes)] = int(limit) for mode in modes: self._list_limit_groups[mode] = frozenset(modes)
[ "async", "def", "on_isupport_maxlist", "(", "self", ",", "value", ")", ":", "self", ".", "_list_limits", "=", "{", "}", "for", "entry", "in", "value", ".", "split", "(", "','", ")", ":", "modes", ",", "limit", "=", "entry", ".", "split", "(", "':'", ...
Limits on channel modes involving lists.
[ "Limits", "on", "channel", "modes", "involving", "lists", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L162-L172
train
23,878
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_prefix
async def on_isupport_prefix(self, value): """ Nickname prefixes on channels and their associated modes. """ if not value: # No prefixes support. self._nickname_prefixes = collections.OrderedDict() return modes, prefixes = value.lstrip('(').split(')', 1) # Update valid channel modes and their behaviour as CHANMODES doesn't include PREFIX modes. self._channel_modes.update(set(modes)) if not rfc1459.protocol.BEHAVIOUR_PARAMETER in self._channel_modes_behaviour: self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER] = set() self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER].update(set(modes)) self._nickname_prefixes = collections.OrderedDict() for mode, prefix in zip(modes, prefixes): self._nickname_prefixes[prefix] = mode
python
async def on_isupport_prefix(self, value): """ Nickname prefixes on channels and their associated modes. """ if not value: # No prefixes support. self._nickname_prefixes = collections.OrderedDict() return modes, prefixes = value.lstrip('(').split(')', 1) # Update valid channel modes and their behaviour as CHANMODES doesn't include PREFIX modes. self._channel_modes.update(set(modes)) if not rfc1459.protocol.BEHAVIOUR_PARAMETER in self._channel_modes_behaviour: self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER] = set() self._channel_modes_behaviour[rfc1459.protocol.BEHAVIOUR_PARAMETER].update(set(modes)) self._nickname_prefixes = collections.OrderedDict() for mode, prefix in zip(modes, prefixes): self._nickname_prefixes[prefix] = mode
[ "async", "def", "on_isupport_prefix", "(", "self", ",", "value", ")", ":", "if", "not", "value", ":", "# No prefixes support.", "self", ".", "_nickname_prefixes", "=", "collections", ".", "OrderedDict", "(", ")", "return", "modes", ",", "prefixes", "=", "value...
Nickname prefixes on channels and their associated modes.
[ "Nickname", "prefixes", "on", "channels", "and", "their", "associated", "modes", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L194-L211
train
23,879
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_targmax
async def on_isupport_targmax(self, value): """ The maximum number of targets certain types of commands can affect. """ if not value: return for entry in value.split(','): command, limit = entry.split(':', 1) if not limit: continue self._target_limits[command] = int(limit)
python
async def on_isupport_targmax(self, value): """ The maximum number of targets certain types of commands can affect. """ if not value: return for entry in value.split(','): command, limit = entry.split(':', 1) if not limit: continue self._target_limits[command] = int(limit)
[ "async", "def", "on_isupport_targmax", "(", "self", ",", "value", ")", ":", "if", "not", "value", ":", "return", "for", "entry", "in", "value", ".", "split", "(", "','", ")", ":", "command", ",", "limit", "=", "entry", ".", "split", "(", "':'", ",", ...
The maximum number of targets certain types of commands can affect.
[ "The", "maximum", "number", "of", "targets", "certain", "types", "of", "commands", "can", "affect", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L217-L226
train
23,880
Shizmob/pydle
pydle/features/isupport.py
ISUPPORTSupport.on_isupport_wallchops
async def on_isupport_wallchops(self, value): """ Support for messaging every opped member or higher on a channel. Replaced by STATUSMSG. """ for prefix, mode in self._nickname_prefixes.items(): if mode == 'o': break else: prefix = '@' self._status_message_prefixes.add(prefix)
python
async def on_isupport_wallchops(self, value): """ Support for messaging every opped member or higher on a channel. Replaced by STATUSMSG. """ for prefix, mode in self._nickname_prefixes.items(): if mode == 'o': break else: prefix = '@' self._status_message_prefixes.add(prefix)
[ "async", "def", "on_isupport_wallchops", "(", "self", ",", "value", ")", ":", "for", "prefix", ",", "mode", "in", "self", ".", "_nickname_prefixes", ".", "items", "(", ")", ":", "if", "mode", "==", "'o'", ":", "break", "else", ":", "prefix", "=", "'@'"...
Support for messaging every opped member or higher on a channel. Replaced by STATUSMSG.
[ "Support", "for", "messaging", "every", "opped", "member", "or", "higher", "on", "a", "channel", ".", "Replaced", "by", "STATUSMSG", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/isupport.py#L232-L239
train
23,881
Shizmob/pydle
pydle/features/ircv3/tags.py
TaggedMessage.parse
def parse(cls, line, encoding=pydle.protocol.DEFAULT_ENCODING): """ Parse given line into IRC message structure. Returns a TaggedMessage. """ valid = True # Decode message. try: message = line.decode(encoding) except UnicodeDecodeError: # Try our fallback encoding. message = line.decode(pydle.protocol.FALLBACK_ENCODING) # Sanity check for message length. if len(message) > TAGGED_MESSAGE_LENGTH_LIMIT: valid = False # Strip message separator. if message.endswith(rfc1459.protocol.LINE_SEPARATOR): message = message[:-len(rfc1459.protocol.LINE_SEPARATOR)] elif message.endswith(rfc1459.protocol.MINIMAL_LINE_SEPARATOR): message = message[:-len(rfc1459.protocol.MINIMAL_LINE_SEPARATOR)] raw = message # Parse tags. tags = {} if message.startswith(TAG_INDICATOR): message = message[len(TAG_INDICATOR):] raw_tags, message = message.split(' ', 1) for raw_tag in raw_tags.split(TAG_SEPARATOR): if TAG_VALUE_SEPARATOR in raw_tag: tag, value = raw_tag.split(TAG_VALUE_SEPARATOR, 1) else: tag = raw_tag value = True tags[tag] = value # Parse rest of message. message = super().parse(message.lstrip().encode(encoding), encoding=encoding) return TaggedMessage(_raw=raw, _valid=message._valid and valid, tags=tags, **message._kw)
python
def parse(cls, line, encoding=pydle.protocol.DEFAULT_ENCODING): """ Parse given line into IRC message structure. Returns a TaggedMessage. """ valid = True # Decode message. try: message = line.decode(encoding) except UnicodeDecodeError: # Try our fallback encoding. message = line.decode(pydle.protocol.FALLBACK_ENCODING) # Sanity check for message length. if len(message) > TAGGED_MESSAGE_LENGTH_LIMIT: valid = False # Strip message separator. if message.endswith(rfc1459.protocol.LINE_SEPARATOR): message = message[:-len(rfc1459.protocol.LINE_SEPARATOR)] elif message.endswith(rfc1459.protocol.MINIMAL_LINE_SEPARATOR): message = message[:-len(rfc1459.protocol.MINIMAL_LINE_SEPARATOR)] raw = message # Parse tags. tags = {} if message.startswith(TAG_INDICATOR): message = message[len(TAG_INDICATOR):] raw_tags, message = message.split(' ', 1) for raw_tag in raw_tags.split(TAG_SEPARATOR): if TAG_VALUE_SEPARATOR in raw_tag: tag, value = raw_tag.split(TAG_VALUE_SEPARATOR, 1) else: tag = raw_tag value = True tags[tag] = value # Parse rest of message. message = super().parse(message.lstrip().encode(encoding), encoding=encoding) return TaggedMessage(_raw=raw, _valid=message._valid and valid, tags=tags, **message._kw)
[ "def", "parse", "(", "cls", ",", "line", ",", "encoding", "=", "pydle", ".", "protocol", ".", "DEFAULT_ENCODING", ")", ":", "valid", "=", "True", "# Decode message.", "try", ":", "message", "=", "line", ".", "decode", "(", "encoding", ")", "except", "Uni...
Parse given line into IRC message structure. Returns a TaggedMessage.
[ "Parse", "given", "line", "into", "IRC", "message", "structure", ".", "Returns", "a", "TaggedMessage", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/tags.py#L20-L60
train
23,882
Shizmob/pydle
pydle/features/ircv3/tags.py
TaggedMessage.construct
def construct(self, force=False): """ Construct raw IRC message and return it. """ message = super().construct(force=force) # Add tags. if self.tags: raw_tags = [] for tag, value in self.tags.items(): if value == True: raw_tags.append(tag) else: raw_tags.append(tag + TAG_VALUE_SEPARATOR + value) message = TAG_INDICATOR + TAG_SEPARATOR.join(raw_tags) + ' ' + message if len(message) > TAGGED_MESSAGE_LENGTH_LIMIT and not force: raise protocol.ProtocolViolation('The constructed message is too long. ({len} > {maxlen})'.format(len=len(message), maxlen=TAGGED_MESSAGE_LENGTH_LIMIT), message=message) return message
python
def construct(self, force=False): """ Construct raw IRC message and return it. """ message = super().construct(force=force) # Add tags. if self.tags: raw_tags = [] for tag, value in self.tags.items(): if value == True: raw_tags.append(tag) else: raw_tags.append(tag + TAG_VALUE_SEPARATOR + value) message = TAG_INDICATOR + TAG_SEPARATOR.join(raw_tags) + ' ' + message if len(message) > TAGGED_MESSAGE_LENGTH_LIMIT and not force: raise protocol.ProtocolViolation('The constructed message is too long. ({len} > {maxlen})'.format(len=len(message), maxlen=TAGGED_MESSAGE_LENGTH_LIMIT), message=message) return message
[ "def", "construct", "(", "self", ",", "force", "=", "False", ")", ":", "message", "=", "super", "(", ")", ".", "construct", "(", "force", "=", "force", ")", "# Add tags.", "if", "self", ".", "tags", ":", "raw_tags", "=", "[", "]", "for", "tag", ","...
Construct raw IRC message and return it.
[ "Construct", "raw", "IRC", "message", "and", "return", "it", "." ]
7ec7d65d097318ed0bcdc5d8401470287d8c7cf7
https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/tags.py#L62-L81
train
23,883
rbaier/python-urltools
urltools/urltools.py
_get_public_suffix_list
def _get_public_suffix_list(): """Return a set containing all Public Suffixes. If the env variable PUBLIC_SUFFIX_LIST does not point to a local copy of the public suffix list it is downloaded into memory each time urltools is imported. """ local_psl = os.environ.get('PUBLIC_SUFFIX_LIST') if local_psl: with codecs.open(local_psl, 'r', 'utf-8') as f: psl_raw = f.readlines() else: psl_raw = unicode(urlopen(PSL_URL).read(), 'utf-8').split('\n') psl = set() for line in psl_raw: item = line.strip() if item != '' and not item.startswith('//'): psl.add(item) return psl
python
def _get_public_suffix_list(): """Return a set containing all Public Suffixes. If the env variable PUBLIC_SUFFIX_LIST does not point to a local copy of the public suffix list it is downloaded into memory each time urltools is imported. """ local_psl = os.environ.get('PUBLIC_SUFFIX_LIST') if local_psl: with codecs.open(local_psl, 'r', 'utf-8') as f: psl_raw = f.readlines() else: psl_raw = unicode(urlopen(PSL_URL).read(), 'utf-8').split('\n') psl = set() for line in psl_raw: item = line.strip() if item != '' and not item.startswith('//'): psl.add(item) return psl
[ "def", "_get_public_suffix_list", "(", ")", ":", "local_psl", "=", "os", ".", "environ", ".", "get", "(", "'PUBLIC_SUFFIX_LIST'", ")", "if", "local_psl", ":", "with", "codecs", ".", "open", "(", "local_psl", ",", "'r'", ",", "'utf-8'", ")", "as", "f", ":...
Return a set containing all Public Suffixes. If the env variable PUBLIC_SUFFIX_LIST does not point to a local copy of the public suffix list it is downloaded into memory each time urltools is imported.
[ "Return", "a", "set", "containing", "all", "Public", "Suffixes", "." ]
76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1
https://github.com/rbaier/python-urltools/blob/76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1/urltools/urltools.py#L26-L44
train
23,884
rbaier/python-urltools
urltools/urltools.py
normalize
def normalize(url): """Normalize a URL. >>> normalize('hTtp://ExAMPLe.COM:80') 'http://example.com/' """ url = url.strip() if url == '': return '' parts = split(url) if parts.scheme: netloc = parts.netloc if parts.scheme in SCHEMES: path = normalize_path(parts.path) else: path = parts.path # url is relative, netloc (if present) is part of path else: netloc = parts.path path = '' if '/' in netloc: netloc, path_raw = netloc.split('/', 1) path = normalize_path('/' + path_raw) username, password, host, port = split_netloc(netloc) host = normalize_host(host) port = _normalize_port(parts.scheme, port) query = normalize_query(parts.query) fragment = normalize_fragment(parts.fragment) return construct(URL(parts.scheme, username, password, None, host, None, port, path, query, fragment, None))
python
def normalize(url): """Normalize a URL. >>> normalize('hTtp://ExAMPLe.COM:80') 'http://example.com/' """ url = url.strip() if url == '': return '' parts = split(url) if parts.scheme: netloc = parts.netloc if parts.scheme in SCHEMES: path = normalize_path(parts.path) else: path = parts.path # url is relative, netloc (if present) is part of path else: netloc = parts.path path = '' if '/' in netloc: netloc, path_raw = netloc.split('/', 1) path = normalize_path('/' + path_raw) username, password, host, port = split_netloc(netloc) host = normalize_host(host) port = _normalize_port(parts.scheme, port) query = normalize_query(parts.query) fragment = normalize_fragment(parts.fragment) return construct(URL(parts.scheme, username, password, None, host, None, port, path, query, fragment, None))
[ "def", "normalize", "(", "url", ")", ":", "url", "=", "url", ".", "strip", "(", ")", "if", "url", "==", "''", ":", "return", "''", "parts", "=", "split", "(", "url", ")", "if", "parts", ".", "scheme", ":", "netloc", "=", "parts", ".", "netloc", ...
Normalize a URL. >>> normalize('hTtp://ExAMPLe.COM:80') 'http://example.com/'
[ "Normalize", "a", "URL", "." ]
76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1
https://github.com/rbaier/python-urltools/blob/76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1/urltools/urltools.py#L78-L107
train
23,885
rbaier/python-urltools
urltools/urltools.py
_encode_query
def _encode_query(query): """Quote all values of a query string.""" if query == '': return query query_args = [] for query_kv in query.split('&'): k, v = query_kv.split('=') query_args.append(k + "=" + quote(v.encode('utf-8'))) return '&'.join(query_args)
python
def _encode_query(query): """Quote all values of a query string.""" if query == '': return query query_args = [] for query_kv in query.split('&'): k, v = query_kv.split('=') query_args.append(k + "=" + quote(v.encode('utf-8'))) return '&'.join(query_args)
[ "def", "_encode_query", "(", "query", ")", ":", "if", "query", "==", "''", ":", "return", "query", "query_args", "=", "[", "]", "for", "query_kv", "in", "query", ".", "split", "(", "'&'", ")", ":", "k", ",", "v", "=", "query_kv", ".", "split", "(",...
Quote all values of a query string.
[ "Quote", "all", "values", "of", "a", "query", "string", "." ]
76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1
https://github.com/rbaier/python-urltools/blob/76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1/urltools/urltools.py#L123-L131
train
23,886
rbaier/python-urltools
urltools/urltools.py
encode
def encode(url): """Encode URL.""" parts = extract(url) return construct(URL(parts.scheme, parts.username, parts.password, _idna_encode(parts.subdomain), _idna_encode(parts.domain), _idna_encode(parts.tld), parts.port, quote(parts.path.encode('utf-8')), _encode_query(parts.query), quote(parts.fragment.encode('utf-8')), None))
python
def encode(url): """Encode URL.""" parts = extract(url) return construct(URL(parts.scheme, parts.username, parts.password, _idna_encode(parts.subdomain), _idna_encode(parts.domain), _idna_encode(parts.tld), parts.port, quote(parts.path.encode('utf-8')), _encode_query(parts.query), quote(parts.fragment.encode('utf-8')), None))
[ "def", "encode", "(", "url", ")", ":", "parts", "=", "extract", "(", "url", ")", "return", "construct", "(", "URL", "(", "parts", ".", "scheme", ",", "parts", ".", "username", ",", "parts", ".", "password", ",", "_idna_encode", "(", "parts", ".", "su...
Encode URL.
[ "Encode", "URL", "." ]
76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1
https://github.com/rbaier/python-urltools/blob/76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1/urltools/urltools.py#L134-L147
train
23,887
rbaier/python-urltools
urltools/urltools.py
construct
def construct(parts): """Construct a new URL from parts.""" url = '' if parts.scheme: if parts.scheme in SCHEMES: url += parts.scheme + '://' else: url += parts.scheme + ':' if parts.username and parts.password: url += parts.username + ':' + parts.password + '@' elif parts.username: url += parts.username + '@' if parts.subdomain: url += parts.subdomain + '.' url += parts.domain if parts.tld: url += '.' + parts.tld if parts.port: url += ':' + parts.port if parts.path: url += parts.path if parts.query: url += '?' + parts.query if parts.fragment: url += '#' + parts.fragment return url
python
def construct(parts): """Construct a new URL from parts.""" url = '' if parts.scheme: if parts.scheme in SCHEMES: url += parts.scheme + '://' else: url += parts.scheme + ':' if parts.username and parts.password: url += parts.username + ':' + parts.password + '@' elif parts.username: url += parts.username + '@' if parts.subdomain: url += parts.subdomain + '.' url += parts.domain if parts.tld: url += '.' + parts.tld if parts.port: url += ':' + parts.port if parts.path: url += parts.path if parts.query: url += '?' + parts.query if parts.fragment: url += '#' + parts.fragment return url
[ "def", "construct", "(", "parts", ")", ":", "url", "=", "''", "if", "parts", ".", "scheme", ":", "if", "parts", ".", "scheme", "in", "SCHEMES", ":", "url", "+=", "parts", ".", "scheme", "+", "'://'", "else", ":", "url", "+=", "parts", ".", "scheme"...
Construct a new URL from parts.
[ "Construct", "a", "new", "URL", "from", "parts", "." ]
76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1
https://github.com/rbaier/python-urltools/blob/76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1/urltools/urltools.py#L150-L175
train
23,888
rbaier/python-urltools
urltools/urltools.py
_normalize_port
def _normalize_port(scheme, port): """Return port if it is not default port, else None. >>> _normalize_port('http', '80') >>> _normalize_port('http', '8080') '8080' """ if not scheme: return port if port and port != DEFAULT_PORT[scheme]: return port
python
def _normalize_port(scheme, port): """Return port if it is not default port, else None. >>> _normalize_port('http', '80') >>> _normalize_port('http', '8080') '8080' """ if not scheme: return port if port and port != DEFAULT_PORT[scheme]: return port
[ "def", "_normalize_port", "(", "scheme", ",", "port", ")", ":", "if", "not", "scheme", ":", "return", "port", "if", "port", "and", "port", "!=", "DEFAULT_PORT", "[", "scheme", "]", ":", "return", "port" ]
Return port if it is not default port, else None. >>> _normalize_port('http', '80') >>> _normalize_port('http', '8080') '8080'
[ "Return", "port", "if", "it", "is", "not", "default", "port", "else", "None", "." ]
76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1
https://github.com/rbaier/python-urltools/blob/76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1/urltools/urltools.py#L189-L200
train
23,889
rbaier/python-urltools
urltools/urltools.py
unquote
def unquote(text, exceptions=[]): """Unquote a text but ignore the exceptions. >>> unquote('foo%23bar') 'foo#bar' >>> unquote('foo%23bar', ['#']) 'foo%23bar' """ if not text: if text is None: raise TypeError('None object cannot be unquoted') else: return text if '%' not in text: return text s = text.split('%') res = [s[0]] for h in s[1:]: c = _hextochr.get(h[:2]) if c and c not in exceptions: if len(h) > 2: res.append(c + h[2:]) else: res.append(c) else: res.append('%' + h) return ''.join(res)
python
def unquote(text, exceptions=[]): """Unquote a text but ignore the exceptions. >>> unquote('foo%23bar') 'foo#bar' >>> unquote('foo%23bar', ['#']) 'foo%23bar' """ if not text: if text is None: raise TypeError('None object cannot be unquoted') else: return text if '%' not in text: return text s = text.split('%') res = [s[0]] for h in s[1:]: c = _hextochr.get(h[:2]) if c and c not in exceptions: if len(h) > 2: res.append(c + h[2:]) else: res.append(c) else: res.append('%' + h) return ''.join(res)
[ "def", "unquote", "(", "text", ",", "exceptions", "=", "[", "]", ")", ":", "if", "not", "text", ":", "if", "text", "is", "None", ":", "raise", "TypeError", "(", "'None object cannot be unquoted'", ")", "else", ":", "return", "text", "if", "'%'", "not", ...
Unquote a text but ignore the exceptions. >>> unquote('foo%23bar') 'foo#bar' >>> unquote('foo%23bar', ['#']) 'foo%23bar'
[ "Unquote", "a", "text", "but", "ignore", "the", "exceptions", "." ]
76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1
https://github.com/rbaier/python-urltools/blob/76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1/urltools/urltools.py#L246-L272
train
23,890
rbaier/python-urltools
urltools/urltools.py
split
def split(url): """Split URL into scheme, netloc, path, query and fragment. >>> split('http://www.example.com/abc?x=1&y=2#foo') SplitResult(scheme='http', netloc='www.example.com', path='/abc', query='x=1&y=2', fragment='foo') """ scheme = netloc = path = query = fragment = '' ip6_start = url.find('[') scheme_end = url.find(':') if ip6_start > 0 and ip6_start < scheme_end: scheme_end = -1 if scheme_end > 0: for c in url[:scheme_end]: if c not in SCHEME_CHARS: break else: scheme = url[:scheme_end].lower() rest = url[scheme_end:].lstrip(':/') if not scheme: rest = url l_path = rest.find('/') l_query = rest.find('?') l_frag = rest.find('#') if l_path > 0: if l_query > 0 and l_frag > 0: netloc = rest[:l_path] path = rest[l_path:min(l_query, l_frag)] elif l_query > 0: if l_query > l_path: netloc = rest[:l_path] path = rest[l_path:l_query] else: netloc = rest[:l_query] path = '' elif l_frag > 0: netloc = rest[:l_path] path = rest[l_path:l_frag] else: netloc = rest[:l_path] path = rest[l_path:] else: if l_query > 0: netloc = rest[:l_query] elif l_frag > 0: netloc = rest[:l_frag] else: netloc = rest if l_query > 0: if l_frag > 0: query = rest[l_query+1:l_frag] else: query = rest[l_query+1:] if l_frag > 0: fragment = rest[l_frag+1:] if not scheme: path = netloc + path netloc = '' return SplitResult(scheme, netloc, path, query, fragment)
python
def split(url): """Split URL into scheme, netloc, path, query and fragment. >>> split('http://www.example.com/abc?x=1&y=2#foo') SplitResult(scheme='http', netloc='www.example.com', path='/abc', query='x=1&y=2', fragment='foo') """ scheme = netloc = path = query = fragment = '' ip6_start = url.find('[') scheme_end = url.find(':') if ip6_start > 0 and ip6_start < scheme_end: scheme_end = -1 if scheme_end > 0: for c in url[:scheme_end]: if c not in SCHEME_CHARS: break else: scheme = url[:scheme_end].lower() rest = url[scheme_end:].lstrip(':/') if not scheme: rest = url l_path = rest.find('/') l_query = rest.find('?') l_frag = rest.find('#') if l_path > 0: if l_query > 0 and l_frag > 0: netloc = rest[:l_path] path = rest[l_path:min(l_query, l_frag)] elif l_query > 0: if l_query > l_path: netloc = rest[:l_path] path = rest[l_path:l_query] else: netloc = rest[:l_query] path = '' elif l_frag > 0: netloc = rest[:l_path] path = rest[l_path:l_frag] else: netloc = rest[:l_path] path = rest[l_path:] else: if l_query > 0: netloc = rest[:l_query] elif l_frag > 0: netloc = rest[:l_frag] else: netloc = rest if l_query > 0: if l_frag > 0: query = rest[l_query+1:l_frag] else: query = rest[l_query+1:] if l_frag > 0: fragment = rest[l_frag+1:] if not scheme: path = netloc + path netloc = '' return SplitResult(scheme, netloc, path, query, fragment)
[ "def", "split", "(", "url", ")", ":", "scheme", "=", "netloc", "=", "path", "=", "query", "=", "fragment", "=", "''", "ip6_start", "=", "url", ".", "find", "(", "'['", ")", "scheme_end", "=", "url", ".", "find", "(", "':'", ")", "if", "ip6_start", ...
Split URL into scheme, netloc, path, query and fragment. >>> split('http://www.example.com/abc?x=1&y=2#foo') SplitResult(scheme='http', netloc='www.example.com', path='/abc', query='x=1&y=2', fragment='foo')
[ "Split", "URL", "into", "scheme", "netloc", "path", "query", "and", "fragment", "." ]
76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1
https://github.com/rbaier/python-urltools/blob/76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1/urltools/urltools.py#L313-L370
train
23,891
rbaier/python-urltools
urltools/urltools.py
split_netloc
def split_netloc(netloc): """Split netloc into username, password, host and port. >>> split_netloc('foo:bar@www.example.com:8080') ('foo', 'bar', 'www.example.com', '8080') """ username = password = host = port = '' if '@' in netloc: user_pw, netloc = netloc.split('@', 1) if ':' in user_pw: username, password = user_pw.split(':', 1) else: username = user_pw netloc = _clean_netloc(netloc) if ':' in netloc and netloc[-1] != ']': host, port = netloc.rsplit(':', 1) else: host = netloc return username, password, host, port
python
def split_netloc(netloc): """Split netloc into username, password, host and port. >>> split_netloc('foo:bar@www.example.com:8080') ('foo', 'bar', 'www.example.com', '8080') """ username = password = host = port = '' if '@' in netloc: user_pw, netloc = netloc.split('@', 1) if ':' in user_pw: username, password = user_pw.split(':', 1) else: username = user_pw netloc = _clean_netloc(netloc) if ':' in netloc and netloc[-1] != ']': host, port = netloc.rsplit(':', 1) else: host = netloc return username, password, host, port
[ "def", "split_netloc", "(", "netloc", ")", ":", "username", "=", "password", "=", "host", "=", "port", "=", "''", "if", "'@'", "in", "netloc", ":", "user_pw", ",", "netloc", "=", "netloc", ".", "split", "(", "'@'", ",", "1", ")", "if", "':'", "in",...
Split netloc into username, password, host and port. >>> split_netloc('foo:bar@www.example.com:8080') ('foo', 'bar', 'www.example.com', '8080')
[ "Split", "netloc", "into", "username", "password", "host", "and", "port", "." ]
76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1
https://github.com/rbaier/python-urltools/blob/76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1/urltools/urltools.py#L385-L403
train
23,892
rbaier/python-urltools
urltools/urltools.py
split_host
def split_host(host): """Use the Public Suffix List to split host into subdomain, domain and tld. >>> split_host('foo.bar.co.uk') ('foo', 'bar', 'co.uk') """ # host is IPv6? if '[' in host: return '', host, '' # host is IPv4? for c in host: if c not in IP_CHARS: break else: return '', host, '' # host is a domain name domain = subdomain = tld = '' parts = host.split('.') for i in range(len(parts)): tld = '.'.join(parts[i:]) wildcard_tld = '*.' + tld exception_tld = '!' + tld if exception_tld in PSL: domain = '.'.join(parts[:i+1]) tld = '.'.join(parts[i+1:]) break if tld in PSL: domain = '.'.join(parts[:i]) break if wildcard_tld in PSL: domain = '.'.join(parts[:i-1]) tld = '.'.join(parts[i-1:]) break if '.' in domain: subdomain, domain = domain.rsplit('.', 1) return subdomain, domain, tld
python
def split_host(host): """Use the Public Suffix List to split host into subdomain, domain and tld. >>> split_host('foo.bar.co.uk') ('foo', 'bar', 'co.uk') """ # host is IPv6? if '[' in host: return '', host, '' # host is IPv4? for c in host: if c not in IP_CHARS: break else: return '', host, '' # host is a domain name domain = subdomain = tld = '' parts = host.split('.') for i in range(len(parts)): tld = '.'.join(parts[i:]) wildcard_tld = '*.' + tld exception_tld = '!' + tld if exception_tld in PSL: domain = '.'.join(parts[:i+1]) tld = '.'.join(parts[i+1:]) break if tld in PSL: domain = '.'.join(parts[:i]) break if wildcard_tld in PSL: domain = '.'.join(parts[:i-1]) tld = '.'.join(parts[i-1:]) break if '.' in domain: subdomain, domain = domain.rsplit('.', 1) return subdomain, domain, tld
[ "def", "split_host", "(", "host", ")", ":", "# host is IPv6?", "if", "'['", "in", "host", ":", "return", "''", ",", "host", ",", "''", "# host is IPv4?", "for", "c", "in", "host", ":", "if", "c", "not", "in", "IP_CHARS", ":", "break", "else", ":", "r...
Use the Public Suffix List to split host into subdomain, domain and tld. >>> split_host('foo.bar.co.uk') ('foo', 'bar', 'co.uk')
[ "Use", "the", "Public", "Suffix", "List", "to", "split", "host", "into", "subdomain", "domain", "and", "tld", "." ]
76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1
https://github.com/rbaier/python-urltools/blob/76bf599aeb4cb463df8e38367aa40a7d8ec7d9a1/urltools/urltools.py#L406-L441
train
23,893
mvn23/pyotgw
pyotgw/protocol.py
protocol.connection_made
def connection_made(self, transport): """ Gets called when a connection to the gateway is established. Initialise the protocol object. """ self.transport = transport self.loop = transport.loop self._cmd_lock = asyncio.Lock(loop=self.loop) self._wd_lock = asyncio.Lock(loop=self.loop) self._cmdq = asyncio.Queue(loop=self.loop) self._msgq = asyncio.Queue(loop=self.loop) self._updateq = asyncio.Queue(loop=self.loop) self._readbuf = b'' self._update_cb = None self._received_lines = 0 self._msg_task = self.loop.create_task(self._process_msgs()) self._report_task = None self._watchdog_task = None self.status = {} self.connected = True
python
def connection_made(self, transport): """ Gets called when a connection to the gateway is established. Initialise the protocol object. """ self.transport = transport self.loop = transport.loop self._cmd_lock = asyncio.Lock(loop=self.loop) self._wd_lock = asyncio.Lock(loop=self.loop) self._cmdq = asyncio.Queue(loop=self.loop) self._msgq = asyncio.Queue(loop=self.loop) self._updateq = asyncio.Queue(loop=self.loop) self._readbuf = b'' self._update_cb = None self._received_lines = 0 self._msg_task = self.loop.create_task(self._process_msgs()) self._report_task = None self._watchdog_task = None self.status = {} self.connected = True
[ "def", "connection_made", "(", "self", ",", "transport", ")", ":", "self", ".", "transport", "=", "transport", "self", ".", "loop", "=", "transport", ".", "loop", "self", ".", "_cmd_lock", "=", "asyncio", ".", "Lock", "(", "loop", "=", "self", ".", "lo...
Gets called when a connection to the gateway is established. Initialise the protocol object.
[ "Gets", "called", "when", "a", "connection", "to", "the", "gateway", "is", "established", ".", "Initialise", "the", "protocol", "object", "." ]
7612378ef4332b250176505af33e7536d6c9da78
https://github.com/mvn23/pyotgw/blob/7612378ef4332b250176505af33e7536d6c9da78/pyotgw/protocol.py#L36-L55
train
23,894
mvn23/pyotgw
pyotgw/protocol.py
protocol.connection_lost
def connection_lost(self, exc): """ Gets called when the connection to the gateway is lost. Tear down and clean up the protocol object. """ _LOGGER.error("Disconnected: %s", exc) self.connected = False self.transport.close() if self._report_task is not None: self._report_task.cancel() self._msg_task.cancel() for q in [self._cmdq, self._updateq, self._msgq]: while not q.empty(): q.get_nowait() self.status = {}
python
def connection_lost(self, exc): """ Gets called when the connection to the gateway is lost. Tear down and clean up the protocol object. """ _LOGGER.error("Disconnected: %s", exc) self.connected = False self.transport.close() if self._report_task is not None: self._report_task.cancel() self._msg_task.cancel() for q in [self._cmdq, self._updateq, self._msgq]: while not q.empty(): q.get_nowait() self.status = {}
[ "def", "connection_lost", "(", "self", ",", "exc", ")", ":", "_LOGGER", ".", "error", "(", "\"Disconnected: %s\"", ",", "exc", ")", "self", ".", "connected", "=", "False", "self", ".", "transport", ".", "close", "(", ")", "if", "self", ".", "_report_task...
Gets called when the connection to the gateway is lost. Tear down and clean up the protocol object.
[ "Gets", "called", "when", "the", "connection", "to", "the", "gateway", "is", "lost", ".", "Tear", "down", "and", "clean", "up", "the", "protocol", "object", "." ]
7612378ef4332b250176505af33e7536d6c9da78
https://github.com/mvn23/pyotgw/blob/7612378ef4332b250176505af33e7536d6c9da78/pyotgw/protocol.py#L57-L71
train
23,895
mvn23/pyotgw
pyotgw/protocol.py
protocol.setup_watchdog
async def setup_watchdog(self, cb, timeout): """Trigger a reconnect after @timeout seconds of inactivity.""" self._watchdog_timeout = timeout self._watchdog_cb = cb self._watchdog_task = self.loop.create_task(self._watchdog(timeout))
python
async def setup_watchdog(self, cb, timeout): """Trigger a reconnect after @timeout seconds of inactivity.""" self._watchdog_timeout = timeout self._watchdog_cb = cb self._watchdog_task = self.loop.create_task(self._watchdog(timeout))
[ "async", "def", "setup_watchdog", "(", "self", ",", "cb", ",", "timeout", ")", ":", "self", ".", "_watchdog_timeout", "=", "timeout", "self", ".", "_watchdog_cb", "=", "cb", "self", ".", "_watchdog_task", "=", "self", ".", "loop", ".", "create_task", "(", ...
Trigger a reconnect after @timeout seconds of inactivity.
[ "Trigger", "a", "reconnect", "after" ]
7612378ef4332b250176505af33e7536d6c9da78
https://github.com/mvn23/pyotgw/blob/7612378ef4332b250176505af33e7536d6c9da78/pyotgw/protocol.py#L96-L100
train
23,896
mvn23/pyotgw
pyotgw/protocol.py
protocol.cancel_watchdog
async def cancel_watchdog(self): """Cancel the watchdog task and related variables.""" if self._watchdog_task is not None: _LOGGER.debug("Canceling Watchdog task.") self._watchdog_task.cancel() try: await self._watchdog_task except asyncio.CancelledError: self._watchdog_task = None
python
async def cancel_watchdog(self): """Cancel the watchdog task and related variables.""" if self._watchdog_task is not None: _LOGGER.debug("Canceling Watchdog task.") self._watchdog_task.cancel() try: await self._watchdog_task except asyncio.CancelledError: self._watchdog_task = None
[ "async", "def", "cancel_watchdog", "(", "self", ")", ":", "if", "self", ".", "_watchdog_task", "is", "not", "None", ":", "_LOGGER", ".", "debug", "(", "\"Canceling Watchdog task.\"", ")", "self", ".", "_watchdog_task", ".", "cancel", "(", ")", "try", ":", ...
Cancel the watchdog task and related variables.
[ "Cancel", "the", "watchdog", "task", "and", "related", "variables", "." ]
7612378ef4332b250176505af33e7536d6c9da78
https://github.com/mvn23/pyotgw/blob/7612378ef4332b250176505af33e7536d6c9da78/pyotgw/protocol.py#L102-L110
train
23,897
mvn23/pyotgw
pyotgw/protocol.py
protocol._inform_watchdog
async def _inform_watchdog(self): """Inform the watchdog of activity.""" async with self._wd_lock: if self._watchdog_task is None: # Check within the Lock to deal with external cancel_watchdog # calls with queued _inform_watchdog tasks. return self._watchdog_task.cancel() try: await self._watchdog_task except asyncio.CancelledError: self._watchdog_task = self.loop.create_task(self._watchdog( self._watchdog_timeout))
python
async def _inform_watchdog(self): """Inform the watchdog of activity.""" async with self._wd_lock: if self._watchdog_task is None: # Check within the Lock to deal with external cancel_watchdog # calls with queued _inform_watchdog tasks. return self._watchdog_task.cancel() try: await self._watchdog_task except asyncio.CancelledError: self._watchdog_task = self.loop.create_task(self._watchdog( self._watchdog_timeout))
[ "async", "def", "_inform_watchdog", "(", "self", ")", ":", "async", "with", "self", ".", "_wd_lock", ":", "if", "self", ".", "_watchdog_task", "is", "None", ":", "# Check within the Lock to deal with external cancel_watchdog", "# calls with queued _inform_watchdog tasks.", ...
Inform the watchdog of activity.
[ "Inform", "the", "watchdog", "of", "activity", "." ]
7612378ef4332b250176505af33e7536d6c9da78
https://github.com/mvn23/pyotgw/blob/7612378ef4332b250176505af33e7536d6c9da78/pyotgw/protocol.py#L112-L124
train
23,898
mvn23/pyotgw
pyotgw/protocol.py
protocol._watchdog
async def _watchdog(self, timeout): """Trigger and cancel the watchdog after timeout. Call callback.""" await asyncio.sleep(timeout, loop=self.loop) _LOGGER.debug("Watchdog triggered!") await self.cancel_watchdog() await self._watchdog_cb()
python
async def _watchdog(self, timeout): """Trigger and cancel the watchdog after timeout. Call callback.""" await asyncio.sleep(timeout, loop=self.loop) _LOGGER.debug("Watchdog triggered!") await self.cancel_watchdog() await self._watchdog_cb()
[ "async", "def", "_watchdog", "(", "self", ",", "timeout", ")", ":", "await", "asyncio", ".", "sleep", "(", "timeout", ",", "loop", "=", "self", ".", "loop", ")", "_LOGGER", ".", "debug", "(", "\"Watchdog triggered!\"", ")", "await", "self", ".", "cancel_...
Trigger and cancel the watchdog after timeout. Call callback.
[ "Trigger", "and", "cancel", "the", "watchdog", "after", "timeout", ".", "Call", "callback", "." ]
7612378ef4332b250176505af33e7536d6c9da78
https://github.com/mvn23/pyotgw/blob/7612378ef4332b250176505af33e7536d6c9da78/pyotgw/protocol.py#L126-L131
train
23,899