code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
command = command.lower()
if command in ('enable', 'disable'):
return await self.bot.responses.failure(message='Cannot disable that command.')
if command not in self.bot.commands:
return await self.bot.responses.failure(message='Command "{}" was not found.'.for... | async def disable(self, ctx, *, command: str) | Disables a command for this server.
You must have Manage Server permissions or the
Bot Admin role to use this command. | 2.895449 | 2.758456 | 1.049663 |
command = command.lower()
guild_id = ctx.message.server.id
cmds = self.config.get('commands', {})
entries = cmds.get(guild_id, [])
try:
entries.remove(command)
except KeyError:
await self.bot.responses.failure(message='The command does no... | async def enable(self, ctx, *, command: str) | Enables a command for this server.
You must have Manage Server permissions or the
Bot Admin role to use this command. | 3.479638 | 3.352495 | 1.037925 |
if ctx.invoked_subcommand is None:
await self.bot.say('Invalid subcommand passed: {0.subcommand_passed}'.format(ctx)) | async def ignore(self, ctx) | Handles the bot's ignore lists.
To use these commands, you must have the Bot Admin role or have
Manage Channels permissions. These commands are not allowed to be used
in a private message context.
Users with Manage Roles or Bot Admin role can still invoke the bot
in ignored cha... | 3.162835 | 3.328209 | 0.950311 |
ignored = self.config.get('ignored', [])
channel_ids = set(c.id for c in ctx.message.server.channels)
result = []
for channel in ignored:
if channel in channel_ids:
result.append('<#{}>'.format(channel))
if result:
await self.bot... | async def ignore_list(self, ctx) | Tells you what channels are currently ignored in this server. | 3.776444 | 3.449909 | 1.09465 |
if channel is None:
channel = ctx.message.channel
ignored = self.config.get('ignored', [])
if channel.id in ignored:
await self.bot.responses.failure(message='That channel is already ignored.')
return
ignored.append(channel.id)
awai... | async def channel_cmd(self, ctx, *, channel : discord.Channel = None) | Ignores a specific channel from being processed.
If no channel is specified, the current channel is ignored.
If a channel is ignored then the bot does not process commands in that
channel until it is unignored. | 2.762794 | 2.611593 | 1.057896 |
ignored = self.config.get('ignored', [])
channels = ctx.message.server.channels
ignored.extend(c.id for c in channels if c.type == discord.ChannelType.text)
await self.config.put('ignored', list(set(ignored))) # make unique
await self.bot.responses.success(message='All ... | async def _all(self, ctx) | Ignores every channel in the server from being processed.
This works by adding every channel that the server currently has into
the ignore list. If more channels are added then they will have to be
ignored by using the ignore command.
To use this command you must have Manage Server per... | 5.353911 | 3.885978 | 1.377751 |
if len(channels) == 0:
channels = (ctx.message.channel,)
# a set is the proper data type for the ignore list
# however, JSON only supports arrays and objects not sets.
ignored = self.config.get('ignored', [])
result = []
for channel in channels:
... | async def unignore(self, ctx, *channels: discord.Channel) | Unignores channels from being processed.
If no channels are specified, it unignores the current channel.
To use this command you must have the Manage Channels permission or have the
Bot Admin role. | 4.101039 | 3.911184 | 1.048542 |
channels = [c for c in ctx.message.server.channels if c.type is discord.ChannelType.text]
await ctx.invoke(self.unignore, *channels) | async def unignore_all(self, ctx) | Unignores all channels in this server from being processed.
To use this command you must have the Manage Channels permission or have the
Bot Admin role. | 3.217945 | 3.106465 | 1.035887 |
spammers = Counter()
channel = ctx.message.channel
prefixes = self.bot.command_prefix
if callable(prefixes):
prefixes = prefixes(self.bot, ctx.message)
def is_possible_command_invoke(entry):
valid_call = any(entry.content.startswith(prefix) for ... | async def cleanup(self, ctx, search : int = 100) | Cleans up the bot's messages from the channel.
If a search number is specified, it searches that many messages to delete.
If the bot has Manage Messages permissions, then it will try to delete
messages that look like they invoked the bot as well.
After the cleanup is completed, the bot... | 2.413057 | 2.343045 | 1.029881 |
plonks = self.config.get('plonks', {})
guild_id = ctx.message.server.id
db = plonks.get(guild_id, [])
if member.id in db:
await self.bot.responses.failure(message='That user is already bot banned in this server.')
return
db.append(member.id)
... | async def plonk(self, ctx, *, member: discord.Member) | Bans a user from using the bot.
This bans a person from using the bot in the current server.
There is no concept of a global ban. This ban can be bypassed
by having the Manage Server permission.
To use this command you must have the Manage Server permission
or have a Bot Admin ... | 3.044888 | 2.669259 | 1.140724 |
plonks = self.config.get('plonks', {})
guild = ctx.message.server
db = plonks.get(guild.id, [])
members = '\n'.join(map(str, filter(None, map(guild.get_member, db))))
if members:
await self.bot.responses.basic(title="Plonked Users:", message=members)
... | async def plonks(self, ctx) | Shows members banned from the bot. | 4.764446 | 4.233939 | 1.125299 |
plonks = self.config.get('plonks', {})
guild_id = ctx.message.server.id
db = plonks.get(guild_id, [])
try:
db.remove(member.id)
except ValueError:
await self.bot.responses.failure(message='%s is not banned from using the bot in this server.' % m... | async def unplonk(self, ctx, *, member: discord.Member) | Unbans a user from using the bot.
To use this command you must have the Manage Server permission
or have a Bot Admin role. | 2.783753 | 2.511715 | 1.108308 |
perms = discord.Permissions.none()
perms.read_messages = True
perms.send_messages = True
perms.manage_messages = True
perms.embed_links = True
perms.read_message_history = True
perms.attach_files = True
perms.add_reactions = True
await sel... | async def join(self, ctx) | Sends you the bot invite link. | 1.92755 | 1.707323 | 1.12899 |
channel = ctx.message.channel
if member is None:
member = ctx.message.author
e = discord.Embed()
roles = [role.name.replace('@', '@\u200b') for role in member.roles]
shared = sum(1 for m in self.bot.get_all_members() if m.id == member.id)
voice = mem... | async def info(self, ctx, *, member : discord.Member = None) | Shows info about a member.
This cannot be used in private messages. If you don't specify
a member then the info returned will be yours. | 2.006749 | 1.940789 | 1.033986 |
cmd = r'git show -s -3 --format="%s (%cr)"'
if os.name == 'posix':
cmd = cmd.format(r'\`%h\`')
else:
cmd = cmd.format(r'`%h`')
embed = discord.Embed()
embed.colour = Colors.get_default(self.bot)
embed.add_field(name="About "+self.bot.us... | async def about(self) | Tells you information about the bot itself.
This is more information about the bot, not really
sure when this comes into play tbh, thats what I am
testing right now. | 2.532287 | 2.511781 | 1.008164 |
self._db[key] = value
await self.save() | async def put(self, key, value, *args) | Edits a data entry. | 7.851533 | 6.801732 | 1.154343 |
values = {}
title = "Description"
description = self.command.description + "\n\n" + self.get_ending_note() if not self.is_cog() else inspect.getdoc(self.command)
sections = []
if isinstance(self.command, Command):
description = self.command.short_doc
... | def format(self) | Handles the actual behaviour involved with formatting.
To change the behaviour, this method should be overridden.
Returns
--------
list
A paginated output of the help command. | 3.24291 | 3.067851 | 1.057062 |
if not reactor:
await self.bot.say("What should I react to?")
response = await self.bot.wait_for_message(author=ctx.message.author)
reactor = response.content
data = self.config.get(ctx.message.server.id, {})
keyword = data.get(reactor, {})
... | async def addreaction(self, ctx, *, reactor="") | Interactively adds a custom reaction | 2.663774 | 2.641476 | 1.008441 |
data = self.config.get(ctx.message.server.id, {})
if not data:
await self.bot.responses.failure(message="There are no reactions on this server.")
return
try:
pager = Pages(self.bot, message=ctx.message, entries=list(data.keys()))
pager.emb... | async def listreactions(self, ctx) | Lists all the reactions for the server | 3.054525 | 2.993184 | 1.020494 |
data = self.config.get(ctx.message.server.id, {})
keyword = data.get(reactor, {})
if not keyword:
await self.bot.responses.failure(message="Reaction '{}' was not found.".format(reactor))
return
response = data.get(reactor, {}).get("response", "")
... | async def viewreaction(self, ctx, *, reactor : str) | Views a specific reaction | 4.036238 | 4.010206 | 1.006491 |
data = self.config.get(ctx.message.server.id, {})
keyword = data.get(reactor, {})
if keyword:
data.pop(reactor)
await self.config.put(ctx.message.server.id, data)
await self.bot.responses.success(message="Reaction '{}' has been deleted.".format(reacto... | async def deletereaction(self, ctx, *, reactor : str) | Removes a reaction | 3.147857 | 3.0434 | 1.034322 |
data = self.config.get(ctx.message.server.id, {})
if data:
await self.config.put(ctx.message.server.id, {})
await self.bot.responses.success(message="All reactions have been deleted.")
else:
await self.bot.responses.failure(message="This server has no... | async def deleteallreactions(self, ctx) | Removes a reaction | 3.347838 | 3.442096 | 0.972616 |
bot = ctx.bot
destination = ctx.message.author if bot.pm_help else ctx.message.channel
def repl(obj):
return _mentions_transforms.get(obj.group(0), '')
# help by itself just lists our own commands.
if len(commands) == 0:
pages = bot.formatter.format_help_for(ctx, bot)
elif... | async def _default_help_command(ctx, *commands : str) | Shows this message. | 2.475543 | 2.42299 | 1.021689 |
return remaining.value >= nla.SIZEOF and nla.SIZEOF <= nla.nla_len <= remaining.value | def nla_ok(nla, remaining) | Check if the attribute header and payload can be accessed safely.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L148
Verifies that the header and payload do not exceed the number of bytes left in the attribute stream. This function
must be called before access the attribute header or payloa... | 11.833993 | 12.386853 | 0.955367 |
totlen = int(NLA_ALIGN(nla.nla_len))
remaining.value -= totlen
return nlattr(bytearray_ptr(nla.bytearray, totlen)) | def nla_next(nla, remaining) | Return next attribute in a stream of attributes.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L171
Calculates the offset to the next attribute based on the attribute given. The attribute provided is assumed to be
accessible, the caller is responsible to use nla_ok() beforehand. The offset ... | 17.785969 | 11.890035 | 1.495872 |
minlen = 0
type_ = nla_type(nla)
if type_ < 0 or type_ > maxtype:
return 0
pt = policy[type_]
if pt.type_ > NLA_TYPE_MAX:
raise BUG
if pt.minlen:
minlen = pt.minlen
elif pt.type_ != NLA_UNSPEC:
minlen = nla_attr_minlen[pt.type_]
if nla_len(nla) < m... | def validate_nla(nla, maxtype, policy) | https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L188.
Positional arguments:
nla -- nlattr class instance.
maxtype -- integer.
policy -- dictionary of nla_policy class instances as values, with nla types as keys.
Returns:
0 on success or a negative error code. | 3.200629 | 3.105338 | 1.030686 |
rem = c_int()
for nla in nla_for_each_attr(head, len_, rem):
type_ = nla_type(nla)
if type_ > maxtype:
continue
if policy:
err = validate_nla(nla, maxtype, policy)
if err < 0:
return err
if type_ in tb and tb[type_]:
... | def nla_parse(tb, maxtype, head, len_, policy) | Create attribute index based on a stream of attributes.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L242
Iterates over the stream of attributes and stores a pointer to each attribute in the index array using the attribute
type as index to the array. Attribute with a type greater than the ... | 5.452961 | 4.488904 | 1.214765 |
pos = head
rem.value = len_
while nla_ok(pos, rem):
yield pos
pos = nla_next(pos, rem) | def nla_for_each_attr(head, len_, rem) | Iterate over a stream of attributes.
https://github.com/thom311/libnl/blob/libnl3_2_25/include/netlink/attr.h#L262
Positional arguments:
head -- first nlattr with more in its bytearray payload (nlattr class instance).
len_ -- length of attribute stream (integer).
rem -- initialized to len, holds b... | 5.855495 | 6.493059 | 0.901808 |
pos = nlattr(nla_data(nla))
rem.value = nla_len(nla)
while nla_ok(pos, rem):
yield pos
pos = nla_next(pos, rem) | def nla_for_each_nested(nla, rem) | Iterate over a stream of nested attributes.
https://github.com/thom311/libnl/blob/libnl3_2_25/include/netlink/attr.h#L274
Positional arguments:
nla -- attribute containing the nested attributes (nlattr class instance).
rem -- initialized to len, holds bytes currently remaining in stream (c_int).
... | 7.042821 | 5.700624 | 1.235447 |
rem = c_int()
for nla in nla_for_each_attr(head, len_, rem):
if nla_type(nla) == attrtype:
return nla
return None | def nla_find(head, len_, attrtype) | Find a single attribute in a stream of attributes.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L323
Iterates over the stream of attributes and compares each type with the type specified. Returns the first attribute
which matches the type.
Positional arguments:
head -- first nlatt... | 4.61058 | 6.295387 | 0.732374 |
tlen = NLMSG_ALIGN(msg.nm_nlh.nlmsg_len) + nla_total_size(attrlen)
if tlen > msg.nm_size:
return None
nla = nlattr(nlmsg_tail(msg.nm_nlh))
nla.nla_type = attrtype
nla.nla_len = nla_attr_size(attrlen)
if attrlen:
padlen = nla_padlen(attrlen)
nla.bytearray[nla.nla_le... | def nla_reserve(msg, attrtype, attrlen) | Reserve space for an attribute.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L456
Reserves room for an attribute in the specified Netlink message and fills in the attribute header (type, length).
Returns None if there is insufficient space for the attribute.
Any padding between payloa... | 4.206089 | 3.92489 | 1.071645 |
nla = nla_reserve(msg, attrtype, datalen)
if not nla:
return -NLE_NOMEM
if datalen <= 0:
return 0
nla_data(nla)[:datalen] = data[:datalen]
_LOGGER.debug('msg 0x%x: attr <0x%x> %d: Wrote %d bytes at offset +%d', id(msg), id(nla), nla.nla_type, datalen,
nla.byte... | def nla_put(msg, attrtype, datalen, data) | Add a unspecific attribute to Netlink message.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L497
Reserves room for an unspecific attribute and copies the provided data into the message as payload of the attribute.
Returns an error if there is insufficient space for the attribute.
Posi... | 6.94008 | 7.431722 | 0.933845 |
return nla_put(msg, attrtype, len(data), data) | def nla_put_data(msg, attrtype, data) | Add abstract data as unspecific attribute to Netlink message.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L527
Equivalent to nla_put() except that the length of the payload is derived from the bytearray data object.
Positional arguments:
msg -- Netlink message (nl_msg class instance)... | 4.270813 | 6.21994 | 0.686633 |
data = bytearray(value if isinstance(value, c_uint8) else c_uint8(value))
return nla_put(msg, attrtype, SIZEOF_U8, data) | def nla_put_u8(msg, attrtype, value) | Add 8 bit integer attribute to Netlink message.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L563
Positional arguments:
msg -- Netlink message (nl_msg class instance).
attrtype -- attribute type (integer).
value -- numeric value to store as payload (int() or c_uint8()).
Return... | 4.39039 | 5.862415 | 0.748905 |
data = bytearray(value if isinstance(value, c_uint16) else c_uint16(value))
return nla_put(msg, attrtype, SIZEOF_U16, data) | def nla_put_u16(msg, attrtype, value) | Add 16 bit integer attribute to Netlink message.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L588
Positional arguments:
msg -- Netlink message (nl_msg class instance).
attrtype -- attribute type (integer).
value -- numeric value to store as payload (int() or c_uint16()).
Retu... | 4.08138 | 5.094932 | 0.801067 |
data = bytearray(value if isinstance(value, c_uint32) else c_uint32(value))
return nla_put(msg, attrtype, SIZEOF_U32, data) | def nla_put_u32(msg, attrtype, value) | Add 32 bit integer attribute to Netlink message.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L613
Positional arguments:
msg -- Netlink message (nl_msg class instance).
attrtype -- attribute type (integer).
value -- numeric value to store as payload (int() or c_uint32()).
Retu... | 4.190257 | 5.202519 | 0.805429 |
data = bytearray(value if isinstance(value, c_uint64) else c_uint64(value))
return nla_put(msg, attrtype, SIZEOF_U64, data) | def nla_put_u64(msg, attrtype, value) | Add 64 bit integer attribute to Netlink message.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L638
Positional arguments:
msg -- Netlink message (nl_msg class instance).
attrtype -- attribute type (integer).
value -- numeric value to store as payload (int() or c_uint64()).
Retu... | 4.107926 | 5.310149 | 0.773599 |
tmp = c_uint64(0)
if nla and nla_len(nla) >= sizeof(tmp):
tmp = c_uint64.from_buffer(nla_data(nla)[:SIZEOF_U64])
return int(tmp.value) | def nla_get_u64(nla) | Return value of 64 bit integer attribute as an int().
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L649
Positional arguments:
nla -- 64 bit integer attribute (nlattr class instance).
Returns:
Payload as an int(). | 4.139986 | 4.742591 | 0.872938 |
data = bytearray(value) + bytearray(b'\0')
return nla_put(msg, attrtype, len(data), data) | def nla_put_string(msg, attrtype, value) | Add string attribute to Netlink message.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L674
Positional arguments:
msg -- Netlink message (nl_msg class instance).
attrtype -- attribute type (integer).
value -- bytes() or bytearray() value (e.g. 'Test'.encode('ascii')).
Returns:
... | 4.169752 | 6.862127 | 0.607647 |
if isinstance(msecs, c_uint64):
pass
elif isinstance(msecs, c_ulong):
msecs = c_uint64(msecs.value)
else:
msecs = c_uint64(msecs)
return nla_put_u64(msg, attrtype, msecs) | def nla_put_msecs(msg, attrtype, msecs) | Add msecs Netlink attribute to Netlink message.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L737
Positional arguments:
msg -- Netlink message (nl_msg class instance).
attrtype -- attribute type (integer).
msecs -- number of msecs (int(), c_uint64(), or c_ulong()).
Returns:
... | 2.12466 | 2.068587 | 1.027107 |
_LOGGER.debug('msg 0x%x: attr <> %d: adding msg 0x%x as nested attribute', id(msg), attrtype, id(nested))
return nla_put(msg, attrtype, nlmsg_datalen(nested.nm_nlh), nlmsg_data(nested.nm_nlh)) | def nla_put_nested(msg, attrtype, nested) | Add nested attributes to Netlink message.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L772
Takes the attributes found in the `nested` message and appends them to the message `msg` nested in a container of
the type `attrtype`. The `nested` message may not have a family specific header.
... | 9.486402 | 9.39515 | 1.009713 |
return nla_parse(tb, maxtype, nlattr(nla_data(nla)), nla_len(nla), policy) | def nla_parse_nested(tb, maxtype, nla, policy) | Create attribute index based on nested attribute.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L885
Feeds the stream of attributes nested into the specified attribute to nla_parse().
Positional arguments:
tb -- dictionary to be filled (maxtype+1 elements).
maxtype -- maximum attri... | 6.277797 | 6.997797 | 0.89711 |
hdr = genlmsghdr(cmd=cmd, version=version)
return int(nl_send_simple(sk, family, flags, hdr, hdr.SIZEOF)) | def genl_send_simple(sk, family, cmd, version, flags) | Send a Generic Netlink message consisting only of a header.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/genl/genl.c#L84
This function is a shortcut for sending a Generic Netlink message without any message payload. The message will only
consist of the Netlink and Generic Netlink headers. The hea... | 11.200231 | 11.577147 | 0.967443 |
if not nlmsg_valid_hdr(nlh, GENL_HDRLEN):
return False
ghdr = genlmsghdr(nlmsg_data(nlh))
if genlmsg_len(ghdr) < NLMSG_ALIGN(hdrlen):
return False
return True | def genlmsg_valid_hdr(nlh, hdrlen) | Validate Generic Netlink message headers.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/genl/genl.c#L117
Verifies the integrity of the Netlink and Generic Netlink headers by enforcing the following requirements:
- Valid Netlink message header (`nlmsg_valid_hdr()`)
- Presence of a complete Gene... | 6.104708 | 7.186293 | 0.849493 |
if not genlmsg_valid_hdr(nlh, hdrlen):
return -NLE_MSG_TOOSHORT
ghdr = genlmsghdr(nlmsg_data(nlh))
return int(nla_parse(tb, maxtype, genlmsg_attrdata(ghdr, hdrlen), genlmsg_attrlen(ghdr, hdrlen), policy)) | def genlmsg_parse(nlh, hdrlen, tb, maxtype, policy) | Parse Generic Netlink message including attributes.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/genl/genl.c#L191
Verifies the validity of the Netlink and Generic Netlink headers using genlmsg_valid_hdr() and calls nla_parse() on
the message payload to parse eventual attributes.
Positional a... | 7.039422 | 6.039042 | 1.165652 |
nlh = nlmsghdr(bytearray_ptr(gnlh.bytearray, -NLMSG_HDRLEN, oob=True))
return nlh.nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN | def genlmsg_len(gnlh) | Return length of message payload including user header.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/genl/genl.c#L224
Positional arguments:
gnlh -- Generic Netlink message header (genlmsghdr class instance).
Returns:
Length of user payload including an eventual user header in number of b... | 15.783826 | 15.695815 | 1.005607 |
hdr = genlmsghdr(cmd=cmd, version=version)
nlh = nlmsg_put(msg, port, seq, family, GENL_HDRLEN + hdrlen, flags)
if nlh is None:
return None
nlmsg_data(nlh)[:hdr.SIZEOF] = hdr.bytearray[:hdr.SIZEOF]
_LOGGER.debug('msg 0x%x: Added generic netlink header cmd=%d version=%d', id(msg), cmd, v... | def genlmsg_put(msg, port, seq, family, hdrlen, flags, cmd, version) | Add Generic Netlink headers to Netlink message.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/genl/genl.c#L348
Calls nlmsg_put() on the specified message object to reserve space for the Netlink header, the Generic Netlink
header, and a user header of specified length. Fills out the header fields w... | 7.616632 | 6.748808 | 1.128589 |
cb.cb_active = type_
ret = cb.cb_set[type_](msg, cb.cb_args[type_])
cb.cb_active = 10 + 1 # NL_CB_TYPE_MAX + 1
return int(ret) | def nl_cb_call(cb, type_, msg) | Call a callback function.
https://github.com/thom311/libnl/blob/libnl3_2_25/include/netlink-private/netlink.h#L136
Positional arguments:
cb -- nl_cb class instance.
type_ -- callback type integer (e.g. NL_CB_MSG_OUT).
msg -- Netlink message (nl_msg class instance).
Returns:
Integer from t... | 7.375384 | 7.729898 | 0.954137 |
self.bytearray[self._get_slicers(0)] = bytearray(c_uint(value or 0)) | def nl_family(self, value) | Family setter. | 22.480488 | 20.662573 | 1.087981 |
self.bytearray[self._get_slicers(1)] = bytearray(c_ushort(value or 0)) | def nl_pad(self, value) | Pad setter. | 21.552818 | 18.743448 | 1.149885 |
self.bytearray[self._get_slicers(2)] = bytearray(c_uint32(value or 0)) | def nl_pid(self, value) | Port ID setter. | 17.49198 | 14.609464 | 1.197305 |
self.bytearray[self._get_slicers(3)] = bytearray(c_uint32(value or 0)) | def nl_groups(self, value) | Group setter. | 17.173502 | 15.990051 | 1.074012 |
self.bytearray[self._get_slicers(0)] = bytearray(c_uint32(value or 0)) | def nlmsg_len(self, value) | Length setter. | 16.876539 | 14.464539 | 1.166753 |
self.bytearray[self._get_slicers(1)] = bytearray(c_uint16(value or 0)) | def nlmsg_type(self, value) | Message content setter. | 18.284571 | 15.944566 | 1.146759 |
self.bytearray[self._get_slicers(2)] = bytearray(c_uint16(value or 0)) | def nlmsg_flags(self, value) | Message flags setter. | 16.633219 | 14.915102 | 1.115193 |
self.bytearray[self._get_slicers(3)] = bytearray(c_uint32(value or 0)) | def nlmsg_seq(self, value) | Sequence setter. | 17.227942 | 15.358953 | 1.121687 |
self.bytearray[self._get_slicers(4)] = bytearray(c_uint32(value or 0)) | def nlmsg_pid(self, value) | Port ID setter. | 17.777803 | 14.713087 | 1.208299 |
self.bytearray[self._get_slicers(0)] = bytearray(c_uint16(value or 0)) | def nla_len(self, value) | Length setter. | 16.874044 | 14.231656 | 1.18567 |
self.bytearray[self._get_slicers(1)] = bytearray(c_uint16(value or 0)) | def nla_type(self, value) | Type setter. | 17.995169 | 16.52301 | 1.089097 |
global default_cb
nlcb = os.environ.get('NLCB', '').lower()
if not nlcb:
return
if nlcb == 'default':
default_cb = NL_CB_DEFAULT
elif nlcb == 'verbose':
default_cb = NL_CB_VERBOSE
elif nlcb == 'debug':
default_cb = NL_CB_DEBUG
else:
_LOGGER.warni... | def init_default_cb() | https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L42. | 3.622775 | 3.450035 | 1.050069 |
global _PREVIOUS_LOCAL_PORT
if _PREVIOUS_LOCAL_PORT is None:
try:
with contextlib.closing(socket.socket(getattr(socket, 'AF_NETLINK', -1), socket.SOCK_RAW)) as s:
s.bind((0, 0))
_PREVIOUS_LOCAL_PORT = int(s.getsockname()[0])
except OSError:
... | def generate_local_port() | https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L63. | 2.881424 | 2.65197 | 1.086522 |
# Allocate the callback.
cb = cb or nl_cb_alloc(default_cb)
if not cb:
return None
# Allocate the socket.
sk = nl_sock()
sk.s_cb = cb
sk.s_local.nl_family = getattr(socket, 'AF_NETLINK', -1)
sk.s_peer.nl_family = getattr(socket, 'AF_NETLINK', -1)
sk.s_seq_expect = sk.s_... | def nl_socket_alloc(cb=None) | Allocate new Netlink socket. Does not yet actually open a socket.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L206
Also has code for generating local port once.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/nl.c#L123
Keyword arguments:
cb -- custom callback handler.
... | 6.50662 | 6.108618 | 1.065154 |
if not sk.s_local.nl_pid:
port = generate_local_port()
sk.s_flags &= ~NL_OWN_PORT
sk.s_local.nl_pid = port
return port
return sk.s_local.nl_pid | def nl_socket_get_local_port(sk) | https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L357.
Also https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L338 | 5.294582 | 6.197626 | 0.854292 |
if sk.s_fd == -1:
return -NLE_BAD_SOCK
for grp in group:
if not grp:
break
if grp < 0:
return -NLE_INVAL
try:
sk.socket_instance.setsockopt(SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, grp)
except OSError as exc:
return -nl_sys... | def nl_socket_add_memberships(sk, *group) | Join groups.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L417
Joins the specified groups using the modern socket option. The list of groups has to be terminated by 0.
Make sure to use the correct group definitions as the older bitmask definitions for nl_join_groups() are likely to
... | 5.360959 | 5.758457 | 0.930971 |
if sk.s_fd == -1:
return -NLE_BAD_SOCK
for grp in group:
if not grp:
break
if grp < 0:
return -NLE_INVAL
try:
sk.socket_instance.setsockopt(SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, grp)
except OSError as exc:
return -nl_sy... | def nl_socket_drop_memberships(sk, *group) | Leave groups.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L465
Leaves the specified groups using the modern socket option. The list of groups has to terminated by 0.
Positional arguments:
sk -- Netlink socket (nl_sock class instance).
group -- group identifier (integer).
R... | 5.151489 | 5.68005 | 0.906944 |
return int(nl_cb_set(sk.s_cb, type_, kind, func, arg)) | def nl_socket_modify_cb(sk, type_, kind, func, arg) | Modify the callback handler associated with the socket.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L633
Sets specific callback functions in the existing nl_cb class instance stored in the nl_sock socket.
Positional arguments:
sk -- Netlink socket (nl_sock class instance).
type... | 9.71344 | 10.562468 | 0.919618 |
return int(nl_cb_err(sk.s_cb, kind, func, arg)) | def nl_socket_modify_err_cb(sk, kind, func, arg) | Modify the error callback handler associated with the socket.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L649
Positional arguments:
sk -- Netlink socket (nl_sock class instance).
kind -- kind of callback (integer).
func -- callback function.
arg -- argument to be passed to ... | 11.302423 | 14.760337 | 0.765729 |
rxbuf = 32768 if rxbuf <= 0 else rxbuf
txbuf = 32768 if txbuf <= 0 else txbuf
if sk.s_fd == -1:
return -NLE_BAD_SOCK
try:
sk.socket_instance.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, txbuf)
except OSError as exc:
return -nl_syserr2nlerr(exc.errno)
try:
... | def nl_socket_set_buffer_size(sk, rxbuf, txbuf) | Set socket buffer size of Netlink socket.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L675
Sets the socket buffer size of a Netlink socket to the specified values `rxbuf` and `txbuf`. Providing a value of 0
assumes a good default value.
Positional arguments:
sk -- Netlink socke... | 2.600249 | 2.910477 | 0.89341 |
self.bytearray[self._get_slicers(0)] = bytearray(c_uint8(value or 0)) | def cmd(self, value) | Command setter. | 17.891857 | 16.974731 | 1.054029 |
self.bytearray[self._get_slicers(1)] = bytearray(c_uint8(value or 0)) | def version(self, value) | Version setter. | 19.404846 | 17.437395 | 1.112829 |
self.bytearray[self._get_slicers(2)] = bytearray(c_uint16(value or 0)) | def reserved(self, value) | Reserved setter. | 16.318306 | 14.861866 | 1.097998 |
converted = list()
for i in range(len(data)):
try:
c = unichr(data[i])
except NameError:
c = chr(data[i])
if unicodedata.category(c) != 'Cc' and c not in (' ', '\\'):
converted.append(c)
elif c == '\0':
converted.append(c)
... | def get_ssid(_, data) | http://git.kernel.org/cgit/linux/kernel/git/jberg/iw.git/tree/util.c?id=v3.17#n313.
Positional arguments:
data -- bytearray data to read.
Returns:
String. | 3.031314 | 2.861075 | 1.059502 |
answers = list()
for mcs_bit in range(77):
mcs_octet = int(mcs_bit / 8)
mcs_rate_bit = 1 << mcs_bit % 8
mcs_rate_idx_set = not not (mcs[mcs_octet] & mcs_rate_bit)
if not mcs_rate_idx_set:
continue
answers.append(mcs_bit)
return answers | def get_mcs_index(mcs) | http://git.kernel.org/cgit/linux/kernel/git/jberg/iw.git/tree/util.c?id=v3.17#n453.
Positional arguments:
mcs -- bytearray
Returns:
List. | 4.123798 | 3.905402 | 1.055921 |
answers = list()
if cap & 1:
answers.append('RX LDPC')
if cap & 2:
answers.append('HT20/HT40')
if not cap & 2:
answers.append('HT20')
if (cap >> 2) & 0x3 == 0:
answers.append('Static SM Power Save')
if (cap >> 2) & 0x3 == 1:
answers.append('Dynamic SM... | def get_ht_capability(cap) | http://git.kernel.org/cgit/linux/kernel/git/jberg/iw.git/tree/util.c?id=v3.17#n541.
Positional arguments:
cap -- c_uint16
Returns:
List. | 2.556895 | 2.541126 | 1.006206 |
answers = dict()
max_rx_supp_data_rate = (mcs[10] & ((mcs[11] & 0x3) << 8))
tx_mcs_set_defined = not not (mcs[12] & (1 << 0))
tx_mcs_set_equal = not (mcs[12] & (1 << 1))
tx_max_num_spatial_streams = ((mcs[12] >> 2) & 3) + 1
tx_unequal_modulation = not not (mcs[12] & (1 << 4))
if max_rx... | def get_ht_mcs(mcs) | http://git.kernel.org/cgit/linux/kernel/git/jberg/iw.git/tree/util.c?id=v3.17#n591.
Positional arguments:
mcs -- bytearray.
Returns:
Dict. | 3.030461 | 3.151841 | 0.961489 |
short_key = key[12:].lower()
key_integer = getattr(nl80211, key)
if in_bss.get(key_integer) is None:
return dict()
data = parser_func(in_bss[key_integer])
if parser_func == libnl.attr.nla_data:
data = data[:libnl.attr.nla_len(in_bss[key_integer])]
out_parsed[short_key] = dat... | def _get(out_parsed, in_bss, key, parser_func) | Handle calling the parser function to convert bytearray data into Python data types.
Positional arguments:
out_parsed -- dictionary to update with parsed data and string keys.
in_bss -- dictionary of integer keys and bytearray values.
key -- key string to lookup (must be a variable name in libnl.nl8021... | 4.646796 | 4.279933 | 1.085717 |
for ie in ('information_elements', 'beacon_ies'):
target = in_parsed.get(ie, {})
for key in keys:
target = target.get(key, {})
if target:
return target
return None | def _fetch(in_parsed, *keys) | Retrieve nested dict data from either information elements or beacon IES dicts.
Positional arguments:
in_parsed -- dictionary to read from.
keys -- one or more nested dict keys to lookup.
Returns:
Found value or None. | 5.948673 | 4.040114 | 1.472402 |
answer = 'type={0} length={1} flags=<{2}> sequence-nr={3} pid={4}'.format(
nl_nlmsgtype2str(nlh.nlmsg_type, bytearray(), 32).decode('ascii'),
nlh.nlmsg_len,
nl_nlmsg_flags2str(nlh.nlmsg_flags, bytearray(), 128).decode('ascii'),
nlh.nlmsg_seq,
nlh.nlmsg_pid,
)
ret... | def print_header_content(nlh) | Return header content (doesn't actually print like the C library does).
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/handlers.c#L34
Positional arguments:
nlh -- nlmsghdr class instance. | 4.682606 | 4.319233 | 1.084129 |
ofd = arg or _LOGGER.debug
ofd('-- Error received: ' + strerror(-err.error))
ofd('-- Original message: ' + print_header_content(err.msg))
return -nl_syserr2nlerr(err.error) | def nl_error_handler_verbose(_, err, arg) | https://github.com/thom311/libnl/blob/libnl3_2_25/lib/handlers.c#L78. | 22.705664 | 19.099392 | 1.188816 |
ofd = arg or _LOGGER.debug
ofd('-- Debug: Unhandled Valid message: ' + print_header_content(nlmsg_hdr(msg)))
return NL_OK | def nl_valid_handler_debug(msg, arg) | https://github.com/thom311/libnl/blob/libnl3_2_25/lib/handlers.c#L92. | 39.68557 | 39.204529 | 1.01227 |
ofd = arg or _LOGGER.debug
ofd('-- Debug: End of multipart message block: ' + print_header_content(nlmsg_hdr(msg)))
return NL_STOP | def nl_finish_handler_debug(msg, arg) | https://github.com/thom311/libnl/blob/libnl3_2_25/lib/handlers.c#L103. | 41.908829 | 39.103989 | 1.071728 |
ofd = arg or _LOGGER.debug
ofd('-- Debug: Received Message:')
nl_msg_dump(msg, ofd)
return NL_OK | def nl_msg_in_handler_debug(msg, arg) | https://github.com/thom311/libnl/blob/libnl3_2_25/lib/handlers.c#L114. | 17.832726 | 17.332649 | 1.028852 |
ofd = arg or _LOGGER.debug
ofd('-- Debug: Sent Message:')
nl_msg_dump(msg, ofd)
return NL_OK | def nl_msg_out_handler_debug(msg, arg) | https://github.com/thom311/libnl/blob/libnl3_2_25/lib/handlers.c#L124. | 20.030575 | 20.210682 | 0.991089 |
ofd = arg or _LOGGER.debug
ofd('-- Debug: Skipped message: ' + print_header_content(nlmsg_hdr(msg)))
return NL_SKIP | def nl_skipped_handler_debug(msg, arg) | https://github.com/thom311/libnl/blob/libnl3_2_25/lib/handlers.c#L134. | 30.474073 | 29.838753 | 1.021292 |
if kind < 0 or kind > NL_CB_KIND_MAX:
return None
cb = nl_cb()
cb.cb_active = NL_CB_TYPE_MAX + 1
for i in range(NL_CB_TYPE_MAX):
nl_cb_set(cb, i, kind, None, None)
nl_cb_err(cb, kind, None, None)
return cb | def nl_cb_alloc(kind) | Allocate a new callback handle.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/handlers.c#L201
Positional arguments:
kind -- callback kind to be used for initialization.
Returns:
Newly allocated callback handle (nl_cb class instance) or None. | 4.203916 | 4.695118 | 0.89538 |
if type_ < 0 or type_ > NL_CB_TYPE_MAX or kind < 0 or kind > NL_CB_KIND_MAX:
return -NLE_RANGE
if kind == NL_CB_CUSTOM:
cb.cb_set[type_] = func
cb.cb_args[type_] = arg
else:
cb.cb_set[type_] = cb_def[type_][kind]
cb.cb_args[type_] = arg
return 0 | def nl_cb_set(cb, type_, kind, func, arg) | Set up a callback. Updates `cb` in place.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/handlers.c#L293
Positional arguments:
cb -- nl_cb class instance.
type_ -- callback to modify (integer).
kind -- kind of implementation (integer).
func -- callback function (NL_CB_CUSTOM).
arg -... | 2.939834 | 2.98158 | 0.985999 |
if kind < 0 or kind > NL_CB_KIND_MAX:
return -NLE_RANGE
if kind == NL_CB_CUSTOM:
cb.cb_err = func
cb.cb_err_arg = arg
else:
cb.cb_err = cb_err_def[kind]
cb.cb_err_arg = arg
return 0 | def nl_cb_err(cb, kind, func, arg) | Set up an error callback. Updates `cb` in place.
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/handlers.c#L343
Positional arguments:
cb -- nl_cb class instance.
kind -- kind of callback (integer).
func -- callback function.
arg -- argument to be passed to callback function.
Return... | 3.49235 | 3.921288 | 0.890613 |
table = AsciiTable([['Data Type', 'Data Value']])
# First convert `msg` into something more manageable.
gnlh = genlmsghdr(nlmsg_data(nlmsg_hdr(msg)))
# Partially parse the raw binary data and place them in the `tb` dictionary.
tb = dict((i, None) for i in range(nl80211.NL80211_ATTR_MAX + 1)) ... | def callback(msg, has_printed) | Callback function called by libnl upon receiving messages from the kernel.
Positional arguments:
msg -- nl_msg class instance containing the data sent by the kernel.
has_printed -- simple pseudo boolean (if list is empty) to keep track of when to print emtpy lines.
Returns:
An integer, value of NL... | 3.162614 | 3.018167 | 1.047859 |
# First get the wireless interface index.
if OPTIONS['<interface>']:
pack = struct.pack('16sI', OPTIONS['<interface>'].encode('ascii'), 0)
sk = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
info = struct.unpack('16sI', fcntl.ioctl(sk.fileno(), 0x8933, pack))
... | def main() | Main function called upon script execution. | 3.581474 | 3.564935 | 1.004639 |
fmt = 'DBG<0>%(pathname)s:%(lineno)d %(funcName)s: %(message)s'
handler_stderr = logging.StreamHandler(sys.stderr)
handler_stderr.setFormatter(logging.Formatter(fmt))
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
root_logger.addHandler(handler_stderr) | def setup_logging() | Called when __name__ == '__main__' below. Sets up logging library.
All logging messages go to stderr, from DEBUG to CRITICAL. This script uses print() for regular messages. | 2.88236 | 2.701551 | 1.066928 |
self.bytearray[self._get_slicers(0)] = bytearray(c_ushort(value or 0)) | def rta_len(self, value) | Length setter. | 21.037998 | 18.204746 | 1.155633 |
self.bytearray[self._get_slicers(1)] = bytearray(c_ushort(value or 0)) | def rta_type(self, value) | Type setter. | 23.684626 | 21.918045 | 1.080599 |
self.bytearray[self._get_slicers(0)] = bytearray(c_ubyte(value or 0)) | def rtgen_family(self, value) | Family setter. | 22.246979 | 20.950428 | 1.061887 |
self.bytearray[self._get_slicers(0)] = bytearray(c_ubyte(value or 0)) | def ifi_family(self, value) | Family setter. | 18.718548 | 18.085398 | 1.035009 |
self.bytearray[self._get_slicers(2)] = bytearray(c_ushort(value or 0)) | def ifi_type(self, value) | Type setter. | 20.606344 | 20.483536 | 1.005995 |
self.bytearray[self._get_slicers(3)] = bytearray(c_int(value or 0)) | def ifi_index(self, value) | Index setter. | 18.812574 | 16.556541 | 1.136262 |
self.bytearray[self._get_slicers(4)] = bytearray(c_uint(value or 0)) | def ifi_flags(self, value) | Message flags setter. | 19.528175 | 17.778545 | 1.098412 |
self.bytearray[self._get_slicers(5)] = bytearray(c_uint(value or 0)) | def ifi_change(self, value) | Change setter. | 21.46825 | 20.867611 | 1.028783 |
class ClsPyPy(base):
def __repr__(self):
return repr(base(super(ClsPyPy, self).value))
@classmethod
def from_buffer(cls, ba):
try:
integer = struct.unpack_from(getattr(cls, '_type_'), ba)[0]
except struct.error:
len_ =... | def _class_factory(base) | Create subclasses of ctypes.
Positional arguments:
base -- base class to subclass.
Returns:
New class definition. | 3.735168 | 3.703069 | 1.008668 |
r
ba = bytearray()
for c in stream:
if not c:
break
ba.append(c)
return bytes(ba) | def get_string(stream) | r"""Use this to grab a "string" from a bytearray() stream.
C's printf() prints until it encounters a null byte (b'\0'). This function behaves the same.
Positional arguments:
stream -- bytearray stream of data.
Returns:
bytes() instance of any characters from the start of the stream until before t... | 5.754839 | 5.826347 | 0.987727 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.