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 list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
square/pylink | pylink/__main__.py | main | def main(args=None):
"""Main command-line interface entrypoint.
Runs the given subcommand or argument that were specified. If not given a
``args`` parameter, assumes the arguments are passed on the command-line.
Args:
args (list): list of command-line arguments
Returns:
Zero on succe... | python | def main(args=None):
"""Main command-line interface entrypoint.
Runs the given subcommand or argument that were specified. If not given a
``args`` parameter, assumes the arguments are passed on the command-line.
Args:
args (list): list of command-line arguments
Returns:
Zero on succe... | [
"def",
"main",
"(",
"args",
"=",
"None",
")",
":",
"if",
"args",
"is",
"None",
":",
"args",
"=",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
"parser",
"=",
"create_parser",
"(",
")",
"args",
"=",
"parser",
".",
"parse_args",
"(",
"args",
")",
"if",
... | Main command-line interface entrypoint.
Runs the given subcommand or argument that were specified. If not given a
``args`` parameter, assumes the arguments are passed on the command-line.
Args:
args (list): list of command-line arguments
Returns:
Zero on success, non-zero otherwise. | [
"Main",
"command",
"-",
"line",
"interface",
"entrypoint",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L570-L603 | train |
square/pylink | pylink/__main__.py | Command.create_jlink | def create_jlink(self, args):
"""Creates an instance of a J-Link from the given arguments.
Args:
self (Command): the ``Command`` instance
args (Namespace): arguments to construct the ``JLink`` instance from
Returns:
An instance of a ``JLink``.
"""
... | python | def create_jlink(self, args):
"""Creates an instance of a J-Link from the given arguments.
Args:
self (Command): the ``Command`` instance
args (Namespace): arguments to construct the ``JLink`` instance from
Returns:
An instance of a ``JLink``.
"""
... | [
"def",
"create_jlink",
"(",
"self",
",",
"args",
")",
":",
"jlink",
"=",
"pylink",
".",
"JLink",
"(",
")",
"jlink",
".",
"open",
"(",
"args",
".",
"serial_no",
",",
"args",
".",
"ip_addr",
")",
"if",
"hasattr",
"(",
"args",
",",
"'tif'",
")",
"and"... | Creates an instance of a J-Link from the given arguments.
Args:
self (Command): the ``Command`` instance
args (Namespace): arguments to construct the ``JLink`` instance from
Returns:
An instance of a ``JLink``. | [
"Creates",
"an",
"instance",
"of",
"a",
"J",
"-",
"Link",
"from",
"the",
"given",
"arguments",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L66-L88 | train |
square/pylink | pylink/__main__.py | Command.add_common_arguments | def add_common_arguments(self, parser, has_device=False):
"""Adds common arguments to the given parser.
Common arguments for a J-Link command are the target interface, and
J-Link serial number or IP address.
Args:
self (Command): the ``Command`` instance
parser (arg... | python | def add_common_arguments(self, parser, has_device=False):
"""Adds common arguments to the given parser.
Common arguments for a J-Link command are the target interface, and
J-Link serial number or IP address.
Args:
self (Command): the ``Command`` instance
parser (arg... | [
"def",
"add_common_arguments",
"(",
"self",
",",
"parser",
",",
"has_device",
"=",
"False",
")",
":",
"if",
"has_device",
":",
"parser",
".",
"add_argument",
"(",
"'-t'",
",",
"'--tif'",
",",
"required",
"=",
"True",
",",
"type",
"=",
"str",
".",
"lower"... | Adds common arguments to the given parser.
Common arguments for a J-Link command are the target interface, and
J-Link serial number or IP address.
Args:
self (Command): the ``Command`` instance
parser (argparse.ArgumentParser): the parser to add the arguments to
h... | [
"Adds",
"common",
"arguments",
"to",
"the",
"given",
"parser",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L90-L117 | train |
square/pylink | pylink/__main__.py | EraseCommand.run | def run(self, args):
"""Erases the device connected to the J-Link.
Args:
self (EraseCommand): the ``EraseCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None``
"""
jlink = self.create_jlink(args)
era... | python | def run(self, args):
"""Erases the device connected to the J-Link.
Args:
self (EraseCommand): the ``EraseCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None``
"""
jlink = self.create_jlink(args)
era... | [
"def",
"run",
"(",
"self",
",",
"args",
")",
":",
"jlink",
"=",
"self",
".",
"create_jlink",
"(",
"args",
")",
"erased",
"=",
"jlink",
".",
"erase",
"(",
")",
"print",
"(",
"'Bytes Erased: %d'",
"%",
"erased",
")"
] | Erases the device connected to the J-Link.
Args:
self (EraseCommand): the ``EraseCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None`` | [
"Erases",
"the",
"device",
"connected",
"to",
"the",
"J",
"-",
"Link",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L172-L184 | train |
square/pylink | pylink/__main__.py | FlashCommand.run | def run(self, args):
"""Flashes the device connected to the J-Link.
Args:
self (FlashCommand): the ``FlashCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None``
"""
kwargs = {}
kwargs['path'] = args.... | python | def run(self, args):
"""Flashes the device connected to the J-Link.
Args:
self (FlashCommand): the ``FlashCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None``
"""
kwargs = {}
kwargs['path'] = args.... | [
"def",
"run",
"(",
"self",
",",
"args",
")",
":",
"kwargs",
"=",
"{",
"}",
"kwargs",
"[",
"'path'",
"]",
"=",
"args",
".",
"file",
"[",
"0",
"]",
"kwargs",
"[",
"'addr'",
"]",
"=",
"args",
".",
"addr",
"kwargs",
"[",
"'on_progress'",
"]",
"=",
... | Flashes the device connected to the J-Link.
Args:
self (FlashCommand): the ``FlashCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None`` | [
"Flashes",
"the",
"device",
"connected",
"to",
"the",
"J",
"-",
"Link",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L208-L225 | train |
square/pylink | pylink/__main__.py | UnlockCommand.add_arguments | def add_arguments(self, parser):
"""Adds the unlock command arguments to the parser.
Args:
self (UnlockCommand): the ``UnlockCommand`` instance
parser (argparse.ArgumentParser): the parser to add the arguments to
Returns:
``None``
"""
parser.add_ar... | python | def add_arguments(self, parser):
"""Adds the unlock command arguments to the parser.
Args:
self (UnlockCommand): the ``UnlockCommand`` instance
parser (argparse.ArgumentParser): the parser to add the arguments to
Returns:
``None``
"""
parser.add_ar... | [
"def",
"add_arguments",
"(",
"self",
",",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'name'",
",",
"nargs",
"=",
"1",
",",
"choices",
"=",
"[",
"'kinetis'",
"]",
",",
"help",
"=",
"'name of MCU to unlock'",
")",
"return",
"self",
".",
"add_... | Adds the unlock command arguments to the parser.
Args:
self (UnlockCommand): the ``UnlockCommand`` instance
parser (argparse.ArgumentParser): the parser to add the arguments to
Returns:
``None`` | [
"Adds",
"the",
"unlock",
"command",
"arguments",
"to",
"the",
"parser",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L237-L249 | train |
square/pylink | pylink/__main__.py | UnlockCommand.run | def run(self, args):
"""Unlocks the target device.
Args:
self (UnlockCommand): the ``UnlockCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None``
"""
jlink = self.create_jlink(args)
mcu = args.name[0... | python | def run(self, args):
"""Unlocks the target device.
Args:
self (UnlockCommand): the ``UnlockCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None``
"""
jlink = self.create_jlink(args)
mcu = args.name[0... | [
"def",
"run",
"(",
"self",
",",
"args",
")",
":",
"jlink",
"=",
"self",
".",
"create_jlink",
"(",
"args",
")",
"mcu",
"=",
"args",
".",
"name",
"[",
"0",
"]",
".",
"lower",
"(",
")",
"if",
"pylink",
".",
"unlock",
"(",
"jlink",
",",
"mcu",
")",... | Unlocks the target device.
Args:
self (UnlockCommand): the ``UnlockCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None`` | [
"Unlocks",
"the",
"target",
"device",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L251-L266 | train |
square/pylink | pylink/__main__.py | LicenseCommand.run | def run(self, args):
"""Runs the license command.
Args:
self (LicenseCommand): the ``LicenseCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None``
"""
jlink = self.create_jlink(args)
if args.list:
... | python | def run(self, args):
"""Runs the license command.
Args:
self (LicenseCommand): the ``LicenseCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None``
"""
jlink = self.create_jlink(args)
if args.list:
... | [
"def",
"run",
"(",
"self",
",",
"args",
")",
":",
"jlink",
"=",
"self",
".",
"create_jlink",
"(",
"args",
")",
"if",
"args",
".",
"list",
":",
"print",
"(",
"'Built-in Licenses: %s'",
"%",
"', '",
".",
"join",
"(",
"jlink",
".",
"licenses",
".",
"spl... | Runs the license command.
Args:
self (LicenseCommand): the ``LicenseCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None`` | [
"Runs",
"the",
"license",
"command",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L294-L317 | train |
square/pylink | pylink/__main__.py | InfoCommand.add_arguments | def add_arguments(self, parser):
"""Adds the information commands to the parser.
Args:
self (InfoCommand): the ``InfoCommand`` instance
parser (argparse.ArgumentParser): the parser to add the arguments to
Returns:
``None``
"""
parser.add_argument('... | python | def add_arguments(self, parser):
"""Adds the information commands to the parser.
Args:
self (InfoCommand): the ``InfoCommand`` instance
parser (argparse.ArgumentParser): the parser to add the arguments to
Returns:
``None``
"""
parser.add_argument('... | [
"def",
"add_arguments",
"(",
"self",
",",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'-p'",
",",
"'--product'",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"'print the production information'",
")",
"parser",
".",
"add_argument",
"(",
"... | Adds the information commands to the parser.
Args:
self (InfoCommand): the ``InfoCommand`` instance
parser (argparse.ArgumentParser): the parser to add the arguments to
Returns:
``None`` | [
"Adds",
"the",
"information",
"commands",
"to",
"the",
"parser",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L326-L340 | train |
square/pylink | pylink/__main__.py | InfoCommand.run | def run(self, args):
"""Runs the information command.
Args:
self (InfoCommand): the ``InfoCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None``
"""
jlink = self.create_jlink(args)
if args.product:
... | python | def run(self, args):
"""Runs the information command.
Args:
self (InfoCommand): the ``InfoCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None``
"""
jlink = self.create_jlink(args)
if args.product:
... | [
"def",
"run",
"(",
"self",
",",
"args",
")",
":",
"jlink",
"=",
"self",
".",
"create_jlink",
"(",
"args",
")",
"if",
"args",
".",
"product",
":",
"print",
"(",
"'Product: %s'",
"%",
"jlink",
".",
"product_name",
")",
"manufacturer",
"=",
"'SEGGER'",
"i... | Runs the information command.
Args:
self (InfoCommand): the ``InfoCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None`` | [
"Runs",
"the",
"information",
"command",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L342-L370 | train |
square/pylink | pylink/__main__.py | EmulatorCommand.add_arguments | def add_arguments(self, parser):
"""Adds the arguments for the emulator command.
Args:
self (EmulatorCommand): the ``EmulatorCommand`` instance
parser (argparse.ArgumentParser): parser to add the commands to
Returns:
``None``
"""
group = parser.add... | python | def add_arguments(self, parser):
"""Adds the arguments for the emulator command.
Args:
self (EmulatorCommand): the ``EmulatorCommand`` instance
parser (argparse.ArgumentParser): parser to add the commands to
Returns:
``None``
"""
group = parser.add... | [
"def",
"add_arguments",
"(",
"self",
",",
"parser",
")",
":",
"group",
"=",
"parser",
".",
"add_mutually_exclusive_group",
"(",
"required",
"=",
"True",
")",
"group",
".",
"add_argument",
"(",
"'-l'",
",",
"'--list'",
",",
"nargs",
"=",
"'?'",
",",
"type",... | Adds the arguments for the emulator command.
Args:
self (EmulatorCommand): the ``EmulatorCommand`` instance
parser (argparse.ArgumentParser): parser to add the commands to
Returns:
``None`` | [
"Adds",
"the",
"arguments",
"for",
"the",
"emulator",
"command",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L379-L398 | train |
square/pylink | pylink/__main__.py | EmulatorCommand.run | def run(self, args):
"""Runs the emulator command.
Args:
self (EmulatorCommand): the ``EmulatorCommand`` instance
args (Namespace): arguments to parse
Returns:
``None``
"""
jlink = pylink.JLink()
if args.test:
if jlink.test():
... | python | def run(self, args):
"""Runs the emulator command.
Args:
self (EmulatorCommand): the ``EmulatorCommand`` instance
args (Namespace): arguments to parse
Returns:
``None``
"""
jlink = pylink.JLink()
if args.test:
if jlink.test():
... | [
"def",
"run",
"(",
"self",
",",
"args",
")",
":",
"jlink",
"=",
"pylink",
".",
"JLink",
"(",
")",
"if",
"args",
".",
"test",
":",
"if",
"jlink",
".",
"test",
"(",
")",
":",
"print",
"(",
"'Self-test succeeded.'",
")",
"else",
":",
"print",
"(",
"... | Runs the emulator command.
Args:
self (EmulatorCommand): the ``EmulatorCommand`` instance
args (Namespace): arguments to parse
Returns:
``None`` | [
"Runs",
"the",
"emulator",
"command",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L400-L458 | train |
square/pylink | pylink/__main__.py | FirmwareCommand.add_arguments | def add_arguments(self, parser):
"""Adds the arguments for the firmware command.
Args:
self (FirmwareCommand): the ``FirmwareCommand`` instance
parser (argparse.ArgumentParser): parser to add the commands to
Returns:
``None``
"""
group = parser.add... | python | def add_arguments(self, parser):
"""Adds the arguments for the firmware command.
Args:
self (FirmwareCommand): the ``FirmwareCommand`` instance
parser (argparse.ArgumentParser): parser to add the commands to
Returns:
``None``
"""
group = parser.add... | [
"def",
"add_arguments",
"(",
"self",
",",
"parser",
")",
":",
"group",
"=",
"parser",
".",
"add_mutually_exclusive_group",
"(",
"required",
"=",
"True",
")",
"group",
".",
"add_argument",
"(",
"'-d'",
",",
"'--downgrade'",
",",
"action",
"=",
"'store_true'",
... | Adds the arguments for the firmware command.
Args:
self (FirmwareCommand): the ``FirmwareCommand`` instance
parser (argparse.ArgumentParser): parser to add the commands to
Returns:
``None`` | [
"Adds",
"the",
"arguments",
"for",
"the",
"firmware",
"command",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L467-L482 | train |
square/pylink | pylink/__main__.py | FirmwareCommand.run | def run(self, args):
"""Runs the firmware command.
Args:
self (FirmwareCommand): the ``FirmwareCommand`` instance
args (Namespace): arguments to parse
Returns:
``None``
"""
jlink = self.create_jlink(args)
if args.downgrade:
if n... | python | def run(self, args):
"""Runs the firmware command.
Args:
self (FirmwareCommand): the ``FirmwareCommand`` instance
args (Namespace): arguments to parse
Returns:
``None``
"""
jlink = self.create_jlink(args)
if args.downgrade:
if n... | [
"def",
"run",
"(",
"self",
",",
"args",
")",
":",
"jlink",
"=",
"self",
".",
"create_jlink",
"(",
"args",
")",
"if",
"args",
".",
"downgrade",
":",
"if",
"not",
"jlink",
".",
"firmware_newer",
"(",
")",
":",
"print",
"(",
"'DLL firmware is not older than... | Runs the firmware command.
Args:
self (FirmwareCommand): the ``FirmwareCommand`` instance
args (Namespace): arguments to parse
Returns:
``None`` | [
"Runs",
"the",
"firmware",
"command",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/__main__.py#L484-L523 | train |
square/pylink | pylink/structs.py | JLinkDeviceInfo.name | def name(self):
"""Returns the name of the device.
Args:
self (JLinkDeviceInfo): the ``JLinkDeviceInfo`` instance
Returns:
Device name.
"""
return ctypes.cast(self.sName, ctypes.c_char_p).value.decode() | python | def name(self):
"""Returns the name of the device.
Args:
self (JLinkDeviceInfo): the ``JLinkDeviceInfo`` instance
Returns:
Device name.
"""
return ctypes.cast(self.sName, ctypes.c_char_p).value.decode() | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"ctypes",
".",
"cast",
"(",
"self",
".",
"sName",
",",
"ctypes",
".",
"c_char_p",
")",
".",
"value",
".",
"decode",
"(",
")"
] | Returns the name of the device.
Args:
self (JLinkDeviceInfo): the ``JLinkDeviceInfo`` instance
Returns:
Device name. | [
"Returns",
"the",
"name",
"of",
"the",
"device",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/structs.py#L207-L216 | train |
square/pylink | pylink/structs.py | JLinkDeviceInfo.manufacturer | def manufacturer(self):
"""Returns the name of the manufacturer of the device.
Args:
self (JLinkDeviceInfo): the ``JLinkDeviceInfo`` instance
Returns:
Manufacturer name.
"""
buf = ctypes.cast(self.sManu, ctypes.c_char_p).value
return buf.decode() if ... | python | def manufacturer(self):
"""Returns the name of the manufacturer of the device.
Args:
self (JLinkDeviceInfo): the ``JLinkDeviceInfo`` instance
Returns:
Manufacturer name.
"""
buf = ctypes.cast(self.sManu, ctypes.c_char_p).value
return buf.decode() if ... | [
"def",
"manufacturer",
"(",
"self",
")",
":",
"buf",
"=",
"ctypes",
".",
"cast",
"(",
"self",
".",
"sManu",
",",
"ctypes",
".",
"c_char_p",
")",
".",
"value",
"return",
"buf",
".",
"decode",
"(",
")",
"if",
"buf",
"else",
"None"
] | Returns the name of the manufacturer of the device.
Args:
self (JLinkDeviceInfo): the ``JLinkDeviceInfo`` instance
Returns:
Manufacturer name. | [
"Returns",
"the",
"name",
"of",
"the",
"manufacturer",
"of",
"the",
"device",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/structs.py#L219-L229 | train |
square/pylink | pylink/structs.py | JLinkBreakpointInfo.software_breakpoint | def software_breakpoint(self):
"""Returns whether this is a software breakpoint.
Args:
self (JLinkBreakpointInfo): the ``JLinkBreakpointInfo`` instance
Returns:
``True`` if the breakpoint is a software breakpoint, otherwise
``False``.
"""
software_... | python | def software_breakpoint(self):
"""Returns whether this is a software breakpoint.
Args:
self (JLinkBreakpointInfo): the ``JLinkBreakpointInfo`` instance
Returns:
``True`` if the breakpoint is a software breakpoint, otherwise
``False``.
"""
software_... | [
"def",
"software_breakpoint",
"(",
"self",
")",
":",
"software_types",
"=",
"[",
"enums",
".",
"JLinkBreakpoint",
".",
"SW_RAM",
",",
"enums",
".",
"JLinkBreakpoint",
".",
"SW_FLASH",
",",
"enums",
".",
"JLinkBreakpoint",
".",
"SW",
"]",
"return",
"any",
"("... | Returns whether this is a software breakpoint.
Args:
self (JLinkBreakpointInfo): the ``JLinkBreakpointInfo`` instance
Returns:
``True`` if the breakpoint is a software breakpoint, otherwise
``False``. | [
"Returns",
"whether",
"this",
"is",
"a",
"software",
"breakpoint",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/structs.py#L687-L702 | train |
square/pylink | pylink/library.py | Library.find_library_windows | def find_library_windows(cls):
"""Loads the SEGGER DLL from the windows installation directory.
On Windows, these are found either under:
- ``C:\\Program Files\\SEGGER\\JLink``
- ``C:\\Program Files (x86)\\SEGGER\\JLink``.
Args:
cls (Library): the ``Library`` clas... | python | def find_library_windows(cls):
"""Loads the SEGGER DLL from the windows installation directory.
On Windows, these are found either under:
- ``C:\\Program Files\\SEGGER\\JLink``
- ``C:\\Program Files (x86)\\SEGGER\\JLink``.
Args:
cls (Library): the ``Library`` clas... | [
"def",
"find_library_windows",
"(",
"cls",
")",
":",
"dll",
"=",
"cls",
".",
"get_appropriate_windows_sdk_name",
"(",
")",
"+",
"'.dll'",
"root",
"=",
"'C:\\\\'",
"for",
"d",
"in",
"os",
".",
"listdir",
"(",
"root",
")",
":",
"dir_path",
"=",
"os",
".",
... | Loads the SEGGER DLL from the windows installation directory.
On Windows, these are found either under:
- ``C:\\Program Files\\SEGGER\\JLink``
- ``C:\\Program Files (x86)\\SEGGER\\JLink``.
Args:
cls (Library): the ``Library`` class
Returns:
The paths to... | [
"Loads",
"the",
"SEGGER",
"DLL",
"from",
"the",
"windows",
"installation",
"directory",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/library.py#L112-L144 | train |
square/pylink | pylink/library.py | Library.find_library_linux | def find_library_linux(cls):
"""Loads the SEGGER DLL from the root directory.
On Linux, the SEGGER tools are installed under the ``/opt/SEGGER``
directory with versioned directories having the suffix ``_VERSION``.
Args:
cls (Library): the ``Library`` class
Returns:
... | python | def find_library_linux(cls):
"""Loads the SEGGER DLL from the root directory.
On Linux, the SEGGER tools are installed under the ``/opt/SEGGER``
directory with versioned directories having the suffix ``_VERSION``.
Args:
cls (Library): the ``Library`` class
Returns:
... | [
"def",
"find_library_linux",
"(",
"cls",
")",
":",
"dll",
"=",
"Library",
".",
"JLINK_SDK_NAME",
"root",
"=",
"os",
".",
"path",
".",
"join",
"(",
"'/'",
",",
"'opt'",
",",
"'SEGGER'",
")",
"for",
"(",
"directory_name",
",",
"subdirs",
",",
"files",
")... | Loads the SEGGER DLL from the root directory.
On Linux, the SEGGER tools are installed under the ``/opt/SEGGER``
directory with versioned directories having the suffix ``_VERSION``.
Args:
cls (Library): the ``Library`` class
Returns:
The paths to the J-Link library... | [
"Loads",
"the",
"SEGGER",
"DLL",
"from",
"the",
"root",
"directory",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/library.py#L147-L182 | train |
square/pylink | pylink/library.py | Library.find_library_darwin | def find_library_darwin(cls):
"""Loads the SEGGER DLL from the installed applications.
This method accounts for the all the different ways in which the DLL
may be installed depending on the version of the DLL. Always uses
the first directory found.
SEGGER's DLL is installed in... | python | def find_library_darwin(cls):
"""Loads the SEGGER DLL from the installed applications.
This method accounts for the all the different ways in which the DLL
may be installed depending on the version of the DLL. Always uses
the first directory found.
SEGGER's DLL is installed in... | [
"def",
"find_library_darwin",
"(",
"cls",
")",
":",
"dll",
"=",
"Library",
".",
"JLINK_SDK_NAME",
"root",
"=",
"os",
".",
"path",
".",
"join",
"(",
"'/'",
",",
"'Applications'",
",",
"'SEGGER'",
")",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
... | Loads the SEGGER DLL from the installed applications.
This method accounts for the all the different ways in which the DLL
may be installed depending on the version of the DLL. Always uses
the first directory found.
SEGGER's DLL is installed in one of three ways dependent on which
... | [
"Loads",
"the",
"SEGGER",
"DLL",
"from",
"the",
"installed",
"applications",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/library.py#L185-L231 | train |
square/pylink | pylink/library.py | Library.load_default | def load_default(self):
"""Loads the default J-Link SDK DLL.
The default J-Link SDK is determined by first checking if ``ctypes``
can find the DLL, then by searching the platform-specific paths.
Args:
self (Library): the ``Library`` instance
Returns:
``True... | python | def load_default(self):
"""Loads the default J-Link SDK DLL.
The default J-Link SDK is determined by first checking if ``ctypes``
can find the DLL, then by searching the platform-specific paths.
Args:
self (Library): the ``Library`` instance
Returns:
``True... | [
"def",
"load_default",
"(",
"self",
")",
":",
"path",
"=",
"ctypes_util",
".",
"find_library",
"(",
"self",
".",
"_sdk",
")",
"if",
"path",
"is",
"None",
":",
"if",
"self",
".",
"_windows",
"or",
"self",
".",
"_cygwin",
":",
"path",
"=",
"next",
"(",... | Loads the default J-Link SDK DLL.
The default J-Link SDK is determined by first checking if ``ctypes``
can find the DLL, then by searching the platform-specific paths.
Args:
self (Library): the ``Library`` instance
Returns:
``True`` if the DLL was loaded, otherwise... | [
"Loads",
"the",
"default",
"J",
"-",
"Link",
"SDK",
"DLL",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/library.py#L274-L301 | train |
square/pylink | pylink/library.py | Library.load | def load(self, path=None):
"""Loads the specified DLL, if any, otherwise re-loads the current DLL.
If ``path`` is specified, loads the DLL at the given ``path``,
otherwise re-loads the DLL currently specified by this library.
Note:
This creates a temporary DLL file to use for... | python | def load(self, path=None):
"""Loads the specified DLL, if any, otherwise re-loads the current DLL.
If ``path`` is specified, loads the DLL at the given ``path``,
otherwise re-loads the DLL currently specified by this library.
Note:
This creates a temporary DLL file to use for... | [
"def",
"load",
"(",
"self",
",",
"path",
"=",
"None",
")",
":",
"self",
".",
"unload",
"(",
")",
"self",
".",
"_path",
"=",
"path",
"or",
"self",
".",
"_path",
"if",
"self",
".",
"_windows",
"or",
"self",
".",
"_cygwin",
":",
"suffix",
"=",
"'.dl... | Loads the specified DLL, if any, otherwise re-loads the current DLL.
If ``path`` is specified, loads the DLL at the given ``path``,
otherwise re-loads the DLL currently specified by this library.
Note:
This creates a temporary DLL file to use for the instance. This is
nece... | [
"Loads",
"the",
"specified",
"DLL",
"if",
"any",
"otherwise",
"re",
"-",
"loads",
"the",
"current",
"DLL",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/library.py#L303-L368 | train |
square/pylink | pylink/library.py | Library.unload | def unload(self):
"""Unloads the library's DLL if it has been loaded.
This additionally cleans up the temporary DLL file that was created
when the library was loaded.
Args:
self (Library): the ``Library`` instance
Returns:
``True`` if the DLL was unloaded, ... | python | def unload(self):
"""Unloads the library's DLL if it has been loaded.
This additionally cleans up the temporary DLL file that was created
when the library was loaded.
Args:
self (Library): the ``Library`` instance
Returns:
``True`` if the DLL was unloaded, ... | [
"def",
"unload",
"(",
"self",
")",
":",
"unloaded",
"=",
"False",
"if",
"self",
".",
"_lib",
"is",
"not",
"None",
":",
"if",
"self",
".",
"_winlib",
"is",
"not",
"None",
":",
"ctypes",
".",
"windll",
".",
"kernel32",
".",
"FreeLibrary",
".",
"argtype... | Unloads the library's DLL if it has been loaded.
This additionally cleans up the temporary DLL file that was created
when the library was loaded.
Args:
self (Library): the ``Library`` instance
Returns:
``True`` if the DLL was unloaded, otherwise ``False``. | [
"Unloads",
"the",
"library",
"s",
"DLL",
"if",
"it",
"has",
"been",
"loaded",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/library.py#L370-L414 | train |
bndr/pipreqs | pipreqs/pipreqs.py | _open | def _open(filename=None, mode='r'):
"""Open a file or ``sys.stdout`` depending on the provided filename.
Args:
filename (str): The path to the file that should be opened. If
``None`` or ``'-'``, ``sys.stdout`` or ``sys.stdin`` is
returned depending on the desired mode. Defaults ... | python | def _open(filename=None, mode='r'):
"""Open a file or ``sys.stdout`` depending on the provided filename.
Args:
filename (str): The path to the file that should be opened. If
``None`` or ``'-'``, ``sys.stdout`` or ``sys.stdin`` is
returned depending on the desired mode. Defaults ... | [
"def",
"_open",
"(",
"filename",
"=",
"None",
",",
"mode",
"=",
"'r'",
")",
":",
"if",
"not",
"filename",
"or",
"filename",
"==",
"'-'",
":",
"if",
"not",
"mode",
"or",
"'r'",
"in",
"mode",
":",
"file",
"=",
"sys",
".",
"stdin",
"elif",
"'w'",
"i... | Open a file or ``sys.stdout`` depending on the provided filename.
Args:
filename (str): The path to the file that should be opened. If
``None`` or ``'-'``, ``sys.stdout`` or ``sys.stdin`` is
returned depending on the desired mode. Defaults to ``None``.
mode (str): The mode t... | [
"Open",
"a",
"file",
"or",
"sys",
".",
"stdout",
"depending",
"on",
"the",
"provided",
"filename",
"."
] | 15208540da03fdacf48fcb0a8b88b26da76b64f3 | https://github.com/bndr/pipreqs/blob/15208540da03fdacf48fcb0a8b88b26da76b64f3/pipreqs/pipreqs.py#L66-L93 | train |
bndr/pipreqs | pipreqs/pipreqs.py | get_pkg_names | def get_pkg_names(pkgs):
"""Get PyPI package names from a list of imports.
Args:
pkgs (List[str]): List of import names.
Returns:
List[str]: The corresponding PyPI package names.
"""
result = set()
with open(join("mapping"), "r") as f:
data = dict(x.strip().split(":") ... | python | def get_pkg_names(pkgs):
"""Get PyPI package names from a list of imports.
Args:
pkgs (List[str]): List of import names.
Returns:
List[str]: The corresponding PyPI package names.
"""
result = set()
with open(join("mapping"), "r") as f:
data = dict(x.strip().split(":") ... | [
"def",
"get_pkg_names",
"(",
"pkgs",
")",
":",
"result",
"=",
"set",
"(",
")",
"with",
"open",
"(",
"join",
"(",
"\"mapping\"",
")",
",",
"\"r\"",
")",
"as",
"f",
":",
"data",
"=",
"dict",
"(",
"x",
".",
"strip",
"(",
")",
".",
"split",
"(",
"\... | Get PyPI package names from a list of imports.
Args:
pkgs (List[str]): List of import names.
Returns:
List[str]: The corresponding PyPI package names. | [
"Get",
"PyPI",
"package",
"names",
"from",
"a",
"list",
"of",
"imports",
"."
] | 15208540da03fdacf48fcb0a8b88b26da76b64f3 | https://github.com/bndr/pipreqs/blob/15208540da03fdacf48fcb0a8b88b26da76b64f3/pipreqs/pipreqs.py#L252-L270 | train |
spyder-ide/qtawesome | qtawesome/__init__.py | charmap | def charmap(prefixed_name):
"""
Return the character map used for a given font.
Returns
-------
return_value: dict
The dictionary mapping the icon names to the corresponding unicode character.
"""
prefix, name = prefixed_name.split('.')
return _instance().charmap[prefix][name] | python | def charmap(prefixed_name):
"""
Return the character map used for a given font.
Returns
-------
return_value: dict
The dictionary mapping the icon names to the corresponding unicode character.
"""
prefix, name = prefixed_name.split('.')
return _instance().charmap[prefix][name] | [
"def",
"charmap",
"(",
"prefixed_name",
")",
":",
"prefix",
",",
"name",
"=",
"prefixed_name",
".",
"split",
"(",
"'.'",
")",
"return",
"_instance",
"(",
")",
".",
"charmap",
"[",
"prefix",
"]",
"[",
"name",
"]"
] | Return the character map used for a given font.
Returns
-------
return_value: dict
The dictionary mapping the icon names to the corresponding unicode character. | [
"Return",
"the",
"character",
"map",
"used",
"for",
"a",
"given",
"font",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/qtawesome/__init__.py#L176-L187 | train |
spyder-ide/qtawesome | qtawesome/iconic_font.py | set_global_defaults | def set_global_defaults(**kwargs):
"""Set global defaults for the options passed to the icon painter."""
valid_options = [
'active', 'selected', 'disabled', 'on', 'off',
'on_active', 'on_selected', 'on_disabled',
'off_active', 'off_selected', 'off_disabled',
'color', 'color_on',... | python | def set_global_defaults(**kwargs):
"""Set global defaults for the options passed to the icon painter."""
valid_options = [
'active', 'selected', 'disabled', 'on', 'off',
'on_active', 'on_selected', 'on_disabled',
'off_active', 'off_selected', 'off_disabled',
'color', 'color_on',... | [
"def",
"set_global_defaults",
"(",
"**",
"kwargs",
")",
":",
"valid_options",
"=",
"[",
"'active'",
",",
"'selected'",
",",
"'disabled'",
",",
"'on'",
",",
"'off'",
",",
"'on_active'",
",",
"'on_selected'",
",",
"'on_disabled'",
",",
"'off_active'",
",",
"'off... | Set global defaults for the options passed to the icon painter. | [
"Set",
"global",
"defaults",
"for",
"the",
"options",
"passed",
"to",
"the",
"icon",
"painter",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/qtawesome/iconic_font.py#L53-L72 | train |
spyder-ide/qtawesome | qtawesome/iconic_font.py | CharIconPainter.paint | def paint(self, iconic, painter, rect, mode, state, options):
"""Main paint method."""
for opt in options:
self._paint_icon(iconic, painter, rect, mode, state, opt) | python | def paint(self, iconic, painter, rect, mode, state, options):
"""Main paint method."""
for opt in options:
self._paint_icon(iconic, painter, rect, mode, state, opt) | [
"def",
"paint",
"(",
"self",
",",
"iconic",
",",
"painter",
",",
"rect",
",",
"mode",
",",
"state",
",",
"options",
")",
":",
"for",
"opt",
"in",
"options",
":",
"self",
".",
"_paint_icon",
"(",
"iconic",
",",
"painter",
",",
"rect",
",",
"mode",
"... | Main paint method. | [
"Main",
"paint",
"method",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/qtawesome/iconic_font.py#L79-L82 | train |
spyder-ide/qtawesome | qtawesome/iconic_font.py | CharIconPainter._paint_icon | def _paint_icon(self, iconic, painter, rect, mode, state, options):
"""Paint a single icon."""
painter.save()
color = options['color']
char = options['char']
color_options = {
QIcon.On: {
QIcon.Normal: (options['color_on'], options['on']),
... | python | def _paint_icon(self, iconic, painter, rect, mode, state, options):
"""Paint a single icon."""
painter.save()
color = options['color']
char = options['char']
color_options = {
QIcon.On: {
QIcon.Normal: (options['color_on'], options['on']),
... | [
"def",
"_paint_icon",
"(",
"self",
",",
"iconic",
",",
"painter",
",",
"rect",
",",
"mode",
",",
"state",
",",
"options",
")",
":",
"painter",
".",
"save",
"(",
")",
"color",
"=",
"options",
"[",
"'color'",
"]",
"char",
"=",
"options",
"[",
"'char'",... | Paint a single icon. | [
"Paint",
"a",
"single",
"icon",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/qtawesome/iconic_font.py#L84-L138 | train |
spyder-ide/qtawesome | qtawesome/iconic_font.py | IconicFont.icon | def icon(self, *names, **kwargs):
"""Return a QIcon object corresponding to the provided icon name."""
cache_key = '{}{}'.format(names,kwargs)
if cache_key not in self.icon_cache:
options_list = kwargs.pop('options', [{}] * len(names))
general_options = kwargs
... | python | def icon(self, *names, **kwargs):
"""Return a QIcon object corresponding to the provided icon name."""
cache_key = '{}{}'.format(names,kwargs)
if cache_key not in self.icon_cache:
options_list = kwargs.pop('options', [{}] * len(names))
general_options = kwargs
... | [
"def",
"icon",
"(",
"self",
",",
"*",
"names",
",",
"**",
"kwargs",
")",
":",
"cache_key",
"=",
"'{}{}'",
".",
"format",
"(",
"names",
",",
"kwargs",
")",
"if",
"cache_key",
"not",
"in",
"self",
".",
"icon_cache",
":",
"options_list",
"=",
"kwargs",
... | Return a QIcon object corresponding to the provided icon name. | [
"Return",
"a",
"QIcon",
"object",
"corresponding",
"to",
"the",
"provided",
"icon",
"name",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/qtawesome/iconic_font.py#L252-L279 | train |
spyder-ide/qtawesome | qtawesome/iconic_font.py | IconicFont.font | def font(self, prefix, size):
"""Return a QFont corresponding to the given prefix and size."""
font = QFont(self.fontname[prefix])
font.setPixelSize(size)
if prefix[-1] == 's': # solid style
font.setStyleName('Solid')
return font | python | def font(self, prefix, size):
"""Return a QFont corresponding to the given prefix and size."""
font = QFont(self.fontname[prefix])
font.setPixelSize(size)
if prefix[-1] == 's': # solid style
font.setStyleName('Solid')
return font | [
"def",
"font",
"(",
"self",
",",
"prefix",
",",
"size",
")",
":",
"font",
"=",
"QFont",
"(",
"self",
".",
"fontname",
"[",
"prefix",
"]",
")",
"font",
".",
"setPixelSize",
"(",
"size",
")",
"if",
"prefix",
"[",
"-",
"1",
"]",
"==",
"'s'",
":",
... | Return a QFont corresponding to the given prefix and size. | [
"Return",
"a",
"QFont",
"corresponding",
"to",
"the",
"given",
"prefix",
"and",
"size",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/qtawesome/iconic_font.py#L357-L363 | train |
spyder-ide/qtawesome | qtawesome/iconic_font.py | IconicFont._custom_icon | def _custom_icon(self, name, **kwargs):
"""Return the custom icon corresponding to the given name."""
options = dict(_default_options, **kwargs)
if name in self.painters:
painter = self.painters[name]
return self._icon_by_painter(painter, options)
else:
... | python | def _custom_icon(self, name, **kwargs):
"""Return the custom icon corresponding to the given name."""
options = dict(_default_options, **kwargs)
if name in self.painters:
painter = self.painters[name]
return self._icon_by_painter(painter, options)
else:
... | [
"def",
"_custom_icon",
"(",
"self",
",",
"name",
",",
"**",
"kwargs",
")",
":",
"options",
"=",
"dict",
"(",
"_default_options",
",",
"**",
"kwargs",
")",
"if",
"name",
"in",
"self",
".",
"painters",
":",
"painter",
"=",
"self",
".",
"painters",
"[",
... | Return the custom icon corresponding to the given name. | [
"Return",
"the",
"custom",
"icon",
"corresponding",
"to",
"the",
"given",
"name",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/qtawesome/iconic_font.py#L381-L388 | train |
spyder-ide/qtawesome | qtawesome/iconic_font.py | IconicFont._icon_by_painter | def _icon_by_painter(self, painter, options):
"""Return the icon corresponding to the given painter."""
engine = CharIconEngine(self, painter, options)
return QIcon(engine) | python | def _icon_by_painter(self, painter, options):
"""Return the icon corresponding to the given painter."""
engine = CharIconEngine(self, painter, options)
return QIcon(engine) | [
"def",
"_icon_by_painter",
"(",
"self",
",",
"painter",
",",
"options",
")",
":",
"engine",
"=",
"CharIconEngine",
"(",
"self",
",",
"painter",
",",
"options",
")",
"return",
"QIcon",
"(",
"engine",
")"
] | Return the icon corresponding to the given painter. | [
"Return",
"the",
"icon",
"corresponding",
"to",
"the",
"given",
"painter",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/qtawesome/iconic_font.py#L390-L393 | train |
spyder-ide/qtawesome | setupbase.py | UpdateFA5Command.finalize_options | def finalize_options(self):
"""Validate the command options."""
assert bool(self.fa_version), 'FA version is mandatory for this command.'
if self.zip_path:
assert os.path.exists(self.zip_path), (
'Local zipfile does not exist: %s' % self.zip_path) | python | def finalize_options(self):
"""Validate the command options."""
assert bool(self.fa_version), 'FA version is mandatory for this command.'
if self.zip_path:
assert os.path.exists(self.zip_path), (
'Local zipfile does not exist: %s' % self.zip_path) | [
"def",
"finalize_options",
"(",
"self",
")",
":",
"assert",
"bool",
"(",
"self",
".",
"fa_version",
")",
",",
"'FA version is mandatory for this command.'",
"if",
"self",
".",
"zip_path",
":",
"assert",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"zi... | Validate the command options. | [
"Validate",
"the",
"command",
"options",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/setupbase.py#L98-L103 | train |
spyder-ide/qtawesome | setupbase.py | UpdateFA5Command.__print | def __print(self, msg):
"""Shortcut for printing with the distutils logger."""
self.announce(msg, level=distutils.log.INFO) | python | def __print(self, msg):
"""Shortcut for printing with the distutils logger."""
self.announce(msg, level=distutils.log.INFO) | [
"def",
"__print",
"(",
"self",
",",
"msg",
")",
":",
"self",
".",
"announce",
"(",
"msg",
",",
"level",
"=",
"distutils",
".",
"log",
".",
"INFO",
")"
] | Shortcut for printing with the distutils logger. | [
"Shortcut",
"for",
"printing",
"with",
"the",
"distutils",
"logger",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/setupbase.py#L105-L107 | train |
spyder-ide/qtawesome | setupbase.py | UpdateFA5Command.__zip_file | def __zip_file(self):
"""Get a file object of the FA zip file."""
if self.zip_path:
# If using a local file, just open it:
self.__print('Opening local zipfile: %s' % self.zip_path)
return open(self.zip_path, 'rb')
# Otherwise, download it and make a file obje... | python | def __zip_file(self):
"""Get a file object of the FA zip file."""
if self.zip_path:
# If using a local file, just open it:
self.__print('Opening local zipfile: %s' % self.zip_path)
return open(self.zip_path, 'rb')
# Otherwise, download it and make a file obje... | [
"def",
"__zip_file",
"(",
"self",
")",
":",
"if",
"self",
".",
"zip_path",
":",
"self",
".",
"__print",
"(",
"'Opening local zipfile: %s'",
"%",
"self",
".",
"zip_path",
")",
"return",
"open",
"(",
"self",
".",
"zip_path",
",",
"'rb'",
")",
"url",
"=",
... | Get a file object of the FA zip file. | [
"Get",
"a",
"file",
"object",
"of",
"the",
"FA",
"zip",
"file",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/setupbase.py#L123-L134 | train |
spyder-ide/qtawesome | setupbase.py | UpdateFA5Command.__zipped_files_data | def __zipped_files_data(self):
"""Get a dict of all files of interest from the FA release zipfile."""
files = {}
with zipfile.ZipFile(self.__zip_file) as thezip:
for zipinfo in thezip.infolist():
if zipinfo.filename.endswith('metadata/icons.json'):
... | python | def __zipped_files_data(self):
"""Get a dict of all files of interest from the FA release zipfile."""
files = {}
with zipfile.ZipFile(self.__zip_file) as thezip:
for zipinfo in thezip.infolist():
if zipinfo.filename.endswith('metadata/icons.json'):
... | [
"def",
"__zipped_files_data",
"(",
"self",
")",
":",
"files",
"=",
"{",
"}",
"with",
"zipfile",
".",
"ZipFile",
"(",
"self",
".",
"__zip_file",
")",
"as",
"thezip",
":",
"for",
"zipinfo",
"in",
"thezip",
".",
"infolist",
"(",
")",
":",
"if",
"zipinfo",... | Get a dict of all files of interest from the FA release zipfile. | [
"Get",
"a",
"dict",
"of",
"all",
"files",
"of",
"interest",
"from",
"the",
"FA",
"release",
"zipfile",
"."
] | c88122aac5b7000eab9d2ae98d27fb3ade88d0f3 | https://github.com/spyder-ide/qtawesome/blob/c88122aac5b7000eab9d2ae98d27fb3ade88d0f3/setupbase.py#L137-L162 | train |
trailofbits/protofuzz | protofuzz/pbimport.py | from_string | def from_string(proto_str):
'''
Produce a Protobuf module from a string description.
Return the module if successfully compiled, otherwise raise a BadProtobuf
exception.
'''
_, proto_file = tempfile.mkstemp(suffix='.proto')
with open(proto_file, 'w+') as proto_f:
proto_f.... | python | def from_string(proto_str):
'''
Produce a Protobuf module from a string description.
Return the module if successfully compiled, otherwise raise a BadProtobuf
exception.
'''
_, proto_file = tempfile.mkstemp(suffix='.proto')
with open(proto_file, 'w+') as proto_f:
proto_f.... | [
"def",
"from_string",
"(",
"proto_str",
")",
":",
"_",
",",
"proto_file",
"=",
"tempfile",
".",
"mkstemp",
"(",
"suffix",
"=",
"'.proto'",
")",
"with",
"open",
"(",
"proto_file",
",",
"'w+'",
")",
"as",
"proto_f",
":",
"proto_f",
".",
"write",
"(",
"pr... | Produce a Protobuf module from a string description.
Return the module if successfully compiled, otherwise raise a BadProtobuf
exception. | [
"Produce",
"a",
"Protobuf",
"module",
"from",
"a",
"string",
"description",
".",
"Return",
"the",
"module",
"if",
"successfully",
"compiled",
"otherwise",
"raise",
"a",
"BadProtobuf",
"exception",
"."
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/pbimport.py#L48-L60 | train |
trailofbits/protofuzz | protofuzz/pbimport.py | _load_module | def _load_module(path):
'Helper to load a Python file at path and return as a module'
module_name = os.path.splitext(os.path.basename(path))[0]
module = None
if sys.version_info.minor < 5:
loader = importlib.machinery.SourceFileLoader(module_name, path)
module = loader.load_mod... | python | def _load_module(path):
'Helper to load a Python file at path and return as a module'
module_name = os.path.splitext(os.path.basename(path))[0]
module = None
if sys.version_info.minor < 5:
loader = importlib.machinery.SourceFileLoader(module_name, path)
module = loader.load_mod... | [
"def",
"_load_module",
"(",
"path",
")",
":",
"'Helper to load a Python file at path and return as a module'",
"module_name",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"os",
".",
"path",
".",
"basename",
"(",
"path",
")",
")",
"[",
"0",
"]",
"module",
"=",... | Helper to load a Python file at path and return as a module | [
"Helper",
"to",
"load",
"a",
"Python",
"file",
"at",
"path",
"and",
"return",
"as",
"a",
"module"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/pbimport.py#L63-L77 | train |
trailofbits/protofuzz | protofuzz/pbimport.py | _compile_proto | def _compile_proto(full_path, dest):
'Helper to compile protobuf files'
proto_path = os.path.dirname(full_path)
protoc_args = [find_protoc(),
'--python_out={}'.format(dest),
'--proto_path={}'.format(proto_path),
full_path]
proc = subprocess... | python | def _compile_proto(full_path, dest):
'Helper to compile protobuf files'
proto_path = os.path.dirname(full_path)
protoc_args = [find_protoc(),
'--python_out={}'.format(dest),
'--proto_path={}'.format(proto_path),
full_path]
proc = subprocess... | [
"def",
"_compile_proto",
"(",
"full_path",
",",
"dest",
")",
":",
"'Helper to compile protobuf files'",
"proto_path",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"full_path",
")",
"protoc_args",
"=",
"[",
"find_protoc",
"(",
")",
",",
"'--python_out={}'",
".",
... | Helper to compile protobuf files | [
"Helper",
"to",
"compile",
"protobuf",
"files"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/pbimport.py#L80-L101 | train |
trailofbits/protofuzz | protofuzz/pbimport.py | from_file | def from_file(proto_file):
'''
Take a filename |protoc_file|, compile it via the Protobuf
compiler, and import the module.
Return the module if successfully compiled, otherwise raise either
a ProtocNotFound or BadProtobuf exception.
'''
if not proto_file.endswith('.proto'):
... | python | def from_file(proto_file):
'''
Take a filename |protoc_file|, compile it via the Protobuf
compiler, and import the module.
Return the module if successfully compiled, otherwise raise either
a ProtocNotFound or BadProtobuf exception.
'''
if not proto_file.endswith('.proto'):
... | [
"def",
"from_file",
"(",
"proto_file",
")",
":",
"if",
"not",
"proto_file",
".",
"endswith",
"(",
"'.proto'",
")",
":",
"raise",
"BadProtobuf",
"(",
")",
"dest",
"=",
"tempfile",
".",
"mkdtemp",
"(",
")",
"full_path",
"=",
"os",
".",
"path",
".",
"absp... | Take a filename |protoc_file|, compile it via the Protobuf
compiler, and import the module.
Return the module if successfully compiled, otherwise raise either
a ProtocNotFound or BadProtobuf exception. | [
"Take",
"a",
"filename",
"|protoc_file|",
"compile",
"it",
"via",
"the",
"Protobuf",
"compiler",
"and",
"import",
"the",
"module",
".",
"Return",
"the",
"module",
"if",
"successfully",
"compiled",
"otherwise",
"raise",
"either",
"a",
"ProtocNotFound",
"or",
"Bad... | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/pbimport.py#L104-L123 | train |
trailofbits/protofuzz | protofuzz/pbimport.py | types_from_module | def types_from_module(pb_module):
'''
Return protobuf class types from an imported generated module.
'''
types = pb_module.DESCRIPTOR.message_types_by_name
return [getattr(pb_module, name) for name in types] | python | def types_from_module(pb_module):
'''
Return protobuf class types from an imported generated module.
'''
types = pb_module.DESCRIPTOR.message_types_by_name
return [getattr(pb_module, name) for name in types] | [
"def",
"types_from_module",
"(",
"pb_module",
")",
":",
"types",
"=",
"pb_module",
".",
"DESCRIPTOR",
".",
"message_types_by_name",
"return",
"[",
"getattr",
"(",
"pb_module",
",",
"name",
")",
"for",
"name",
"in",
"types",
"]"
] | Return protobuf class types from an imported generated module. | [
"Return",
"protobuf",
"class",
"types",
"from",
"an",
"imported",
"generated",
"module",
"."
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/pbimport.py#L126-L131 | train |
trailofbits/protofuzz | protofuzz/gen.py | Permuter._resolve_child | def _resolve_child(self, path):
'Return a member generator by a dot-delimited path'
obj = self
for component in path.split('.'):
ptr = obj
if not isinstance(ptr, Permuter):
raise self.MessageNotFound("Bad element path [wrong type]")
# pylint:... | python | def _resolve_child(self, path):
'Return a member generator by a dot-delimited path'
obj = self
for component in path.split('.'):
ptr = obj
if not isinstance(ptr, Permuter):
raise self.MessageNotFound("Bad element path [wrong type]")
# pylint:... | [
"def",
"_resolve_child",
"(",
"self",
",",
"path",
")",
":",
"'Return a member generator by a dot-delimited path'",
"obj",
"=",
"self",
"for",
"component",
"in",
"path",
".",
"split",
"(",
"'.'",
")",
":",
"ptr",
"=",
"obj",
"if",
"not",
"isinstance",
"(",
"... | Return a member generator by a dot-delimited path | [
"Return",
"a",
"member",
"generator",
"by",
"a",
"dot",
"-",
"delimited",
"path"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/gen.py#L111-L128 | train |
trailofbits/protofuzz | protofuzz/gen.py | Permuter.make_dependent | def make_dependent(self, source, target, action):
'''
Create a dependency between path 'source' and path 'target' via the
callable 'action'.
>>> permuter._generators
[IterValueGenerator(one), IterValueGenerator(two)]
>>> permuter.make_dependent('one', 'two', lambda x: x ... | python | def make_dependent(self, source, target, action):
'''
Create a dependency between path 'source' and path 'target' via the
callable 'action'.
>>> permuter._generators
[IterValueGenerator(one), IterValueGenerator(two)]
>>> permuter.make_dependent('one', 'two', lambda x: x ... | [
"def",
"make_dependent",
"(",
"self",
",",
"source",
",",
"target",
",",
"action",
")",
":",
"if",
"not",
"self",
".",
"_generators",
":",
"return",
"src_permuter",
",",
"src",
"=",
"self",
".",
"_resolve_child",
"(",
"source",
")",
"dest",
"=",
"self",
... | Create a dependency between path 'source' and path 'target' via the
callable 'action'.
>>> permuter._generators
[IterValueGenerator(one), IterValueGenerator(two)]
>>> permuter.make_dependent('one', 'two', lambda x: x + 1)
Going forward, 'two' will only contain values that are (... | [
"Create",
"a",
"dependency",
"between",
"path",
"source",
"and",
"path",
"target",
"via",
"the",
"callable",
"action",
"."
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/gen.py#L130-L152 | train |
trailofbits/protofuzz | protofuzz/gen.py | Permuter.get | def get(self):
'Retrieve the most recent value generated'
# If you attempt to use a generator comprehension below, it will
# consume the StopIteration exception and just return an empty tuple,
# instead of stopping iteration normally
return tuple([(x.name(), x.get()) for x in sel... | python | def get(self):
'Retrieve the most recent value generated'
# If you attempt to use a generator comprehension below, it will
# consume the StopIteration exception and just return an empty tuple,
# instead of stopping iteration normally
return tuple([(x.name(), x.get()) for x in sel... | [
"def",
"get",
"(",
"self",
")",
":",
"'Retrieve the most recent value generated'",
"return",
"tuple",
"(",
"[",
"(",
"x",
".",
"name",
"(",
")",
",",
"x",
".",
"get",
"(",
")",
")",
"for",
"x",
"in",
"self",
".",
"_generators",
"]",
")"
] | Retrieve the most recent value generated | [
"Retrieve",
"the",
"most",
"recent",
"value",
"generated"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/gen.py#L154-L159 | train |
trailofbits/protofuzz | protofuzz/values.py | _fuzzdb_integers | def _fuzzdb_integers(limit=0):
'Helper to grab some integers from fuzzdb'
path = os.path.join(BASE_PATH, 'integer-overflow/integer-overflows.txt')
stream = _open_fuzzdb_file(path)
for line in _limit_helper(stream, limit):
yield int(line.decode('utf-8'), 0) | python | def _fuzzdb_integers(limit=0):
'Helper to grab some integers from fuzzdb'
path = os.path.join(BASE_PATH, 'integer-overflow/integer-overflows.txt')
stream = _open_fuzzdb_file(path)
for line in _limit_helper(stream, limit):
yield int(line.decode('utf-8'), 0) | [
"def",
"_fuzzdb_integers",
"(",
"limit",
"=",
"0",
")",
":",
"'Helper to grab some integers from fuzzdb'",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"BASE_PATH",
",",
"'integer-overflow/integer-overflows.txt'",
")",
"stream",
"=",
"_open_fuzzdb_file",
"(",
"... | Helper to grab some integers from fuzzdb | [
"Helper",
"to",
"grab",
"some",
"integers",
"from",
"fuzzdb"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/values.py#L31-L36 | train |
trailofbits/protofuzz | protofuzz/values.py | _fuzzdb_get_strings | def _fuzzdb_get_strings(max_len=0):
'Helper to get all the strings from fuzzdb'
ignored = ['integer-overflow']
for subdir in pkg_resources.resource_listdir('protofuzz', BASE_PATH):
if subdir in ignored:
continue
path = '{}/{}'.format(BASE_PATH, subdir)
listing = pkg_re... | python | def _fuzzdb_get_strings(max_len=0):
'Helper to get all the strings from fuzzdb'
ignored = ['integer-overflow']
for subdir in pkg_resources.resource_listdir('protofuzz', BASE_PATH):
if subdir in ignored:
continue
path = '{}/{}'.format(BASE_PATH, subdir)
listing = pkg_re... | [
"def",
"_fuzzdb_get_strings",
"(",
"max_len",
"=",
"0",
")",
":",
"'Helper to get all the strings from fuzzdb'",
"ignored",
"=",
"[",
"'integer-overflow'",
"]",
"for",
"subdir",
"in",
"pkg_resources",
".",
"resource_listdir",
"(",
"'protofuzz'",
",",
"BASE_PATH",
")",... | Helper to get all the strings from fuzzdb | [
"Helper",
"to",
"get",
"all",
"the",
"strings",
"from",
"fuzzdb"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/values.py#L39-L63 | train |
trailofbits/protofuzz | protofuzz/values.py | get_integers | def get_integers(bitwidth, unsigned, limit=0):
'''
Get integers from fuzzdb database
bitwidth - The bitwidth that has to contain the integer
unsigned - Whether the type is unsigned
limit - Limit to |limit| results
'''
if unsigned:
start, stop = 0, ((1 << bitwidth) - 1)
els... | python | def get_integers(bitwidth, unsigned, limit=0):
'''
Get integers from fuzzdb database
bitwidth - The bitwidth that has to contain the integer
unsigned - Whether the type is unsigned
limit - Limit to |limit| results
'''
if unsigned:
start, stop = 0, ((1 << bitwidth) - 1)
els... | [
"def",
"get_integers",
"(",
"bitwidth",
",",
"unsigned",
",",
"limit",
"=",
"0",
")",
":",
"if",
"unsigned",
":",
"start",
",",
"stop",
"=",
"0",
",",
"(",
"(",
"1",
"<<",
"bitwidth",
")",
"-",
"1",
")",
"else",
":",
"start",
",",
"stop",
"=",
... | Get integers from fuzzdb database
bitwidth - The bitwidth that has to contain the integer
unsigned - Whether the type is unsigned
limit - Limit to |limit| results | [
"Get",
"integers",
"from",
"fuzzdb",
"database"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/values.py#L76-L91 | train |
trailofbits/protofuzz | protofuzz/values.py | get_floats | def get_floats(bitwidth, limit=0):
'''
Return a number of interesting floating point values
'''
assert bitwidth in (32, 64, 80)
values = [0.0, -1.0, 1.0, -1231231231231.0123, 123123123123123.123]
for val in _limit_helper(values, limit):
yield val | python | def get_floats(bitwidth, limit=0):
'''
Return a number of interesting floating point values
'''
assert bitwidth in (32, 64, 80)
values = [0.0, -1.0, 1.0, -1231231231231.0123, 123123123123123.123]
for val in _limit_helper(values, limit):
yield val | [
"def",
"get_floats",
"(",
"bitwidth",
",",
"limit",
"=",
"0",
")",
":",
"assert",
"bitwidth",
"in",
"(",
"32",
",",
"64",
",",
"80",
")",
"values",
"=",
"[",
"0.0",
",",
"-",
"1.0",
",",
"1.0",
",",
"-",
"1231231231231.0123",
",",
"123123123123123.12... | Return a number of interesting floating point values | [
"Return",
"a",
"number",
"of",
"interesting",
"floating",
"point",
"values"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/values.py#L94-L102 | train |
trailofbits/protofuzz | protofuzz/protofuzz.py | _int_generator | def _int_generator(descriptor, bitwidth, unsigned):
'Helper to create a basic integer value generator'
vals = list(values.get_integers(bitwidth, unsigned))
return gen.IterValueGenerator(descriptor.name, vals) | python | def _int_generator(descriptor, bitwidth, unsigned):
'Helper to create a basic integer value generator'
vals = list(values.get_integers(bitwidth, unsigned))
return gen.IterValueGenerator(descriptor.name, vals) | [
"def",
"_int_generator",
"(",
"descriptor",
",",
"bitwidth",
",",
"unsigned",
")",
":",
"'Helper to create a basic integer value generator'",
"vals",
"=",
"list",
"(",
"values",
".",
"get_integers",
"(",
"bitwidth",
",",
"unsigned",
")",
")",
"return",
"gen",
".",... | Helper to create a basic integer value generator | [
"Helper",
"to",
"create",
"a",
"basic",
"integer",
"value",
"generator"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L41-L44 | train |
trailofbits/protofuzz | protofuzz/protofuzz.py | _string_generator | def _string_generator(descriptor, max_length=0, limit=0):
'Helper to create a string generator'
vals = list(values.get_strings(max_length, limit))
return gen.IterValueGenerator(descriptor.name, vals) | python | def _string_generator(descriptor, max_length=0, limit=0):
'Helper to create a string generator'
vals = list(values.get_strings(max_length, limit))
return gen.IterValueGenerator(descriptor.name, vals) | [
"def",
"_string_generator",
"(",
"descriptor",
",",
"max_length",
"=",
"0",
",",
"limit",
"=",
"0",
")",
":",
"'Helper to create a string generator'",
"vals",
"=",
"list",
"(",
"values",
".",
"get_strings",
"(",
"max_length",
",",
"limit",
")",
")",
"return",
... | Helper to create a string generator | [
"Helper",
"to",
"create",
"a",
"string",
"generator"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L47-L50 | train |
trailofbits/protofuzz | protofuzz/protofuzz.py | _float_generator | def _float_generator(descriptor, bitwidth):
'Helper to create floating point values'
return gen.IterValueGenerator(descriptor.name, values.get_floats(bitwidth)) | python | def _float_generator(descriptor, bitwidth):
'Helper to create floating point values'
return gen.IterValueGenerator(descriptor.name, values.get_floats(bitwidth)) | [
"def",
"_float_generator",
"(",
"descriptor",
",",
"bitwidth",
")",
":",
"'Helper to create floating point values'",
"return",
"gen",
".",
"IterValueGenerator",
"(",
"descriptor",
".",
"name",
",",
"values",
".",
"get_floats",
"(",
"bitwidth",
")",
")"
] | Helper to create floating point values | [
"Helper",
"to",
"create",
"floating",
"point",
"values"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L60-L62 | train |
trailofbits/protofuzz | protofuzz/protofuzz.py | _enum_generator | def _enum_generator(descriptor):
'Helper to create protobuf enums'
vals = descriptor.enum_type.values_by_number.keys()
return gen.IterValueGenerator(descriptor.name, vals) | python | def _enum_generator(descriptor):
'Helper to create protobuf enums'
vals = descriptor.enum_type.values_by_number.keys()
return gen.IterValueGenerator(descriptor.name, vals) | [
"def",
"_enum_generator",
"(",
"descriptor",
")",
":",
"'Helper to create protobuf enums'",
"vals",
"=",
"descriptor",
".",
"enum_type",
".",
"values_by_number",
".",
"keys",
"(",
")",
"return",
"gen",
".",
"IterValueGenerator",
"(",
"descriptor",
".",
"name",
","... | Helper to create protobuf enums | [
"Helper",
"to",
"create",
"protobuf",
"enums"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L65-L68 | train |
trailofbits/protofuzz | protofuzz/protofuzz.py | _prototype_to_generator | def _prototype_to_generator(descriptor, cls):
'Helper to map a descriptor to a protofuzz generator'
_fd = D.FieldDescriptor
generator = None
ints32 = [_fd.TYPE_INT32, _fd.TYPE_UINT32, _fd.TYPE_FIXED32,
_fd.TYPE_SFIXED32, _fd.TYPE_SINT32]
ints64 = [_fd.TYPE_INT64, _fd.TYPE_UINT64, _fd.... | python | def _prototype_to_generator(descriptor, cls):
'Helper to map a descriptor to a protofuzz generator'
_fd = D.FieldDescriptor
generator = None
ints32 = [_fd.TYPE_INT32, _fd.TYPE_UINT32, _fd.TYPE_FIXED32,
_fd.TYPE_SFIXED32, _fd.TYPE_SINT32]
ints64 = [_fd.TYPE_INT64, _fd.TYPE_UINT64, _fd.... | [
"def",
"_prototype_to_generator",
"(",
"descriptor",
",",
"cls",
")",
":",
"'Helper to map a descriptor to a protofuzz generator'",
"_fd",
"=",
"D",
".",
"FieldDescriptor",
"generator",
"=",
"None",
"ints32",
"=",
"[",
"_fd",
".",
"TYPE_INT32",
",",
"_fd",
".",
"T... | Helper to map a descriptor to a protofuzz generator | [
"Helper",
"to",
"map",
"a",
"descriptor",
"to",
"a",
"protofuzz",
"generator"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L71-L105 | train |
trailofbits/protofuzz | protofuzz/protofuzz.py | descriptor_to_generator | def descriptor_to_generator(cls_descriptor, cls, limit=0):
'Convert a protobuf descriptor to a protofuzz generator for same type'
generators = []
for descriptor in cls_descriptor.fields_by_name.values():
generator = _prototype_to_generator(descriptor, cls)
if limit != 0:
genera... | python | def descriptor_to_generator(cls_descriptor, cls, limit=0):
'Convert a protobuf descriptor to a protofuzz generator for same type'
generators = []
for descriptor in cls_descriptor.fields_by_name.values():
generator = _prototype_to_generator(descriptor, cls)
if limit != 0:
genera... | [
"def",
"descriptor_to_generator",
"(",
"cls_descriptor",
",",
"cls",
",",
"limit",
"=",
"0",
")",
":",
"'Convert a protobuf descriptor to a protofuzz generator for same type'",
"generators",
"=",
"[",
"]",
"for",
"descriptor",
"in",
"cls_descriptor",
".",
"fields_by_name"... | Convert a protobuf descriptor to a protofuzz generator for same type | [
"Convert",
"a",
"protobuf",
"descriptor",
"to",
"a",
"protofuzz",
"generator",
"for",
"same",
"type"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L108-L121 | train |
trailofbits/protofuzz | protofuzz/protofuzz.py | _assign_to_field | def _assign_to_field(obj, name, val):
'Helper to assign an arbitrary value to a protobuf field'
target = getattr(obj, name)
if isinstance(target, containers.RepeatedScalarFieldContainer):
target.append(val)
elif isinstance(target, containers.RepeatedCompositeFieldContainer):
target = ta... | python | def _assign_to_field(obj, name, val):
'Helper to assign an arbitrary value to a protobuf field'
target = getattr(obj, name)
if isinstance(target, containers.RepeatedScalarFieldContainer):
target.append(val)
elif isinstance(target, containers.RepeatedCompositeFieldContainer):
target = ta... | [
"def",
"_assign_to_field",
"(",
"obj",
",",
"name",
",",
"val",
")",
":",
"'Helper to assign an arbitrary value to a protobuf field'",
"target",
"=",
"getattr",
"(",
"obj",
",",
"name",
")",
"if",
"isinstance",
"(",
"target",
",",
"containers",
".",
"RepeatedScala... | Helper to assign an arbitrary value to a protobuf field | [
"Helper",
"to",
"assign",
"an",
"arbitrary",
"value",
"to",
"a",
"protobuf",
"field"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L124-L138 | train |
trailofbits/protofuzz | protofuzz/protofuzz.py | _fields_to_object | def _fields_to_object(descriptor, fields):
'Helper to convert a descriptor and a set of fields to a Protobuf instance'
# pylint: disable=protected-access
obj = descriptor._concrete_class()
for name, value in fields:
if isinstance(value, tuple):
subtype = descriptor.fields_by_name[na... | python | def _fields_to_object(descriptor, fields):
'Helper to convert a descriptor and a set of fields to a Protobuf instance'
# pylint: disable=protected-access
obj = descriptor._concrete_class()
for name, value in fields:
if isinstance(value, tuple):
subtype = descriptor.fields_by_name[na... | [
"def",
"_fields_to_object",
"(",
"descriptor",
",",
"fields",
")",
":",
"'Helper to convert a descriptor and a set of fields to a Protobuf instance'",
"obj",
"=",
"descriptor",
".",
"_concrete_class",
"(",
")",
"for",
"name",
",",
"value",
"in",
"fields",
":",
"if",
"... | Helper to convert a descriptor and a set of fields to a Protobuf instance | [
"Helper",
"to",
"convert",
"a",
"descriptor",
"and",
"a",
"set",
"of",
"fields",
"to",
"a",
"Protobuf",
"instance"
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L141-L152 | train |
trailofbits/protofuzz | protofuzz/protofuzz.py | _module_to_generators | def _module_to_generators(pb_module):
'''
Convert a protobuf module to a dict of generators.
This is typically used with modules that contain multiple type definitions.
'''
if not pb_module:
return None
message_types = pb_module.DESCRIPTOR.message_types_by_name
return {k: ProtobufGe... | python | def _module_to_generators(pb_module):
'''
Convert a protobuf module to a dict of generators.
This is typically used with modules that contain multiple type definitions.
'''
if not pb_module:
return None
message_types = pb_module.DESCRIPTOR.message_types_by_name
return {k: ProtobufGe... | [
"def",
"_module_to_generators",
"(",
"pb_module",
")",
":",
"if",
"not",
"pb_module",
":",
"return",
"None",
"message_types",
"=",
"pb_module",
".",
"DESCRIPTOR",
".",
"message_types_by_name",
"return",
"{",
"k",
":",
"ProtobufGenerator",
"(",
"v",
")",
"for",
... | Convert a protobuf module to a dict of generators.
This is typically used with modules that contain multiple type definitions. | [
"Convert",
"a",
"protobuf",
"module",
"to",
"a",
"dict",
"of",
"generators",
"."
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L224-L233 | train |
trailofbits/protofuzz | protofuzz/protofuzz.py | ProtobufGenerator.add_dependency | def add_dependency(self, source, target, action):
'''
Create a dependency between fields source and target via callable
action.
>>> permuter = protofuzz.from_description_string("""
... message Address {
... required uint32 one = 1;
... required uint... | python | def add_dependency(self, source, target, action):
'''
Create a dependency between fields source and target via callable
action.
>>> permuter = protofuzz.from_description_string("""
... message Address {
... required uint32 one = 1;
... required uint... | [
"def",
"add_dependency",
"(",
"self",
",",
"source",
",",
"target",
",",
"action",
")",
":",
"self",
".",
"_dependencies",
".",
"append",
"(",
"(",
"source",
",",
"target",
",",
"action",
")",
")"
] | Create a dependency between fields source and target via callable
action.
>>> permuter = protofuzz.from_description_string("""
... message Address {
... required uint32 one = 1;
... required uint32 two = 2;
... }""")['Address']
>>> permuter.add_de... | [
"Create",
"a",
"dependency",
"between",
"fields",
"source",
"and",
"target",
"via",
"callable",
"action",
"."
] | 589492d34de9a0da6cc5554094e2588b893b2fd8 | https://github.com/trailofbits/protofuzz/blob/589492d34de9a0da6cc5554094e2588b893b2fd8/protofuzz/protofuzz.py#L185-L213 | train |
sepandhaghighi/pycm | pycm/pycm_compare.py | Compare.print_report | def print_report(self):
"""
Print Compare report.
:return: None
"""
report = compare_report_print(
self.sorted, self.scores, self.best_name)
print(report) | python | def print_report(self):
"""
Print Compare report.
:return: None
"""
report = compare_report_print(
self.sorted, self.scores, self.best_name)
print(report) | [
"def",
"print_report",
"(",
"self",
")",
":",
"report",
"=",
"compare_report_print",
"(",
"self",
".",
"sorted",
",",
"self",
".",
"scores",
",",
"self",
".",
"best_name",
")",
"print",
"(",
"report",
")"
] | Print Compare report.
:return: None | [
"Print",
"Compare",
"report",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_compare.py#L98-L106 | train |
sepandhaghighi/pycm | pycm/pycm_class_func.py | F_calc | def F_calc(TP, FP, FN, beta):
"""
Calculate F-score.
:param TP: true positive
:type TP : int
:param FP: false positive
:type FP : int
:param FN: false negative
:type FN : int
:param beta : beta coefficient
:type beta : float
:return: F score as float
"""
try:
... | python | def F_calc(TP, FP, FN, beta):
"""
Calculate F-score.
:param TP: true positive
:type TP : int
:param FP: false positive
:type FP : int
:param FN: false negative
:type FN : int
:param beta : beta coefficient
:type beta : float
:return: F score as float
"""
try:
... | [
"def",
"F_calc",
"(",
"TP",
",",
"FP",
",",
"FN",
",",
"beta",
")",
":",
"try",
":",
"result",
"=",
"(",
"(",
"1",
"+",
"(",
"beta",
")",
"**",
"2",
")",
"*",
"TP",
")",
"/",
"(",
"(",
"1",
"+",
"(",
"beta",
")",
"**",
"2",
")",
"*",
... | Calculate F-score.
:param TP: true positive
:type TP : int
:param FP: false positive
:type FP : int
:param FN: false negative
:type FN : int
:param beta : beta coefficient
:type beta : float
:return: F score as float | [
"Calculate",
"F",
"-",
"score",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_class_func.py#L61-L80 | train |
sepandhaghighi/pycm | pycm/pycm_class_func.py | G_calc | def G_calc(item1, item2):
"""
Calculate G-measure & G-mean.
:param item1: PPV or TPR or TNR
:type item1 : float
:param item2: PPV or TPR or TNR
:type item2 : float
:return: G-measure or G-mean as float
"""
try:
result = math.sqrt(item1 * item2)
return result
exce... | python | def G_calc(item1, item2):
"""
Calculate G-measure & G-mean.
:param item1: PPV or TPR or TNR
:type item1 : float
:param item2: PPV or TPR or TNR
:type item2 : float
:return: G-measure or G-mean as float
"""
try:
result = math.sqrt(item1 * item2)
return result
exce... | [
"def",
"G_calc",
"(",
"item1",
",",
"item2",
")",
":",
"try",
":",
"result",
"=",
"math",
".",
"sqrt",
"(",
"item1",
"*",
"item2",
")",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] | Calculate G-measure & G-mean.
:param item1: PPV or TPR or TNR
:type item1 : float
:param item2: PPV or TPR or TNR
:type item2 : float
:return: G-measure or G-mean as float | [
"Calculate",
"G",
"-",
"measure",
"&",
"G",
"-",
"mean",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_class_func.py#L156-L170 | train |
sepandhaghighi/pycm | pycm/pycm_class_func.py | RACC_calc | def RACC_calc(TOP, P, POP):
"""
Calculate random accuracy.
:param TOP: test outcome positive
:type TOP : int
:param P: condition positive
:type P : int
:param POP: population
:type POP:int
:return: RACC as float
"""
try:
result = (TOP * P) / ((POP) ** 2)
ret... | python | def RACC_calc(TOP, P, POP):
"""
Calculate random accuracy.
:param TOP: test outcome positive
:type TOP : int
:param P: condition positive
:type P : int
:param POP: population
:type POP:int
:return: RACC as float
"""
try:
result = (TOP * P) / ((POP) ** 2)
ret... | [
"def",
"RACC_calc",
"(",
"TOP",
",",
"P",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"(",
"TOP",
"*",
"P",
")",
"/",
"(",
"(",
"POP",
")",
"**",
"2",
")",
"return",
"result",
"except",
"Exception",
":",
"return",
"\"None\""
] | Calculate random accuracy.
:param TOP: test outcome positive
:type TOP : int
:param P: condition positive
:type P : int
:param POP: population
:type POP:int
:return: RACC as float | [
"Calculate",
"random",
"accuracy",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_class_func.py#L173-L189 | train |
sepandhaghighi/pycm | pycm/pycm_class_func.py | CEN_misclassification_calc | def CEN_misclassification_calc(
table,
TOP,
P,
i,
j,
subject_class,
modified=False):
"""
Calculate misclassification probability of classifying.
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : in... | python | def CEN_misclassification_calc(
table,
TOP,
P,
i,
j,
subject_class,
modified=False):
"""
Calculate misclassification probability of classifying.
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : in... | [
"def",
"CEN_misclassification_calc",
"(",
"table",
",",
"TOP",
",",
"P",
",",
"i",
",",
"j",
",",
"subject_class",
",",
"modified",
"=",
"False",
")",
":",
"try",
":",
"result",
"=",
"TOP",
"+",
"P",
"if",
"modified",
":",
"result",
"-=",
"table",
"[... | Calculate misclassification probability of classifying.
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : int
:param P: condition positive
:type P : int
:param i: table row index (class name)
:type i : any valid type
:param j: table col inde... | [
"Calculate",
"misclassification",
"probability",
"of",
"classifying",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_class_func.py#L265-L299 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | html_init | def html_init(name):
"""
Return HTML report file first lines.
:param name: name of file
:type name : str
:return: html_init as str
"""
result = ""
result += "<html>\n"
result += "<head>\n"
result += "<title>" + str(name) + "</title>\n"
result += "</head>\n"
result += "<b... | python | def html_init(name):
"""
Return HTML report file first lines.
:param name: name of file
:type name : str
:return: html_init as str
"""
result = ""
result += "<html>\n"
result += "<head>\n"
result += "<title>" + str(name) + "</title>\n"
result += "</head>\n"
result += "<b... | [
"def",
"html_init",
"(",
"name",
")",
":",
"result",
"=",
"\"\"",
"result",
"+=",
"\"<html>\\n\"",
"result",
"+=",
"\"<head>\\n\"",
"result",
"+=",
"\"<title>\"",
"+",
"str",
"(",
"name",
")",
"+",
"\"</title>\\n\"",
"result",
"+=",
"\"</head>\\n\"",
"result",... | Return HTML report file first lines.
:param name: name of file
:type name : str
:return: html_init as str | [
"Return",
"HTML",
"report",
"file",
"first",
"lines",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L10-L26 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | html_dataset_type | def html_dataset_type(is_binary, is_imbalanced):
"""
Return HTML report file dataset type.
:param is_binary: is_binary flag (binary : True , multi-class : False)
:type is_binary: bool
:param is_imbalanced: is_imbalanced flag (imbalance : True , balance : False)
:type is_imbalanced: bool
:re... | python | def html_dataset_type(is_binary, is_imbalanced):
"""
Return HTML report file dataset type.
:param is_binary: is_binary flag (binary : True , multi-class : False)
:type is_binary: bool
:param is_imbalanced: is_imbalanced flag (imbalance : True , balance : False)
:type is_imbalanced: bool
:re... | [
"def",
"html_dataset_type",
"(",
"is_binary",
",",
"is_imbalanced",
")",
":",
"result",
"=",
"\"<h2>Dataset Type : </h2>\\n\"",
"balance_type",
"=",
"\"Balanced\"",
"class_type",
"=",
"\"Binary Classification\"",
"if",
"is_imbalanced",
":",
"balance_type",
"=",
"\"Imbalan... | Return HTML report file dataset type.
:param is_binary: is_binary flag (binary : True , multi-class : False)
:type is_binary: bool
:param is_imbalanced: is_imbalanced flag (imbalance : True , balance : False)
:type is_imbalanced: bool
:return: dataset_type as str | [
"Return",
"HTML",
"report",
"file",
"dataset",
"type",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L29-L51 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | color_check | def color_check(color):
"""
Check input color format.
:param color: input color
:type color : tuple
:return: color as list
"""
if isinstance(color, (tuple, list)):
if all(map(lambda x: isinstance(x, int), color)):
if all(map(lambda x: x < 256, color)):
re... | python | def color_check(color):
"""
Check input color format.
:param color: input color
:type color : tuple
:return: color as list
"""
if isinstance(color, (tuple, list)):
if all(map(lambda x: isinstance(x, int), color)):
if all(map(lambda x: x < 256, color)):
re... | [
"def",
"color_check",
"(",
"color",
")",
":",
"if",
"isinstance",
"(",
"color",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"if",
"all",
"(",
"map",
"(",
"lambda",
"x",
":",
"isinstance",
"(",
"x",
",",
"int",
")",
",",
"color",
")",
")",
":... | Check input color format.
:param color: input color
:type color : tuple
:return: color as list | [
"Check",
"input",
"color",
"format",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L54-L70 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | html_table_color | def html_table_color(row, item, color=(0, 0, 0)):
"""
Return background color of each cell of table.
:param row: row dictionary
:type row : dict
:param item: cell number
:type item : int
:param color : input color
:type color : tuple
:return: background color as list [R,G,B]
"""... | python | def html_table_color(row, item, color=(0, 0, 0)):
"""
Return background color of each cell of table.
:param row: row dictionary
:type row : dict
:param item: cell number
:type item : int
:param color : input color
:type color : tuple
:return: background color as list [R,G,B]
"""... | [
"def",
"html_table_color",
"(",
"row",
",",
"item",
",",
"color",
"=",
"(",
"0",
",",
"0",
",",
"0",
")",
")",
":",
"result",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
"color_list",
"=",
"color_check",
"(",
"color",
")",
"max_color",
"=",
"max",
... | Return background color of each cell of table.
:param row: row dictionary
:type row : dict
:param item: cell number
:type item : int
:param color : input color
:type color : tuple
:return: background color as list [R,G,B] | [
"Return",
"background",
"color",
"of",
"each",
"cell",
"of",
"table",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L73-L93 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | html_table | def html_table(classes, table, rgb_color, normalize=False):
"""
Return HTML report file confusion matrix.
:param classes: matrix classes
:type classes: list
:param table: matrix
:type table : dict
:param rgb_color : input color
:type rgb_color : tuple
:param normalize : save normali... | python | def html_table(classes, table, rgb_color, normalize=False):
"""
Return HTML report file confusion matrix.
:param classes: matrix classes
:type classes: list
:param table: matrix
:type table : dict
:param rgb_color : input color
:type rgb_color : tuple
:param normalize : save normali... | [
"def",
"html_table",
"(",
"classes",
",",
"table",
",",
"rgb_color",
",",
"normalize",
"=",
"False",
")",
":",
"result",
"=",
"\"\"",
"result",
"+=",
"\"<h2>Confusion Matrix \"",
"if",
"normalize",
":",
"result",
"+=",
"\"(Normalized)\"",
"result",
"+=",
"\": ... | Return HTML report file confusion matrix.
:param classes: matrix classes
:type classes: list
:param table: matrix
:type table : dict
:param rgb_color : input color
:type rgb_color : tuple
:param normalize : save normalize matrix flag
:type normalize : bool
:return: html_table as str | [
"Return",
"HTML",
"report",
"file",
"confusion",
"matrix",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L96-L148 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | html_overall_stat | def html_overall_stat(
overall_stat,
digit=5,
overall_param=None,
recommended_list=()):
"""
Return HTML report file overall stat.
:param overall_stat: overall stat
:type overall_stat : dict
:param digit: scale (the number of digits to the right of the decimal point i... | python | def html_overall_stat(
overall_stat,
digit=5,
overall_param=None,
recommended_list=()):
"""
Return HTML report file overall stat.
:param overall_stat: overall stat
:type overall_stat : dict
:param digit: scale (the number of digits to the right of the decimal point i... | [
"def",
"html_overall_stat",
"(",
"overall_stat",
",",
"digit",
"=",
"5",
",",
"overall_param",
"=",
"None",
",",
"recommended_list",
"=",
"(",
")",
")",
":",
"result",
"=",
"\"\"",
"result",
"+=",
"\"<h2>Overall Statistics : </h2>\\n\"",
"result",
"+=",
"'<table... | Return HTML report file overall stat.
:param overall_stat: overall stat
:type overall_stat : dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param overall_param : Overall parameters list for print, Example : ["Kappa","Scott PI]
:... | [
"Return",
"HTML",
"report",
"file",
"overall",
"stat",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L151-L194 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | html_class_stat | def html_class_stat(
classes,
class_stat,
digit=5,
class_param=None,
recommended_list=()):
"""
Return HTML report file class_stat.
:param classes: matrix classes
:type classes: list
:param class_stat: class stat
:type class_stat:dict
:param digit: sca... | python | def html_class_stat(
classes,
class_stat,
digit=5,
class_param=None,
recommended_list=()):
"""
Return HTML report file class_stat.
:param classes: matrix classes
:type classes: list
:param class_stat: class stat
:type class_stat:dict
:param digit: sca... | [
"def",
"html_class_stat",
"(",
"classes",
",",
"class_stat",
",",
"digit",
"=",
"5",
",",
"class_param",
"=",
"None",
",",
"recommended_list",
"=",
"(",
")",
")",
":",
"result",
"=",
"\"\"",
"result",
"+=",
"\"<h2>Class Statistics : </h2>\\n\"",
"result",
"+="... | Return HTML report file class_stat.
:param classes: matrix classes
:type classes: list
:param class_stat: class stat
:type class_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param class_param : Class parameters list f... | [
"Return",
"HTML",
"report",
"file",
"class_stat",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L197-L256 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | table_print | def table_print(classes, table):
"""
Return printable confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: printable table as str
"""
classes_len = len(classes)
table_list = []
for key in classes:
table_list.... | python | def table_print(classes, table):
"""
Return printable confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: printable table as str
"""
classes_len = len(classes)
table_list = []
for key in classes:
table_list.... | [
"def",
"table_print",
"(",
"classes",
",",
"table",
")",
":",
"classes_len",
"=",
"len",
"(",
"classes",
")",
"table_list",
"=",
"[",
"]",
"for",
"key",
"in",
"classes",
":",
"table_list",
".",
"extend",
"(",
"list",
"(",
"table",
"[",
"key",
"]",
".... | Return printable confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: printable table as str | [
"Return",
"printable",
"confusion",
"matrix",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L286-L313 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | csv_matrix_print | def csv_matrix_print(classes, table):
"""
Return matrix as csv data.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return:
"""
result = ""
classes.sort()
for i in classes:
for j in classes:
result += str(table[i][j]... | python | def csv_matrix_print(classes, table):
"""
Return matrix as csv data.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return:
"""
result = ""
classes.sort()
for i in classes:
for j in classes:
result += str(table[i][j]... | [
"def",
"csv_matrix_print",
"(",
"classes",
",",
"table",
")",
":",
"result",
"=",
"\"\"",
"classes",
".",
"sort",
"(",
")",
"for",
"i",
"in",
"classes",
":",
"for",
"j",
"in",
"classes",
":",
"result",
"+=",
"str",
"(",
"table",
"[",
"i",
"]",
"[",... | Return matrix as csv data.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: | [
"Return",
"matrix",
"as",
"csv",
"data",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L316-L332 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | csv_print | def csv_print(classes, class_stat, digit=5, class_param=None):
"""
Return csv file data.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type class_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a ... | python | def csv_print(classes, class_stat, digit=5, class_param=None):
"""
Return csv file data.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type class_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a ... | [
"def",
"csv_print",
"(",
"classes",
",",
"class_stat",
",",
"digit",
"=",
"5",
",",
"class_param",
"=",
"None",
")",
":",
"result",
"=",
"\"Class\"",
"classes",
".",
"sort",
"(",
")",
"for",
"item",
"in",
"classes",
":",
"result",
"+=",
"',\"'",
"+",
... | Return csv file data.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type class_stat:dict
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:param class_param : class parameters li... | [
"Return",
"csv",
"file",
"data",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L335-L364 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | stat_print | def stat_print(
classes,
class_stat,
overall_stat,
digit=5,
overall_param=None,
class_param=None):
"""
Return printable statistics table.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type clas... | python | def stat_print(
classes,
class_stat,
overall_stat,
digit=5,
overall_param=None,
class_param=None):
"""
Return printable statistics table.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type clas... | [
"def",
"stat_print",
"(",
"classes",
",",
"class_stat",
",",
"overall_stat",
",",
"digit",
"=",
"5",
",",
"overall_param",
"=",
"None",
",",
"class_param",
"=",
"None",
")",
":",
"shift",
"=",
"max",
"(",
"map",
"(",
"len",
",",
"PARAMS_DESCRIPTION",
"."... | Return printable statistics table.
:param classes: classes list
:type classes:list
:param class_stat: statistic result for each class
:type class_stat:dict
:param overall_stat : overall statistic result
:type overall_stat:dict
:param digit: scale (the number of digits to the right of the de... | [
"Return",
"printable",
"statistics",
"table",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L367-L426 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | compare_report_print | def compare_report_print(sorted_list, scores, best_name):
"""
Return compare report.
:param sorted_list: sorted list of cm's
:type sorted_list: list
:param scores: scores of cm's
:type scores: dict
:param best_name: best cm name
:type best_name: str
:return: printable result as str
... | python | def compare_report_print(sorted_list, scores, best_name):
"""
Return compare report.
:param sorted_list: sorted list of cm's
:type sorted_list: list
:param scores: scores of cm's
:type scores: dict
:param best_name: best cm name
:type best_name: str
:return: printable result as str
... | [
"def",
"compare_report_print",
"(",
"sorted_list",
",",
"scores",
",",
"best_name",
")",
":",
"title_items",
"=",
"[",
"\"Rank\"",
",",
"\"Name\"",
",",
"\"Class-Score\"",
",",
"\"Overall-Score\"",
"]",
"class_scores_len",
"=",
"map",
"(",
"lambda",
"x",
":",
... | Return compare report.
:param sorted_list: sorted list of cm's
:type sorted_list: list
:param scores: scores of cm's
:type scores: dict
:param best_name: best cm name
:type best_name: str
:return: printable result as str | [
"Return",
"compare",
"report",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L429-L466 | train |
sepandhaghighi/pycm | pycm/pycm_output.py | online_help | def online_help(param=None):
"""
Open online document in web browser.
:param param: input parameter
:type param : int or str
:return: None
"""
try:
PARAMS_LINK_KEYS = sorted(PARAMS_LINK.keys())
if param in PARAMS_LINK_KEYS:
webbrowser.open_new_tab(DOCUMENT_ADR + ... | python | def online_help(param=None):
"""
Open online document in web browser.
:param param: input parameter
:type param : int or str
:return: None
"""
try:
PARAMS_LINK_KEYS = sorted(PARAMS_LINK.keys())
if param in PARAMS_LINK_KEYS:
webbrowser.open_new_tab(DOCUMENT_ADR + ... | [
"def",
"online_help",
"(",
"param",
"=",
"None",
")",
":",
"try",
":",
"PARAMS_LINK_KEYS",
"=",
"sorted",
"(",
"PARAMS_LINK",
".",
"keys",
"(",
")",
")",
"if",
"param",
"in",
"PARAMS_LINK_KEYS",
":",
"webbrowser",
".",
"open_new_tab",
"(",
"DOCUMENT_ADR",
... | Open online document in web browser.
:param param: input parameter
:type param : int or str
:return: None | [
"Open",
"online",
"document",
"in",
"web",
"browser",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_output.py#L469-L490 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | rounder | def rounder(input_number, digit=5):
"""
Round input number and convert to str.
:param input_number: input number
:type input_number : anything
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:return: round number as str
"""
... | python | def rounder(input_number, digit=5):
"""
Round input number and convert to str.
:param input_number: input number
:type input_number : anything
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:return: round number as str
"""
... | [
"def",
"rounder",
"(",
"input_number",
",",
"digit",
"=",
"5",
")",
":",
"if",
"isinstance",
"(",
"input_number",
",",
"tuple",
")",
":",
"tuple_list",
"=",
"list",
"(",
"input_number",
")",
"tuple_str",
"=",
"[",
"]",
"for",
"i",
"in",
"tuple_list",
"... | Round input number and convert to str.
:param input_number: input number
:type input_number : anything
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:return: round number as str | [
"Round",
"input",
"number",
"and",
"convert",
"to",
"str",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L35-L56 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | class_filter | def class_filter(classes, class_name):
"""
Filter classes by comparing two lists.
:param classes: matrix classes
:type classes: list
:param class_name: sub set of classes
:type class_name : list
:return: filtered classes as list
"""
result_classes = classes
if isinstance(class_n... | python | def class_filter(classes, class_name):
"""
Filter classes by comparing two lists.
:param classes: matrix classes
:type classes: list
:param class_name: sub set of classes
:type class_name : list
:return: filtered classes as list
"""
result_classes = classes
if isinstance(class_n... | [
"def",
"class_filter",
"(",
"classes",
",",
"class_name",
")",
":",
"result_classes",
"=",
"classes",
"if",
"isinstance",
"(",
"class_name",
",",
"list",
")",
":",
"if",
"set",
"(",
"class_name",
")",
"<=",
"set",
"(",
"classes",
")",
":",
"result_classes"... | Filter classes by comparing two lists.
:param classes: matrix classes
:type classes: list
:param class_name: sub set of classes
:type class_name : list
:return: filtered classes as list | [
"Filter",
"classes",
"by",
"comparing",
"two",
"lists",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L59-L73 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | vector_check | def vector_check(vector):
"""
Check input vector items type.
:param vector: input vector
:type vector : list
:return: bool
"""
for i in vector:
if isinstance(i, int) is False:
return False
if i < 0:
return False
return True | python | def vector_check(vector):
"""
Check input vector items type.
:param vector: input vector
:type vector : list
:return: bool
"""
for i in vector:
if isinstance(i, int) is False:
return False
if i < 0:
return False
return True | [
"def",
"vector_check",
"(",
"vector",
")",
":",
"for",
"i",
"in",
"vector",
":",
"if",
"isinstance",
"(",
"i",
",",
"int",
")",
"is",
"False",
":",
"return",
"False",
"if",
"i",
"<",
"0",
":",
"return",
"False",
"return",
"True"
] | Check input vector items type.
:param vector: input vector
:type vector : list
:return: bool | [
"Check",
"input",
"vector",
"items",
"type",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L76-L89 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | matrix_check | def matrix_check(table):
"""
Check input matrix format.
:param table: input matrix
:type table : dict
:return: bool
"""
try:
if len(table.keys()) == 0:
return False
for i in table.keys():
if table.keys() != table[i].keys() or vector_check(
... | python | def matrix_check(table):
"""
Check input matrix format.
:param table: input matrix
:type table : dict
:return: bool
"""
try:
if len(table.keys()) == 0:
return False
for i in table.keys():
if table.keys() != table[i].keys() or vector_check(
... | [
"def",
"matrix_check",
"(",
"table",
")",
":",
"try",
":",
"if",
"len",
"(",
"table",
".",
"keys",
"(",
")",
")",
"==",
"0",
":",
"return",
"False",
"for",
"i",
"in",
"table",
".",
"keys",
"(",
")",
":",
"if",
"table",
".",
"keys",
"(",
")",
... | Check input matrix format.
:param table: input matrix
:type table : dict
:return: bool | [
"Check",
"input",
"matrix",
"format",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L92-L109 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | vector_filter | def vector_filter(actual_vector, predict_vector):
"""
Convert different type of items in vectors to str.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:return: new actual and predict vector
"""
temp = ... | python | def vector_filter(actual_vector, predict_vector):
"""
Convert different type of items in vectors to str.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:return: new actual and predict vector
"""
temp = ... | [
"def",
"vector_filter",
"(",
"actual_vector",
",",
"predict_vector",
")",
":",
"temp",
"=",
"[",
"]",
"temp",
".",
"extend",
"(",
"actual_vector",
")",
"temp",
".",
"extend",
"(",
"predict_vector",
")",
"types",
"=",
"set",
"(",
"map",
"(",
"type",
",",
... | Convert different type of items in vectors to str.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:return: new actual and predict vector | [
"Convert",
"different",
"type",
"of",
"items",
"in",
"vectors",
"to",
"str",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L112-L128 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | class_check | def class_check(vector):
"""
Check different items in matrix classes.
:param vector: input vector
:type vector : list
:return: bool
"""
for i in vector:
if not isinstance(i, type(vector[0])):
return False
return True | python | def class_check(vector):
"""
Check different items in matrix classes.
:param vector: input vector
:type vector : list
:return: bool
"""
for i in vector:
if not isinstance(i, type(vector[0])):
return False
return True | [
"def",
"class_check",
"(",
"vector",
")",
":",
"for",
"i",
"in",
"vector",
":",
"if",
"not",
"isinstance",
"(",
"i",
",",
"type",
"(",
"vector",
"[",
"0",
"]",
")",
")",
":",
"return",
"False",
"return",
"True"
] | Check different items in matrix classes.
:param vector: input vector
:type vector : list
:return: bool | [
"Check",
"different",
"items",
"in",
"matrix",
"classes",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L131-L142 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | one_vs_all_func | def one_vs_all_func(classes, table, TP, TN, FP, FN, class_name):
"""
One-Vs-All mode handler.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TP: true positive dict for all classes
:type TP : dict
:param TN: true negative dict for al... | python | def one_vs_all_func(classes, table, TP, TN, FP, FN, class_name):
"""
One-Vs-All mode handler.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TP: true positive dict for all classes
:type TP : dict
:param TN: true negative dict for al... | [
"def",
"one_vs_all_func",
"(",
"classes",
",",
"table",
",",
"TP",
",",
"TN",
",",
"FP",
",",
"FN",
",",
"class_name",
")",
":",
"try",
":",
"report_classes",
"=",
"[",
"str",
"(",
"class_name",
")",
",",
"\"~\"",
"]",
"report_table",
"=",
"{",
"str"... | One-Vs-All mode handler.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TP: true positive dict for all classes
:type TP : dict
:param TN: true negative dict for all classes
:type TN : dict
:param FP: false positive dict for all clas... | [
"One",
"-",
"Vs",
"-",
"All",
"mode",
"handler",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L158-L186 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | normalized_table_calc | def normalized_table_calc(classes, table):
"""
Return normalized confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: normalized table as dict
"""
map_dict = {k: 0 for k in classes}
new_table = {k: map_dict.copy() for k ... | python | def normalized_table_calc(classes, table):
"""
Return normalized confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: normalized table as dict
"""
map_dict = {k: 0 for k in classes}
new_table = {k: map_dict.copy() for k ... | [
"def",
"normalized_table_calc",
"(",
"classes",
",",
"table",
")",
":",
"map_dict",
"=",
"{",
"k",
":",
"0",
"for",
"k",
"in",
"classes",
"}",
"new_table",
"=",
"{",
"k",
":",
"map_dict",
".",
"copy",
"(",
")",
"for",
"k",
"in",
"classes",
"}",
"fo... | Return normalized confusion matrix.
:param classes: classes list
:type classes:list
:param table: table
:type table:dict
:return: normalized table as dict | [
"Return",
"normalized",
"confusion",
"matrix",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L189-L207 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | transpose_func | def transpose_func(classes, table):
"""
Transpose table.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:return: transposed table as dict
"""
transposed_table = table
for i, item1 in enumerate(classes):
for j, item2 in enumerat... | python | def transpose_func(classes, table):
"""
Transpose table.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:return: transposed table as dict
"""
transposed_table = table
for i, item1 in enumerate(classes):
for j, item2 in enumerat... | [
"def",
"transpose_func",
"(",
"classes",
",",
"table",
")",
":",
"transposed_table",
"=",
"table",
"for",
"i",
",",
"item1",
"in",
"enumerate",
"(",
"classes",
")",
":",
"for",
"j",
",",
"item2",
"in",
"enumerate",
"(",
"classes",
")",
":",
"if",
"i",
... | Transpose table.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:return: transposed table as dict | [
"Transpose",
"table",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L210-L227 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | matrix_params_from_table | def matrix_params_from_table(table, transpose=False):
"""
Calculate TP,TN,FP,FN from confusion matrix.
:param table: input matrix
:type table : dict
:param transpose : transpose flag
:type transpose : bool
:return: [classes_list,table,TP,TN,FP,FN]
"""
classes = sorted(table.keys())
... | python | def matrix_params_from_table(table, transpose=False):
"""
Calculate TP,TN,FP,FN from confusion matrix.
:param table: input matrix
:type table : dict
:param transpose : transpose flag
:type transpose : bool
:return: [classes_list,table,TP,TN,FP,FN]
"""
classes = sorted(table.keys())
... | [
"def",
"matrix_params_from_table",
"(",
"table",
",",
"transpose",
"=",
"False",
")",
":",
"classes",
"=",
"sorted",
"(",
"table",
".",
"keys",
"(",
")",
")",
"map_dict",
"=",
"{",
"k",
":",
"0",
"for",
"k",
"in",
"classes",
"}",
"TP_dict",
"=",
"map... | Calculate TP,TN,FP,FN from confusion matrix.
:param table: input matrix
:type table : dict
:param transpose : transpose flag
:type transpose : bool
:return: [classes_list,table,TP,TN,FP,FN] | [
"Calculate",
"TP",
"TN",
"FP",
"FN",
"from",
"confusion",
"matrix",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L230-L259 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | matrix_params_calc | def matrix_params_calc(actual_vector, predict_vector, sample_weight):
"""
Calculate TP,TN,FP,FN for each class.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:param sample_weight : sample weights list
:typ... | python | def matrix_params_calc(actual_vector, predict_vector, sample_weight):
"""
Calculate TP,TN,FP,FN for each class.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:param sample_weight : sample weights list
:typ... | [
"def",
"matrix_params_calc",
"(",
"actual_vector",
",",
"predict_vector",
",",
"sample_weight",
")",
":",
"if",
"isinstance",
"(",
"actual_vector",
",",
"numpy",
".",
"ndarray",
")",
":",
"actual_vector",
"=",
"actual_vector",
".",
"tolist",
"(",
")",
"if",
"i... | Calculate TP,TN,FP,FN for each class.
:param actual_vector: actual values
:type actual_vector : list
:param predict_vector: predict value
:type predict_vector : list
:param sample_weight : sample weights list
:type sample_weight : list
:return: [classes_list,table,TP,TN,FP,FN] | [
"Calculate",
"TP",
"TN",
"FP",
"FN",
"for",
"each",
"class",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L262-L290 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | imbalance_check | def imbalance_check(P):
"""
Check if the dataset is imbalanced.
:param P: condition positive
:type P : dict
:return: is_imbalanced as bool
"""
p_list = list(P.values())
max_value = max(p_list)
min_value = min(p_list)
if min_value > 0:
balance_ratio = max_value / min_valu... | python | def imbalance_check(P):
"""
Check if the dataset is imbalanced.
:param P: condition positive
:type P : dict
:return: is_imbalanced as bool
"""
p_list = list(P.values())
max_value = max(p_list)
min_value = min(p_list)
if min_value > 0:
balance_ratio = max_value / min_valu... | [
"def",
"imbalance_check",
"(",
"P",
")",
":",
"p_list",
"=",
"list",
"(",
"P",
".",
"values",
"(",
")",
")",
"max_value",
"=",
"max",
"(",
"p_list",
")",
"min_value",
"=",
"min",
"(",
"p_list",
")",
"if",
"min_value",
">",
"0",
":",
"balance_ratio",
... | Check if the dataset is imbalanced.
:param P: condition positive
:type P : dict
:return: is_imbalanced as bool | [
"Check",
"if",
"the",
"dataset",
"is",
"imbalanced",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L293-L311 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | binary_check | def binary_check(classes):
"""
Check if the problem is a binary classification.
:param classes: all classes name
:type classes : list
:return: is_binary as bool
"""
num_classes = len(classes)
is_binary = False
if num_classes == 2:
is_binary = True
return is_binary | python | def binary_check(classes):
"""
Check if the problem is a binary classification.
:param classes: all classes name
:type classes : list
:return: is_binary as bool
"""
num_classes = len(classes)
is_binary = False
if num_classes == 2:
is_binary = True
return is_binary | [
"def",
"binary_check",
"(",
"classes",
")",
":",
"num_classes",
"=",
"len",
"(",
"classes",
")",
"is_binary",
"=",
"False",
"if",
"num_classes",
"==",
"2",
":",
"is_binary",
"=",
"True",
"return",
"is_binary"
] | Check if the problem is a binary classification.
:param classes: all classes name
:type classes : list
:return: is_binary as bool | [
"Check",
"if",
"the",
"problem",
"is",
"a",
"binary",
"classification",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L314-L326 | train |
sepandhaghighi/pycm | pycm/pycm_util.py | statistic_recommend | def statistic_recommend(classes, P):
"""
Return recommend parameters which are more suitable due to the input dataset characteristics.
:param classes: all classes name
:type classes : list
:param P: condition positive
:type P : dict
:return: recommendation_list as list
"""
if imbal... | python | def statistic_recommend(classes, P):
"""
Return recommend parameters which are more suitable due to the input dataset characteristics.
:param classes: all classes name
:type classes : list
:param P: condition positive
:type P : dict
:return: recommendation_list as list
"""
if imbal... | [
"def",
"statistic_recommend",
"(",
"classes",
",",
"P",
")",
":",
"if",
"imbalance_check",
"(",
"P",
")",
":",
"return",
"IMBALANCED_RECOMMEND",
"if",
"binary_check",
"(",
"classes",
")",
":",
"return",
"BINARY_RECOMMEND",
"return",
"MULTICLASS_RECOMMEND"
] | Return recommend parameters which are more suitable due to the input dataset characteristics.
:param classes: all classes name
:type classes : list
:param P: condition positive
:type P : dict
:return: recommendation_list as list | [
"Return",
"recommend",
"parameters",
"which",
"are",
"more",
"suitable",
"due",
"to",
"the",
"input",
"dataset",
"characteristics",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_util.py#L329-L343 | train |
sepandhaghighi/pycm | Otherfiles/version_check.py | print_result | def print_result(failed=False):
"""
Print final result.
:param failed: failed flag
:type failed: bool
:return: None
"""
message = "Version tag tests "
if not failed:
print("\n" + message + "passed!")
else:
print("\n" + message + "failed!")
print("Passed : " + str... | python | def print_result(failed=False):
"""
Print final result.
:param failed: failed flag
:type failed: bool
:return: None
"""
message = "Version tag tests "
if not failed:
print("\n" + message + "passed!")
else:
print("\n" + message + "failed!")
print("Passed : " + str... | [
"def",
"print_result",
"(",
"failed",
"=",
"False",
")",
":",
"message",
"=",
"\"Version tag tests \"",
"if",
"not",
"failed",
":",
"print",
"(",
"\"\\n\"",
"+",
"message",
"+",
"\"passed!\"",
")",
"else",
":",
"print",
"(",
"\"\\n\"",
"+",
"message",
"+",... | Print final result.
:param failed: failed flag
:type failed: bool
:return: None | [
"Print",
"final",
"result",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/Otherfiles/version_check.py#L40-L53 | train |
sepandhaghighi/pycm | pycm/pycm_overall_func.py | AUNP_calc | def AUNP_calc(classes, P, POP, AUC_dict):
"""
Calculate AUNP.
:param classes: classes
:type classes : list
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:param AUC_dict: AUC (Area under the ROC curve) for each class
:type AUC_dict : dict
... | python | def AUNP_calc(classes, P, POP, AUC_dict):
"""
Calculate AUNP.
:param classes: classes
:type classes : list
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:param AUC_dict: AUC (Area under the ROC curve) for each class
:type AUC_dict : dict
... | [
"def",
"AUNP_calc",
"(",
"classes",
",",
"P",
",",
"POP",
",",
"AUC_dict",
")",
":",
"try",
":",
"result",
"=",
"0",
"for",
"i",
"in",
"classes",
":",
"result",
"+=",
"(",
"P",
"[",
"i",
"]",
"/",
"POP",
"[",
"i",
"]",
")",
"*",
"AUC_dict",
"... | Calculate AUNP.
:param classes: classes
:type classes : list
:param P: condition positive
:type P : dict
:param POP: population
:type POP : dict
:param AUC_dict: AUC (Area under the ROC curve) for each class
:type AUC_dict : dict
:return: AUNP as float | [
"Calculate",
"AUNP",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L43-L63 | train |
sepandhaghighi/pycm | pycm/pycm_overall_func.py | overall_MCC_calc | def overall_MCC_calc(classes, table, TOP, P):
"""
Calculate Overall_MCC.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:return: Overal... | python | def overall_MCC_calc(classes, table, TOP, P):
"""
Calculate Overall_MCC.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:return: Overal... | [
"def",
"overall_MCC_calc",
"(",
"classes",
",",
"table",
",",
"TOP",
",",
"P",
")",
":",
"try",
":",
"cov_x_y",
"=",
"0",
"cov_x_x",
"=",
"0",
"cov_y_y",
"=",
"0",
"matrix_sum",
"=",
"sum",
"(",
"list",
"(",
"TOP",
".",
"values",
"(",
")",
")",
"... | Calculate Overall_MCC.
:param classes: classes
:type classes : list
:param table: input matrix
:type table : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:return: Overall_MCC as float | [
"Calculate",
"Overall_MCC",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L108-L133 | train |
sepandhaghighi/pycm | pycm/pycm_overall_func.py | convex_combination | def convex_combination(classes, TP, TOP, P, class_name, modified=False):
"""
Calculate Overall_CEN coefficient.
:param classes: classes
:type classes : list
:param TP: true Positive Dict For All Classes
:type TP : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: con... | python | def convex_combination(classes, TP, TOP, P, class_name, modified=False):
"""
Calculate Overall_CEN coefficient.
:param classes: classes
:type classes : list
:param TP: true Positive Dict For All Classes
:type TP : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: con... | [
"def",
"convex_combination",
"(",
"classes",
",",
"TP",
",",
"TOP",
",",
"P",
",",
"class_name",
",",
"modified",
"=",
"False",
")",
":",
"try",
":",
"class_number",
"=",
"len",
"(",
"classes",
")",
"alpha",
"=",
"1",
"if",
"class_number",
"==",
"2",
... | Calculate Overall_CEN coefficient.
:param classes: classes
:type classes : list
:param TP: true Positive Dict For All Classes
:type TP : dict
:param TOP: test outcome positive
:type TOP : dict
:param P: condition positive
:type P : dict
:param class_name: reviewed class name
:ty... | [
"Calculate",
"Overall_CEN",
"coefficient",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L136-L168 | train |
sepandhaghighi/pycm | pycm/pycm_overall_func.py | ncr | def ncr(n, r):
"""
Calculate n choose r.
:param n: n
:type n : int
:param r: r
:type r :int
:return: n choose r as int
"""
r = min(r, n - r)
numer = reduce(op.mul, range(n, n - r, -1), 1)
denom = reduce(op.mul, range(1, r + 1), 1)
return numer // denom | python | def ncr(n, r):
"""
Calculate n choose r.
:param n: n
:type n : int
:param r: r
:type r :int
:return: n choose r as int
"""
r = min(r, n - r)
numer = reduce(op.mul, range(n, n - r, -1), 1)
denom = reduce(op.mul, range(1, r + 1), 1)
return numer // denom | [
"def",
"ncr",
"(",
"n",
",",
"r",
")",
":",
"r",
"=",
"min",
"(",
"r",
",",
"n",
"-",
"r",
")",
"numer",
"=",
"reduce",
"(",
"op",
".",
"mul",
",",
"range",
"(",
"n",
",",
"n",
"-",
"r",
",",
"-",
"1",
")",
",",
"1",
")",
"denom",
"="... | Calculate n choose r.
:param n: n
:type n : int
:param r: r
:type r :int
:return: n choose r as int | [
"Calculate",
"n",
"choose",
"r",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L199-L212 | train |
sepandhaghighi/pycm | pycm/pycm_overall_func.py | p_value_calc | def p_value_calc(TP, POP, NIR):
"""
Calculate p_value.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:param NIR: no information rate
:type NIR : float
:return: p_value as float
"""
try:
n = POP
x = sum(list(TP.values()))
... | python | def p_value_calc(TP, POP, NIR):
"""
Calculate p_value.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:param NIR: no information rate
:type NIR : float
:return: p_value as float
"""
try:
n = POP
x = sum(list(TP.values()))
... | [
"def",
"p_value_calc",
"(",
"TP",
",",
"POP",
",",
"NIR",
")",
":",
"try",
":",
"n",
"=",
"POP",
"x",
"=",
"sum",
"(",
"list",
"(",
"TP",
".",
"values",
"(",
")",
")",
")",
"p",
"=",
"NIR",
"result",
"=",
"0",
"for",
"j",
"in",
"range",
"("... | Calculate p_value.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:param NIR: no information rate
:type NIR : float
:return: p_value as float | [
"Calculate",
"p_value",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L215-L236 | train |
sepandhaghighi/pycm | pycm/pycm_overall_func.py | hamming_calc | def hamming_calc(TP, POP):
"""
Calculate hamming loss.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:return: hamming loss as float
"""
try:
length = POP
return (1 / length) * (length - sum(TP.values()))
except Exception:
... | python | def hamming_calc(TP, POP):
"""
Calculate hamming loss.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:return: hamming loss as float
"""
try:
length = POP
return (1 / length) * (length - sum(TP.values()))
except Exception:
... | [
"def",
"hamming_calc",
"(",
"TP",
",",
"POP",
")",
":",
"try",
":",
"length",
"=",
"POP",
"return",
"(",
"1",
"/",
"length",
")",
"*",
"(",
"length",
"-",
"sum",
"(",
"TP",
".",
"values",
"(",
")",
")",
")",
"except",
"Exception",
":",
"return",
... | Calculate hamming loss.
:param TP: true positive
:type TP : dict
:param POP: population
:type POP : int
:return: hamming loss as float | [
"Calculate",
"hamming",
"loss",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L257-L271 | train |
sepandhaghighi/pycm | pycm/pycm_overall_func.py | zero_one_loss_calc | def zero_one_loss_calc(TP, POP):
"""
Calculate zero-one loss.
:param TP: true Positive
:type TP : dict
:param POP: population
:type POP : int
:return: zero_one loss as integer
"""
try:
length = POP
return (length - sum(TP.values()))
except Exception:
retu... | python | def zero_one_loss_calc(TP, POP):
"""
Calculate zero-one loss.
:param TP: true Positive
:type TP : dict
:param POP: population
:type POP : int
:return: zero_one loss as integer
"""
try:
length = POP
return (length - sum(TP.values()))
except Exception:
retu... | [
"def",
"zero_one_loss_calc",
"(",
"TP",
",",
"POP",
")",
":",
"try",
":",
"length",
"=",
"POP",
"return",
"(",
"length",
"-",
"sum",
"(",
"TP",
".",
"values",
"(",
")",
")",
")",
"except",
"Exception",
":",
"return",
"\"None\""
] | Calculate zero-one loss.
:param TP: true Positive
:type TP : dict
:param POP: population
:type POP : int
:return: zero_one loss as integer | [
"Calculate",
"zero",
"-",
"one",
"loss",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L274-L288 | train |
sepandhaghighi/pycm | pycm/pycm_overall_func.py | entropy_calc | def entropy_calc(item, POP):
"""
Calculate reference and response likelihood.
:param item : TOP or P
:type item : dict
:param POP: population
:type POP : dict
:return: reference or response likelihood as float
"""
try:
result = 0
for i in item.keys():
lik... | python | def entropy_calc(item, POP):
"""
Calculate reference and response likelihood.
:param item : TOP or P
:type item : dict
:param POP: population
:type POP : dict
:return: reference or response likelihood as float
"""
try:
result = 0
for i in item.keys():
lik... | [
"def",
"entropy_calc",
"(",
"item",
",",
"POP",
")",
":",
"try",
":",
"result",
"=",
"0",
"for",
"i",
"in",
"item",
".",
"keys",
"(",
")",
":",
"likelihood",
"=",
"item",
"[",
"i",
"]",
"/",
"POP",
"[",
"i",
"]",
"if",
"likelihood",
"!=",
"0",
... | Calculate reference and response likelihood.
:param item : TOP or P
:type item : dict
:param POP: population
:type POP : dict
:return: reference or response likelihood as float | [
"Calculate",
"reference",
"and",
"response",
"likelihood",
"."
] | cb03258afd6a821d10acba73c965aaac174bedcd | https://github.com/sepandhaghighi/pycm/blob/cb03258afd6a821d10acba73c965aaac174bedcd/pycm/pycm_overall_func.py#L291-L309 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.