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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
dailymotion/tartiflette-aiohttp | tartiflette_aiohttp/__init__.py | register_graphql_handlers | def register_graphql_handlers(
app: "Application",
engine_sdl: str = None,
engine_schema_name: str = "default",
executor_context: dict = None,
executor_http_endpoint: str = "/graphql",
executor_http_methods: List[str] = None,
engine: Engine = None,
subscription_ws_endpoint: Optional[str]... | python | def register_graphql_handlers(
app: "Application",
engine_sdl: str = None,
engine_schema_name: str = "default",
executor_context: dict = None,
executor_http_endpoint: str = "/graphql",
executor_http_methods: List[str] = None,
engine: Engine = None,
subscription_ws_endpoint: Optional[str]... | [
"def",
"register_graphql_handlers",
"(",
"app",
":",
"\"Application\"",
",",
"engine_sdl",
":",
"str",
"=",
"None",
",",
"engine_schema_name",
":",
"str",
"=",
"\"default\"",
",",
"executor_context",
":",
"dict",
"=",
"None",
",",
"executor_http_endpoint",
":",
... | Register a Tartiflette Engine to an app
Pass a SDL or an already initialized Engine, not both, not neither.
Keyword Arguments:
app {aiohttp.web.Application} -- The application to register to.
engine_sdl {str} -- The SDL defining your API (default: {None})
engine_schema_name {str} -- Th... | [
"Register",
"a",
"Tartiflette",
"Engine",
"to",
"an",
"app"
] | a87e6aa7d1f18b2d700eeb799228745848c88088 | https://github.com/dailymotion/tartiflette-aiohttp/blob/a87e6aa7d1f18b2d700eeb799228745848c88088/tartiflette_aiohttp/__init__.py#L92-L170 | train |
dailymotion/tartiflette-aiohttp | examples/aiohttp/starwars/app.py | on_shutdown | async def on_shutdown(app):
"""app SHUTDOWN event handler
"""
for method in app.get("close_methods", []):
logger.debug("Calling < %s >", method)
if asyncio.iscoroutinefunction(method):
await method()
else:
method() | python | async def on_shutdown(app):
"""app SHUTDOWN event handler
"""
for method in app.get("close_methods", []):
logger.debug("Calling < %s >", method)
if asyncio.iscoroutinefunction(method):
await method()
else:
method() | [
"async",
"def",
"on_shutdown",
"(",
"app",
")",
":",
"for",
"method",
"in",
"app",
".",
"get",
"(",
"\"close_methods\"",
",",
"[",
"]",
")",
":",
"logger",
".",
"debug",
"(",
"\"Calling < %s >\"",
",",
"method",
")",
"if",
"asyncio",
".",
"iscoroutinefun... | app SHUTDOWN event handler | [
"app",
"SHUTDOWN",
"event",
"handler"
] | a87e6aa7d1f18b2d700eeb799228745848c88088 | https://github.com/dailymotion/tartiflette-aiohttp/blob/a87e6aa7d1f18b2d700eeb799228745848c88088/examples/aiohttp/starwars/app.py#L20-L28 | train |
davidmogar/cucco | cucco/config.py | Config._load_from_file | def _load_from_file(path):
"""Load a config file from the given path.
Load all normalizations from the config file received as
argument. It expects to find a YAML file with a list of
normalizations and arguments under the key 'normalizations'.
Args:
path: Path to YA... | python | def _load_from_file(path):
"""Load a config file from the given path.
Load all normalizations from the config file received as
argument. It expects to find a YAML file with a list of
normalizations and arguments under the key 'normalizations'.
Args:
path: Path to YA... | [
"def",
"_load_from_file",
"(",
"path",
")",
":",
"config",
"=",
"[",
"]",
"try",
":",
"with",
"open",
"(",
"path",
",",
"'r'",
")",
"as",
"config_file",
":",
"config",
"=",
"yaml",
".",
"load",
"(",
"config_file",
")",
"[",
"'normalizations'",
"]",
"... | Load a config file from the given path.
Load all normalizations from the config file received as
argument. It expects to find a YAML file with a list of
normalizations and arguments under the key 'normalizations'.
Args:
path: Path to YAML file. | [
"Load",
"a",
"config",
"file",
"from",
"the",
"given",
"path",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/config.py#L53-L76 | train |
davidmogar/cucco | cucco/config.py | Config._parse_normalization | def _parse_normalization(normalization):
"""Parse a normalization item.
Transform dicts into a tuple containing the normalization
options. If a string is found, the actual value is used.
Args:
normalization: Normalization to parse.
Returns:
Tuple or str... | python | def _parse_normalization(normalization):
"""Parse a normalization item.
Transform dicts into a tuple containing the normalization
options. If a string is found, the actual value is used.
Args:
normalization: Normalization to parse.
Returns:
Tuple or str... | [
"def",
"_parse_normalization",
"(",
"normalization",
")",
":",
"parsed_normalization",
"=",
"None",
"if",
"isinstance",
"(",
"normalization",
",",
"dict",
")",
":",
"if",
"len",
"(",
"normalization",
".",
"keys",
"(",
")",
")",
"==",
"1",
":",
"items",
"="... | Parse a normalization item.
Transform dicts into a tuple containing the normalization
options. If a string is found, the actual value is used.
Args:
normalization: Normalization to parse.
Returns:
Tuple or string containing the parsed normalization. | [
"Parse",
"a",
"normalization",
"item",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/config.py#L79-L105 | train |
davidmogar/cucco | cucco/config.py | Config._parse_normalizations | def _parse_normalizations(self, normalizations):
"""Returns a list of parsed normalizations.
Iterates over a list of normalizations, removing those
not correctly defined. It also transform complex items
to have a common format (list of tuples and strings).
Args:
nor... | python | def _parse_normalizations(self, normalizations):
"""Returns a list of parsed normalizations.
Iterates over a list of normalizations, removing those
not correctly defined. It also transform complex items
to have a common format (list of tuples and strings).
Args:
nor... | [
"def",
"_parse_normalizations",
"(",
"self",
",",
"normalizations",
")",
":",
"parsed_normalizations",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"normalizations",
",",
"list",
")",
":",
"for",
"item",
"in",
"normalizations",
":",
"normalization",
"=",
"self",
".... | Returns a list of parsed normalizations.
Iterates over a list of normalizations, removing those
not correctly defined. It also transform complex items
to have a common format (list of tuples and strings).
Args:
normalizations: List of normalizations to parse.
Retur... | [
"Returns",
"a",
"list",
"of",
"parsed",
"normalizations",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/config.py#L107-L130 | train |
davidmogar/cucco | cucco/logging.py | initialize_logger | def initialize_logger(debug):
"""Set up logger to be used by the library.
Args:
debug: Wheter to use debug level or not.
Returns:
A logger ready to be used.
"""
level = logging.DEBUG if debug else logging.INFO
logger = logging.getLogger('cucco')
logger.setLevel(level)
f... | python | def initialize_logger(debug):
"""Set up logger to be used by the library.
Args:
debug: Wheter to use debug level or not.
Returns:
A logger ready to be used.
"""
level = logging.DEBUG if debug else logging.INFO
logger = logging.getLogger('cucco')
logger.setLevel(level)
f... | [
"def",
"initialize_logger",
"(",
"debug",
")",
":",
"level",
"=",
"logging",
".",
"DEBUG",
"if",
"debug",
"else",
"logging",
".",
"INFO",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"'cucco'",
")",
"logger",
".",
"setLevel",
"(",
"level",
")",
"form... | Set up logger to be used by the library.
Args:
debug: Wheter to use debug level or not.
Returns:
A logger ready to be used. | [
"Set",
"up",
"logger",
"to",
"be",
"used",
"by",
"the",
"library",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/logging.py#L5-L23 | train |
davidmogar/cucco | cucco/cli.py | batch | def batch(ctx, path, recursive, watch):
"""
Normalize files in a path.
Apply normalizations over all files found in a given path.
The normalizations applied will be those defined in the config
file. If no config is specified, the default normalizations will
be used.
"""
batch = Batch(ct... | python | def batch(ctx, path, recursive, watch):
"""
Normalize files in a path.
Apply normalizations over all files found in a given path.
The normalizations applied will be those defined in the config
file. If no config is specified, the default normalizations will
be used.
"""
batch = Batch(ct... | [
"def",
"batch",
"(",
"ctx",
",",
"path",
",",
"recursive",
",",
"watch",
")",
":",
"batch",
"=",
"Batch",
"(",
"ctx",
".",
"obj",
"[",
"'config'",
"]",
",",
"ctx",
".",
"obj",
"[",
"'cucco'",
"]",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(... | Normalize files in a path.
Apply normalizations over all files found in a given path.
The normalizations applied will be those defined in the config
file. If no config is specified, the default normalizations will
be used. | [
"Normalize",
"files",
"in",
"a",
"path",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/cli.py#L23-L43 | train |
davidmogar/cucco | cucco/cli.py | normalize | def normalize(ctx, text):
"""
Normalize text or piped input.
Normalize text passed as an argument to this command using
the specified config (default values if --config option is
not used).
Pipes can be used along this command to process the output
of another cli. This is the default behav... | python | def normalize(ctx, text):
"""
Normalize text or piped input.
Normalize text passed as an argument to this command using
the specified config (default values if --config option is
not used).
Pipes can be used along this command to process the output
of another cli. This is the default behav... | [
"def",
"normalize",
"(",
"ctx",
",",
"text",
")",
":",
"if",
"text",
":",
"click",
".",
"echo",
"(",
"ctx",
".",
"obj",
"[",
"'cucco'",
"]",
".",
"normalize",
"(",
"text",
")",
")",
"else",
":",
"for",
"line",
"in",
"sys",
".",
"stdin",
":",
"c... | Normalize text or piped input.
Normalize text passed as an argument to this command using
the specified config (default values if --config option is
not used).
Pipes can be used along this command to process the output
of another cli. This is the default behaviour when no text
is defined. | [
"Normalize",
"text",
"or",
"piped",
"input",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/cli.py#L48-L64 | train |
davidmogar/cucco | cucco/cli.py | cli | def cli(ctx, config, debug, language, verbose):
"""
Cucco allows to apply normalizations to a given text or file.
This normalizations include, among others, removal of accent
marks, stop words an extra white spaces, replacement of
punctuation symbols, emails, emojis, etc.
For more info on how t... | python | def cli(ctx, config, debug, language, verbose):
"""
Cucco allows to apply normalizations to a given text or file.
This normalizations include, among others, removal of accent
marks, stop words an extra white spaces, replacement of
punctuation symbols, emails, emojis, etc.
For more info on how t... | [
"def",
"cli",
"(",
"ctx",
",",
"config",
",",
"debug",
",",
"language",
",",
"verbose",
")",
":",
"ctx",
".",
"obj",
"=",
"{",
"}",
"try",
":",
"ctx",
".",
"obj",
"[",
"'config'",
"]",
"=",
"Config",
"(",
"normalizations",
"=",
"config",
",",
"la... | Cucco allows to apply normalizations to a given text or file.
This normalizations include, among others, removal of accent
marks, stop words an extra white spaces, replacement of
punctuation symbols, emails, emojis, etc.
For more info on how to use and configure Cucco, check the
project website at ... | [
"Cucco",
"allows",
"to",
"apply",
"normalizations",
"to",
"a",
"given",
"text",
"or",
"file",
".",
"This",
"normalizations",
"include",
"among",
"others",
"removal",
"of",
"accent",
"marks",
"stop",
"words",
"an",
"extra",
"white",
"spaces",
"replacement",
"of... | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/cli.py#L77-L98 | train |
davidmogar/cucco | cucco/batch.py | files_generator | def files_generator(path, recursive):
"""Yield files found in a given path.
Walk over a given path finding and yielding all
files found on it. This can be done only on the root
directory or recursively.
Args:
path: Path to the directory.
recursive: Whether to find files recursively... | python | def files_generator(path, recursive):
"""Yield files found in a given path.
Walk over a given path finding and yielding all
files found on it. This can be done only on the root
directory or recursively.
Args:
path: Path to the directory.
recursive: Whether to find files recursively... | [
"def",
"files_generator",
"(",
"path",
",",
"recursive",
")",
":",
"if",
"recursive",
":",
"for",
"(",
"path",
",",
"_",
",",
"files",
")",
"in",
"os",
".",
"walk",
"(",
"path",
")",
":",
"for",
"file",
"in",
"files",
":",
"if",
"not",
"file",
".... | Yield files found in a given path.
Walk over a given path finding and yielding all
files found on it. This can be done only on the root
directory or recursively.
Args:
path: Path to the directory.
recursive: Whether to find files recursively or not.
Yields:
A tuple for eac... | [
"Yield",
"files",
"found",
"in",
"a",
"given",
"path",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/batch.py#L11-L35 | train |
davidmogar/cucco | cucco/batch.py | Batch.process_file | def process_file(self, path):
"""Process a file applying normalizations.
Get a file as input and generate a new file with the
result of applying normalizations to every single line
in the original file. The extension for the new file
will be the one defined in BATCH_EXTENSION.
... | python | def process_file(self, path):
"""Process a file applying normalizations.
Get a file as input and generate a new file with the
result of applying normalizations to every single line
in the original file. The extension for the new file
will be the one defined in BATCH_EXTENSION.
... | [
"def",
"process_file",
"(",
"self",
",",
"path",
")",
":",
"if",
"self",
".",
"_config",
".",
"verbose",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Processing file \"%s\"'",
",",
"path",
")",
"output_path",
"=",
"'%s%s'",
"%",
"(",
"path",
",",
"... | Process a file applying normalizations.
Get a file as input and generate a new file with the
result of applying normalizations to every single line
in the original file. The extension for the new file
will be the one defined in BATCH_EXTENSION.
Args:
path: Path to t... | [
"Process",
"a",
"file",
"applying",
"normalizations",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/batch.py#L76-L97 | train |
davidmogar/cucco | cucco/batch.py | Batch.process_files | def process_files(self, path, recursive=False):
"""Apply normalizations over all files in the given directory.
Iterate over all files in a given directory. Normalizations
will be applied to each file, storing the result in a new file.
The extension for the new file will be the one defin... | python | def process_files(self, path, recursive=False):
"""Apply normalizations over all files in the given directory.
Iterate over all files in a given directory. Normalizations
will be applied to each file, storing the result in a new file.
The extension for the new file will be the one defin... | [
"def",
"process_files",
"(",
"self",
",",
"path",
",",
"recursive",
"=",
"False",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Processing files in \"%s\"'",
",",
"path",
")",
"for",
"(",
"path",
",",
"file",
")",
"in",
"files_generator",
"(",
"p... | Apply normalizations over all files in the given directory.
Iterate over all files in a given directory. Normalizations
will be applied to each file, storing the result in a new file.
The extension for the new file will be the one defined in
BATCH_EXTENSION.
Args:
p... | [
"Apply",
"normalizations",
"over",
"all",
"files",
"in",
"the",
"given",
"directory",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/batch.py#L99-L115 | train |
davidmogar/cucco | cucco/batch.py | Batch.stop_watching | def stop_watching(self):
"""Stop watching for files.
Stop the observer started by watch function and finish
thread life.
"""
self._watch = False
if self._observer:
self._logger.info('Stopping watcher')
self._observer.stop()
self._logg... | python | def stop_watching(self):
"""Stop watching for files.
Stop the observer started by watch function and finish
thread life.
"""
self._watch = False
if self._observer:
self._logger.info('Stopping watcher')
self._observer.stop()
self._logg... | [
"def",
"stop_watching",
"(",
"self",
")",
":",
"self",
".",
"_watch",
"=",
"False",
"if",
"self",
".",
"_observer",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Stopping watcher'",
")",
"self",
".",
"_observer",
".",
"stop",
"(",
")",
"self",
".",
... | Stop watching for files.
Stop the observer started by watch function and finish
thread life. | [
"Stop",
"watching",
"for",
"files",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/batch.py#L117-L128 | train |
davidmogar/cucco | cucco/batch.py | Batch.watch | def watch(self, path, recursive=False):
"""Watch for files in a directory and apply normalizations.
Watch for new or changed files in a directory and apply
normalizations over them.
Args:
path: Path to the directory.
recursive: Whether to find files recursively ... | python | def watch(self, path, recursive=False):
"""Watch for files in a directory and apply normalizations.
Watch for new or changed files in a directory and apply
normalizations over them.
Args:
path: Path to the directory.
recursive: Whether to find files recursively ... | [
"def",
"watch",
"(",
"self",
",",
"path",
",",
"recursive",
"=",
"False",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'Initializing watcher for path \"%s\"'",
",",
"path",
")",
"handler",
"=",
"FileHandler",
"(",
"self",
")",
"self",
".",
"_observ... | Watch for files in a directory and apply normalizations.
Watch for new or changed files in a directory and apply
normalizations over them.
Args:
path: Path to the directory.
recursive: Whether to find files recursively or not. | [
"Watch",
"for",
"files",
"in",
"a",
"directory",
"and",
"apply",
"normalizations",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/batch.py#L130-L157 | train |
davidmogar/cucco | cucco/batch.py | FileHandler._process_event | def _process_event(self, event):
"""Process received events.
Process events received, applying normalization for those
events referencing a new or changed file and only if it's
not the result of a previous normalization.
Args:
event: Event to process.
"""
... | python | def _process_event(self, event):
"""Process received events.
Process events received, applying normalization for those
events referencing a new or changed file and only if it's
not the result of a previous normalization.
Args:
event: Event to process.
"""
... | [
"def",
"_process_event",
"(",
"self",
",",
"event",
")",
":",
"if",
"(",
"not",
"event",
".",
"is_directory",
"and",
"not",
"event",
".",
"src_path",
".",
"endswith",
"(",
"BATCH_EXTENSION",
")",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"'De... | Process received events.
Process events received, applying normalization for those
events referencing a new or changed file and only if it's
not the result of a previous normalization.
Args:
event: Event to process. | [
"Process",
"received",
"events",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/batch.py#L175-L188 | train |
davidmogar/cucco | cucco/batch.py | FileHandler.on_created | def on_created(self, event):
"""Function called everytime a new file is created.
Args:
event: Event to process.
"""
self._logger.debug('Detected create event on watched path: %s', event.src_path)
self._process_event(event) | python | def on_created(self, event):
"""Function called everytime a new file is created.
Args:
event: Event to process.
"""
self._logger.debug('Detected create event on watched path: %s', event.src_path)
self._process_event(event) | [
"def",
"on_created",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"'Detected create event on watched path: %s'",
",",
"event",
".",
"src_path",
")",
"self",
".",
"_process_event",
"(",
"event",
")"
] | Function called everytime a new file is created.
Args:
event: Event to process. | [
"Function",
"called",
"everytime",
"a",
"new",
"file",
"is",
"created",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/batch.py#L190-L198 | train |
davidmogar/cucco | cucco/batch.py | FileHandler.on_modified | def on_modified(self, event):
"""Function called everytime a new file is modified.
Args:
event: Event to process.
"""
self._logger.debug('Detected modify event on watched path: %s', event.src_path)
self._process_event(event) | python | def on_modified(self, event):
"""Function called everytime a new file is modified.
Args:
event: Event to process.
"""
self._logger.debug('Detected modify event on watched path: %s', event.src_path)
self._process_event(event) | [
"def",
"on_modified",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"'Detected modify event on watched path: %s'",
",",
"event",
".",
"src_path",
")",
"self",
".",
"_process_event",
"(",
"event",
")"
] | Function called everytime a new file is modified.
Args:
event: Event to process. | [
"Function",
"called",
"everytime",
"a",
"new",
"file",
"is",
"modified",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/batch.py#L200-L208 | train |
davidmogar/cucco | cucco/cucco.py | Cucco._parse_normalizations | def _parse_normalizations(normalizations):
"""Parse and yield normalizations.
Parse normalizations parameter that yield all normalizations and
arguments found on it.
Args:
normalizations: List of normalizations.
Yields:
A tuple with a parsed normalizati... | python | def _parse_normalizations(normalizations):
"""Parse and yield normalizations.
Parse normalizations parameter that yield all normalizations and
arguments found on it.
Args:
normalizations: List of normalizations.
Yields:
A tuple with a parsed normalizati... | [
"def",
"_parse_normalizations",
"(",
"normalizations",
")",
":",
"str_type",
"=",
"str",
"if",
"sys",
".",
"version_info",
"[",
"0",
"]",
">",
"2",
"else",
"(",
"str",
",",
"unicode",
")",
"for",
"normalization",
"in",
"normalizations",
":",
"yield",
"(",
... | Parse and yield normalizations.
Parse normalizations parameter that yield all normalizations and
arguments found on it.
Args:
normalizations: List of normalizations.
Yields:
A tuple with a parsed normalization. The first item will
contain the normal... | [
"Parse",
"and",
"yield",
"normalizations",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/cucco.py#L65-L82 | train |
davidmogar/cucco | cucco/cucco.py | Cucco._parse_stop_words_file | def _parse_stop_words_file(self, path):
"""Load stop words from the given path.
Parse the stop words file, saving each word found in it in a set
for the language of the file. This language is obtained from
the file name. If the file doesn't exist, the method will have
no effect.... | python | def _parse_stop_words_file(self, path):
"""Load stop words from the given path.
Parse the stop words file, saving each word found in it in a set
for the language of the file. This language is obtained from
the file name. If the file doesn't exist, the method will have
no effect.... | [
"def",
"_parse_stop_words_file",
"(",
"self",
",",
"path",
")",
":",
"language",
"=",
"None",
"loaded",
"=",
"False",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"path",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"'Loading stop words in %s'",
... | Load stop words from the given path.
Parse the stop words file, saving each word found in it in a set
for the language of the file. This language is obtained from
the file name. If the file doesn't exist, the method will have
no effect.
Args:
path: Path to the stop ... | [
"Load",
"stop",
"words",
"from",
"the",
"given",
"path",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/cucco.py#L84-L114 | train |
davidmogar/cucco | cucco/cucco.py | Cucco.normalize | def normalize(self, text, normalizations=None):
"""Normalize a given text applying all normalizations.
Normalizations to apply can be specified through a list of
parameters and will be executed in that order.
Args:
text: The text to be processed.
normalizations:... | python | def normalize(self, text, normalizations=None):
"""Normalize a given text applying all normalizations.
Normalizations to apply can be specified through a list of
parameters and will be executed in that order.
Args:
text: The text to be processed.
normalizations:... | [
"def",
"normalize",
"(",
"self",
",",
"text",
",",
"normalizations",
"=",
"None",
")",
":",
"for",
"normalization",
",",
"kwargs",
"in",
"self",
".",
"_parse_normalizations",
"(",
"normalizations",
"or",
"self",
".",
"_config",
".",
"normalizations",
")",
":... | Normalize a given text applying all normalizations.
Normalizations to apply can be specified through a list of
parameters and will be executed in that order.
Args:
text: The text to be processed.
normalizations: List of normalizations to apply.
Returns:
... | [
"Normalize",
"a",
"given",
"text",
"applying",
"all",
"normalizations",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/cucco.py#L116-L137 | train |
davidmogar/cucco | cucco/cucco.py | Cucco.remove_accent_marks | def remove_accent_marks(text, excluded=None):
"""Remove accent marks from input text.
This function removes accent marks in the text, but leaves
unicode characters defined in the 'excluded' parameter.
Args:
text: The text to be processed.
excluded: Set of unicod... | python | def remove_accent_marks(text, excluded=None):
"""Remove accent marks from input text.
This function removes accent marks in the text, but leaves
unicode characters defined in the 'excluded' parameter.
Args:
text: The text to be processed.
excluded: Set of unicod... | [
"def",
"remove_accent_marks",
"(",
"text",
",",
"excluded",
"=",
"None",
")",
":",
"if",
"excluded",
"is",
"None",
":",
"excluded",
"=",
"set",
"(",
")",
"return",
"unicodedata",
".",
"normalize",
"(",
"'NFKC'",
",",
"''",
".",
"join",
"(",
"c",
"for",... | Remove accent marks from input text.
This function removes accent marks in the text, but leaves
unicode characters defined in the 'excluded' parameter.
Args:
text: The text to be processed.
excluded: Set of unicode characters to exclude.
Returns:
Th... | [
"Remove",
"accent",
"marks",
"from",
"input",
"text",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/cucco.py#L140-L159 | train |
davidmogar/cucco | cucco/cucco.py | Cucco.replace_characters | def replace_characters(self, text, characters, replacement=''):
"""Remove characters from text.
Removes custom characters from input text or replaces them
with a string if specified.
Args:
text: The text to be processed.
characters: Characters that will be repla... | python | def replace_characters(self, text, characters, replacement=''):
"""Remove characters from text.
Removes custom characters from input text or replaces them
with a string if specified.
Args:
text: The text to be processed.
characters: Characters that will be repla... | [
"def",
"replace_characters",
"(",
"self",
",",
"text",
",",
"characters",
",",
"replacement",
"=",
"''",
")",
":",
"if",
"not",
"characters",
":",
"return",
"text",
"characters",
"=",
"''",
".",
"join",
"(",
"sorted",
"(",
"characters",
")",
")",
"if",
... | Remove characters from text.
Removes custom characters from input text or replaces them
with a string if specified.
Args:
text: The text to be processed.
characters: Characters that will be replaced.
replacement: New text that will replace the custom charact... | [
"Remove",
"characters",
"from",
"text",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/cucco.py#L202-L226 | train |
davidmogar/cucco | cucco/cucco.py | Cucco.replace_punctuation | def replace_punctuation(self, text, excluded=None, replacement=''):
"""Replace punctuation symbols in text.
Removes punctuation from input text or replaces them with a
string if specified. Characters replaced will be those
in string.punctuation.
Args:
text: The text... | python | def replace_punctuation(self, text, excluded=None, replacement=''):
"""Replace punctuation symbols in text.
Removes punctuation from input text or replaces them with a
string if specified. Characters replaced will be those
in string.punctuation.
Args:
text: The text... | [
"def",
"replace_punctuation",
"(",
"self",
",",
"text",
",",
"excluded",
"=",
"None",
",",
"replacement",
"=",
"''",
")",
":",
"if",
"excluded",
"is",
"None",
":",
"excluded",
"=",
"set",
"(",
")",
"elif",
"not",
"isinstance",
"(",
"excluded",
",",
"se... | Replace punctuation symbols in text.
Removes punctuation from input text or replaces them with a
string if specified. Characters replaced will be those
in string.punctuation.
Args:
text: The text to be processed.
excluded: Set of characters to exclude.
... | [
"Replace",
"punctuation",
"symbols",
"in",
"text",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/cucco.py#L276-L298 | train |
davidmogar/cucco | cucco/cucco.py | Cucco.replace_symbols | def replace_symbols(
text,
form='NFKD',
excluded=None,
replacement=''):
"""Replace symbols in text.
Removes symbols from input text or replaces them with a
string if specified.
Args:
text: The text to be processed.
... | python | def replace_symbols(
text,
form='NFKD',
excluded=None,
replacement=''):
"""Replace symbols in text.
Removes symbols from input text or replaces them with a
string if specified.
Args:
text: The text to be processed.
... | [
"def",
"replace_symbols",
"(",
"text",
",",
"form",
"=",
"'NFKD'",
",",
"excluded",
"=",
"None",
",",
"replacement",
"=",
"''",
")",
":",
"if",
"excluded",
"is",
"None",
":",
"excluded",
"=",
"set",
"(",
")",
"categories",
"=",
"set",
"(",
"[",
"'Mn'... | Replace symbols in text.
Removes symbols from input text or replaces them with a
string if specified.
Args:
text: The text to be processed.
form: Unicode form.
excluded: Set of unicode characters to exclude.
replacement: New text that will replac... | [
"Replace",
"symbols",
"in",
"text",
"."
] | e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4 | https://github.com/davidmogar/cucco/blob/e2a0ff3342e4a9f25a65c486206a5a2ae1a4dbd4/cucco/cucco.py#L301-L326 | train |
tmr232/Sark | sark/graph.py | get_idb_graph | def get_idb_graph():
"""Export IDB to a NetworkX graph.
Use xrefs to and from functions to build a DiGraph containing all
the functions in the IDB and all the links between them.
The graph can later be used to perform analysis on the IDB.
:return: nx.DiGraph()
"""
digraph = nx.DiGraph()
... | python | def get_idb_graph():
"""Export IDB to a NetworkX graph.
Use xrefs to and from functions to build a DiGraph containing all
the functions in the IDB and all the links between them.
The graph can later be used to perform analysis on the IDB.
:return: nx.DiGraph()
"""
digraph = nx.DiGraph()
... | [
"def",
"get_idb_graph",
"(",
")",
":",
"digraph",
"=",
"nx",
".",
"DiGraph",
"(",
")",
"for",
"function",
"in",
"functions",
"(",
")",
":",
"for",
"xref",
"in",
"itertools",
".",
"chain",
"(",
"function",
".",
"xrefs_from",
",",
"function",
".",
"xrefs... | Export IDB to a NetworkX graph.
Use xrefs to and from functions to build a DiGraph containing all
the functions in the IDB and all the links between them.
The graph can later be used to perform analysis on the IDB.
:return: nx.DiGraph() | [
"Export",
"IDB",
"to",
"a",
"NetworkX",
"graph",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/graph.py#L48-L66 | train |
tmr232/Sark | sark/code/instruction.py | OperandType.name | def name(self):
"""Name of the xref type."""
return self.TYPES.get(self._type, self.TYPES[idaapi.o_idpspec0]) | python | def name(self):
"""Name of the xref type."""
return self.TYPES.get(self._type, self.TYPES[idaapi.o_idpspec0]) | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"TYPES",
".",
"get",
"(",
"self",
".",
"_type",
",",
"self",
".",
"TYPES",
"[",
"idaapi",
".",
"o_idpspec0",
"]",
")"
] | Name of the xref type. | [
"Name",
"of",
"the",
"xref",
"type",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/instruction.py#L138-L140 | train |
tmr232/Sark | sark/code/instruction.py | Operand.reg | def reg(self):
"""Name of the register used in the operand."""
if self.type.is_displ or self.type.is_phrase:
size = core.get_native_size()
return base.get_register_name(self.reg_id, size)
if self.type.is_reg:
return base.get_register_name(self.reg_id, self.si... | python | def reg(self):
"""Name of the register used in the operand."""
if self.type.is_displ or self.type.is_phrase:
size = core.get_native_size()
return base.get_register_name(self.reg_id, size)
if self.type.is_reg:
return base.get_register_name(self.reg_id, self.si... | [
"def",
"reg",
"(",
"self",
")",
":",
"if",
"self",
".",
"type",
".",
"is_displ",
"or",
"self",
".",
"type",
".",
"is_phrase",
":",
"size",
"=",
"core",
".",
"get_native_size",
"(",
")",
"return",
"base",
".",
"get_register_name",
"(",
"self",
".",
"r... | Name of the register used in the operand. | [
"Name",
"of",
"the",
"register",
"used",
"in",
"the",
"operand",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/instruction.py#L270-L280 | train |
tmr232/Sark | sark/code/instruction.py | Instruction.has_reg | def has_reg(self, reg_name):
"""Check if a register is used in the instruction."""
return any(operand.has_reg(reg_name) for operand in self.operands) | python | def has_reg(self, reg_name):
"""Check if a register is used in the instruction."""
return any(operand.has_reg(reg_name) for operand in self.operands) | [
"def",
"has_reg",
"(",
"self",
",",
"reg_name",
")",
":",
"return",
"any",
"(",
"operand",
".",
"has_reg",
"(",
"reg_name",
")",
"for",
"operand",
"in",
"self",
".",
"operands",
")"
] | Check if a register is used in the instruction. | [
"Check",
"if",
"a",
"register",
"is",
"used",
"in",
"the",
"instruction",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/instruction.py#L384-L386 | train |
tmr232/Sark | sark/code/instruction.py | Instruction.regs | def regs(self):
"""Names of all registers used by the instruction."""
regs = set()
for operand in self.operands:
if not operand.type.has_reg:
continue
regs.update(operand.regs)
return regs | python | def regs(self):
"""Names of all registers used by the instruction."""
regs = set()
for operand in self.operands:
if not operand.type.has_reg:
continue
regs.update(operand.regs)
return regs | [
"def",
"regs",
"(",
"self",
")",
":",
"regs",
"=",
"set",
"(",
")",
"for",
"operand",
"in",
"self",
".",
"operands",
":",
"if",
"not",
"operand",
".",
"type",
".",
"has_reg",
":",
"continue",
"regs",
".",
"update",
"(",
"operand",
".",
"regs",
")",... | Names of all registers used by the instruction. | [
"Names",
"of",
"all",
"registers",
"used",
"by",
"the",
"instruction",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/instruction.py#L397-L404 | train |
tmr232/Sark | sark/ui.py | NXGraph._pad | def _pad(self, text):
"""Pad the text."""
top_bottom = ("\n" * self._padding) + " "
right_left = " " * self._padding * self.PAD_WIDTH
return top_bottom + right_left + text + right_left + top_bottom | python | def _pad(self, text):
"""Pad the text."""
top_bottom = ("\n" * self._padding) + " "
right_left = " " * self._padding * self.PAD_WIDTH
return top_bottom + right_left + text + right_left + top_bottom | [
"def",
"_pad",
"(",
"self",
",",
"text",
")",
":",
"top_bottom",
"=",
"(",
"\"\\n\"",
"*",
"self",
".",
"_padding",
")",
"+",
"\" \"",
"right_left",
"=",
"\" \"",
"*",
"self",
".",
"_padding",
"*",
"self",
".",
"PAD_WIDTH",
"return",
"top_bottom",
"+",... | Pad the text. | [
"Pad",
"the",
"text",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/ui.py#L234-L238 | train |
tmr232/Sark | sark/ui.py | NXGraph._make_unique_title | def _make_unique_title(self, title):
"""Make the title unique.
Adds a counter to the title to prevent duplicates.
Prior to IDA 6.8, two graphs with the same title could crash IDA.
This has been fixed (https://www.hex-rays.com/products/ida/6.8/index.shtml).
The code will not cha... | python | def _make_unique_title(self, title):
"""Make the title unique.
Adds a counter to the title to prevent duplicates.
Prior to IDA 6.8, two graphs with the same title could crash IDA.
This has been fixed (https://www.hex-rays.com/products/ida/6.8/index.shtml).
The code will not cha... | [
"def",
"_make_unique_title",
"(",
"self",
",",
"title",
")",
":",
"unique_title",
"=",
"title",
"for",
"counter",
"in",
"itertools",
".",
"count",
"(",
")",
":",
"unique_title",
"=",
"\"{}-{}\"",
".",
"format",
"(",
"title",
",",
"counter",
")",
"if",
"n... | Make the title unique.
Adds a counter to the title to prevent duplicates.
Prior to IDA 6.8, two graphs with the same title could crash IDA.
This has been fixed (https://www.hex-rays.com/products/ida/6.8/index.shtml).
The code will not change for support of older versions and as it is
... | [
"Make",
"the",
"title",
"unique",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/ui.py#L240-L257 | train |
tmr232/Sark | sark/ui.py | NXGraph._get_handler | def _get_handler(self, node_id):
"""Get the handler of a given node."""
handler = self._get_attrs(node_id).get(self.HANDLER, self._default_handler)
# Here we make sure the handler is an instance of `BasicNodeHandler` or inherited
# types. While generally being bad Python practice, we st... | python | def _get_handler(self, node_id):
"""Get the handler of a given node."""
handler = self._get_attrs(node_id).get(self.HANDLER, self._default_handler)
# Here we make sure the handler is an instance of `BasicNodeHandler` or inherited
# types. While generally being bad Python practice, we st... | [
"def",
"_get_handler",
"(",
"self",
",",
"node_id",
")",
":",
"handler",
"=",
"self",
".",
"_get_attrs",
"(",
"node_id",
")",
".",
"get",
"(",
"self",
".",
"HANDLER",
",",
"self",
".",
"_default_handler",
")",
"# Here we make sure the handler is an instance of `... | Get the handler of a given node. | [
"Get",
"the",
"handler",
"of",
"a",
"given",
"node",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/ui.py#L259-L270 | train |
tmr232/Sark | sark/ui.py | NXGraph._OnNodeInfo | def _OnNodeInfo(self, node_id):
"""Sets the node info based on its attributes."""
handler, value, attrs = self._get_handling_triplet(node_id)
frame_color = handler.on_frame_color(value, attrs)
node_info = idaapi.node_info_t()
if frame_color is not None:
node_info.fr... | python | def _OnNodeInfo(self, node_id):
"""Sets the node info based on its attributes."""
handler, value, attrs = self._get_handling_triplet(node_id)
frame_color = handler.on_frame_color(value, attrs)
node_info = idaapi.node_info_t()
if frame_color is not None:
node_info.fr... | [
"def",
"_OnNodeInfo",
"(",
"self",
",",
"node_id",
")",
":",
"handler",
",",
"value",
",",
"attrs",
"=",
"self",
".",
"_get_handling_triplet",
"(",
"node_id",
")",
"frame_color",
"=",
"handler",
".",
"on_frame_color",
"(",
"value",
",",
"attrs",
")",
"node... | Sets the node info based on its attributes. | [
"Sets",
"the",
"node",
"info",
"based",
"on",
"its",
"attributes",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/ui.py#L284-L296 | train |
tmr232/Sark | sark/data.py | get_string | def get_string(ea):
"""Read the string at the given ea.
This function uses IDA's string APIs and does not implement any special logic.
"""
# We get the item-head because the `GetStringType` function only works on the head of an item.
string_type = idc.GetStringType(idaapi.get_item_head(ea))
if... | python | def get_string(ea):
"""Read the string at the given ea.
This function uses IDA's string APIs and does not implement any special logic.
"""
# We get the item-head because the `GetStringType` function only works on the head of an item.
string_type = idc.GetStringType(idaapi.get_item_head(ea))
if... | [
"def",
"get_string",
"(",
"ea",
")",
":",
"# We get the item-head because the `GetStringType` function only works on the head of an item.",
"string_type",
"=",
"idc",
".",
"GetStringType",
"(",
"idaapi",
".",
"get_item_head",
"(",
"ea",
")",
")",
"if",
"string_type",
"is"... | Read the string at the given ea.
This function uses IDA's string APIs and does not implement any special logic. | [
"Read",
"the",
"string",
"at",
"the",
"given",
"ea",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/data.py#L147-L163 | train |
tmr232/Sark | plugins/quick_copy.py | copy_current_file_offset | def copy_current_file_offset():
"""Get the file-offset mapped to the current address."""
start, end = sark.get_selection()
try:
file_offset = sark.core.get_fileregion_offset(start)
clipboard.copy("0x{:08X}".format(file_offset))
except sark.exceptions.NoFileOffset:
message("The ... | python | def copy_current_file_offset():
"""Get the file-offset mapped to the current address."""
start, end = sark.get_selection()
try:
file_offset = sark.core.get_fileregion_offset(start)
clipboard.copy("0x{:08X}".format(file_offset))
except sark.exceptions.NoFileOffset:
message("The ... | [
"def",
"copy_current_file_offset",
"(",
")",
":",
"start",
",",
"end",
"=",
"sark",
".",
"get_selection",
"(",
")",
"try",
":",
"file_offset",
"=",
"sark",
".",
"core",
".",
"get_fileregion_offset",
"(",
"start",
")",
"clipboard",
".",
"copy",
"(",
"\"0x{:... | Get the file-offset mapped to the current address. | [
"Get",
"the",
"file",
"-",
"offset",
"mapped",
"to",
"the",
"current",
"address",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/plugins/quick_copy.py#L17-L26 | train |
tmr232/Sark | sark/core.py | fix_addresses | def fix_addresses(start=None, end=None):
"""Set missing addresses to start and end of IDB.
Take a start and end addresses. If an address is None or `BADADDR`,
return start or end addresses of the IDB instead.
Args
start: Start EA. Use `None` to get IDB start.
end: End EA. Use `None` t... | python | def fix_addresses(start=None, end=None):
"""Set missing addresses to start and end of IDB.
Take a start and end addresses. If an address is None or `BADADDR`,
return start or end addresses of the IDB instead.
Args
start: Start EA. Use `None` to get IDB start.
end: End EA. Use `None` t... | [
"def",
"fix_addresses",
"(",
"start",
"=",
"None",
",",
"end",
"=",
"None",
")",
":",
"if",
"start",
"in",
"(",
"None",
",",
"idaapi",
".",
"BADADDR",
")",
":",
"start",
"=",
"idaapi",
".",
"cvar",
".",
"inf",
".",
"minEA",
"if",
"end",
"in",
"("... | Set missing addresses to start and end of IDB.
Take a start and end addresses. If an address is None or `BADADDR`,
return start or end addresses of the IDB instead.
Args
start: Start EA. Use `None` to get IDB start.
end: End EA. Use `None` to get IDB end.
Returns:
(start, end... | [
"Set",
"missing",
"addresses",
"to",
"start",
"and",
"end",
"of",
"IDB",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/core.py#L81-L100 | train |
tmr232/Sark | sark/core.py | set_name | def set_name(address, name, anyway=False):
"""Set the name of an address.
Sets the name of an address in IDA.
If the name already exists, check the `anyway` parameter:
True - Add `_COUNTER` to the name (default IDA behaviour)
False - Raise an `exceptions.SarkErrorNameAlreadyExists` excepti... | python | def set_name(address, name, anyway=False):
"""Set the name of an address.
Sets the name of an address in IDA.
If the name already exists, check the `anyway` parameter:
True - Add `_COUNTER` to the name (default IDA behaviour)
False - Raise an `exceptions.SarkErrorNameAlreadyExists` excepti... | [
"def",
"set_name",
"(",
"address",
",",
"name",
",",
"anyway",
"=",
"False",
")",
":",
"success",
"=",
"idaapi",
".",
"set_name",
"(",
"address",
",",
"name",
",",
"idaapi",
".",
"SN_NOWARN",
"|",
"idaapi",
".",
"SN_NOCHECK",
")",
"if",
"success",
":",... | Set the name of an address.
Sets the name of an address in IDA.
If the name already exists, check the `anyway` parameter:
True - Add `_COUNTER` to the name (default IDA behaviour)
False - Raise an `exceptions.SarkErrorNameAlreadyExists` exception.
Args
address: The address to ren... | [
"Set",
"the",
"name",
"of",
"an",
"address",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/core.py#L103-L130 | train |
tmr232/Sark | sark/core.py | is_same_function | def is_same_function(ea1, ea2):
"""Are both addresses in the same function?"""
func1 = idaapi.get_func(ea1)
func2 = idaapi.get_func(ea2)
# This is bloated code. `None in (func1, func2)` will not work because of a
# bug in IDAPython in the way functions are compared.
if any(func is None for func ... | python | def is_same_function(ea1, ea2):
"""Are both addresses in the same function?"""
func1 = idaapi.get_func(ea1)
func2 = idaapi.get_func(ea2)
# This is bloated code. `None in (func1, func2)` will not work because of a
# bug in IDAPython in the way functions are compared.
if any(func is None for func ... | [
"def",
"is_same_function",
"(",
"ea1",
",",
"ea2",
")",
":",
"func1",
"=",
"idaapi",
".",
"get_func",
"(",
"ea1",
")",
"func2",
"=",
"idaapi",
".",
"get_func",
"(",
"ea2",
")",
"# This is bloated code. `None in (func1, func2)` will not work because of a",
"# bug in ... | Are both addresses in the same function? | [
"Are",
"both",
"addresses",
"in",
"the",
"same",
"function?"
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/core.py#L133-L142 | train |
tmr232/Sark | sark/codeblock.py | get_nx_graph | def get_nx_graph(ea):
"""Convert an IDA flowchart to a NetworkX graph."""
nx_graph = networkx.DiGraph()
func = idaapi.get_func(ea)
flowchart = FlowChart(func)
for block in flowchart:
# Make sure all nodes are added (including edge-less nodes)
nx_graph.add_node(block.startEA)
... | python | def get_nx_graph(ea):
"""Convert an IDA flowchart to a NetworkX graph."""
nx_graph = networkx.DiGraph()
func = idaapi.get_func(ea)
flowchart = FlowChart(func)
for block in flowchart:
# Make sure all nodes are added (including edge-less nodes)
nx_graph.add_node(block.startEA)
... | [
"def",
"get_nx_graph",
"(",
"ea",
")",
":",
"nx_graph",
"=",
"networkx",
".",
"DiGraph",
"(",
")",
"func",
"=",
"idaapi",
".",
"get_func",
"(",
"ea",
")",
"flowchart",
"=",
"FlowChart",
"(",
"func",
")",
"for",
"block",
"in",
"flowchart",
":",
"# Make ... | Convert an IDA flowchart to a NetworkX graph. | [
"Convert",
"an",
"IDA",
"flowchart",
"to",
"a",
"NetworkX",
"graph",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/codeblock.py#L100-L114 | train |
tmr232/Sark | sark/codeblock.py | codeblocks | def codeblocks(start=None, end=None, full=True):
"""Get all `CodeBlock`s in a given range.
Args:
start - start address of the range. If `None` uses IDB start.
end - end address of the range. If `None` uses IDB end.
full - `True` is required to change node info (e.g. color). `False` caus... | python | def codeblocks(start=None, end=None, full=True):
"""Get all `CodeBlock`s in a given range.
Args:
start - start address of the range. If `None` uses IDB start.
end - end address of the range. If `None` uses IDB end.
full - `True` is required to change node info (e.g. color). `False` caus... | [
"def",
"codeblocks",
"(",
"start",
"=",
"None",
",",
"end",
"=",
"None",
",",
"full",
"=",
"True",
")",
":",
"if",
"full",
":",
"for",
"function",
"in",
"functions",
"(",
"start",
",",
"end",
")",
":",
"fc",
"=",
"FlowChart",
"(",
"f",
"=",
"func... | Get all `CodeBlock`s in a given range.
Args:
start - start address of the range. If `None` uses IDB start.
end - end address of the range. If `None` uses IDB end.
full - `True` is required to change node info (e.g. color). `False` causes faster iteration. | [
"Get",
"all",
"CodeBlock",
"s",
"in",
"a",
"given",
"range",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/codeblock.py#L117-L135 | train |
tmr232/Sark | sark/structure.py | struct_member_error | def struct_member_error(err, sid, name, offset, size):
"""Create and format a struct member exception.
Args:
err: The error value returned from struct member creation
sid: The struct id
name: The member name
offset: Memeber offset
size: Member size
Returns:
... | python | def struct_member_error(err, sid, name, offset, size):
"""Create and format a struct member exception.
Args:
err: The error value returned from struct member creation
sid: The struct id
name: The member name
offset: Memeber offset
size: Member size
Returns:
... | [
"def",
"struct_member_error",
"(",
"err",
",",
"sid",
",",
"name",
",",
"offset",
",",
"size",
")",
":",
"exception",
",",
"msg",
"=",
"STRUCT_ERROR_MAP",
"[",
"err",
"]",
"struct_name",
"=",
"idc",
".",
"GetStrucName",
"(",
"sid",
")",
"return",
"except... | Create and format a struct member exception.
Args:
err: The error value returned from struct member creation
sid: The struct id
name: The member name
offset: Memeber offset
size: Member size
Returns:
A ``SarkErrorAddStructMemeberFailed`` derivative exception, wi... | [
"Create",
"and",
"format",
"a",
"struct",
"member",
"exception",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/structure.py#L33-L56 | train |
tmr232/Sark | sark/structure.py | create_struct | def create_struct(name):
"""Create a structure.
Args:
name: The structure's name
Returns:
The sturct ID
Raises:
exceptions.SarkStructAlreadyExists: A struct with the same name already exists
exceptions.SarkCreationFailed: Struct creation failed
"""
sid = idc.G... | python | def create_struct(name):
"""Create a structure.
Args:
name: The structure's name
Returns:
The sturct ID
Raises:
exceptions.SarkStructAlreadyExists: A struct with the same name already exists
exceptions.SarkCreationFailed: Struct creation failed
"""
sid = idc.G... | [
"def",
"create_struct",
"(",
"name",
")",
":",
"sid",
"=",
"idc",
".",
"GetStrucIdByName",
"(",
"name",
")",
"if",
"sid",
"!=",
"idaapi",
".",
"BADADDR",
":",
"# The struct already exists.",
"raise",
"exceptions",
".",
"SarkStructAlreadyExists",
"(",
"\"A struct... | Create a structure.
Args:
name: The structure's name
Returns:
The sturct ID
Raises:
exceptions.SarkStructAlreadyExists: A struct with the same name already exists
exceptions.SarkCreationFailed: Struct creation failed | [
"Create",
"a",
"structure",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/structure.py#L59-L81 | train |
tmr232/Sark | sark/structure.py | get_struct | def get_struct(name):
"""Get a struct by it's name.
Args:
name: The name of the struct
Returns:
The struct's id
Raises:
exceptions.SarkStructNotFound: is the struct does not exist.
"""
sid = idc.GetStrucIdByName(name)
if sid == idaapi.BADADDR:
raise excepti... | python | def get_struct(name):
"""Get a struct by it's name.
Args:
name: The name of the struct
Returns:
The struct's id
Raises:
exceptions.SarkStructNotFound: is the struct does not exist.
"""
sid = idc.GetStrucIdByName(name)
if sid == idaapi.BADADDR:
raise excepti... | [
"def",
"get_struct",
"(",
"name",
")",
":",
"sid",
"=",
"idc",
".",
"GetStrucIdByName",
"(",
"name",
")",
"if",
"sid",
"==",
"idaapi",
".",
"BADADDR",
":",
"raise",
"exceptions",
".",
"SarkStructNotFound",
"(",
")",
"return",
"sid"
] | Get a struct by it's name.
Args:
name: The name of the struct
Returns:
The struct's id
Raises:
exceptions.SarkStructNotFound: is the struct does not exist. | [
"Get",
"a",
"struct",
"by",
"it",
"s",
"name",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/structure.py#L84-L100 | train |
tmr232/Sark | sark/structure.py | get_common_register | def get_common_register(start, end):
"""Get the register most commonly used in accessing structs.
Access to is considered for every opcode that accesses memory
in an offset from a register::
mov eax, [ebx + 5]
For every access, the struct-referencing registers, in this case
`ebx`, are cou... | python | def get_common_register(start, end):
"""Get the register most commonly used in accessing structs.
Access to is considered for every opcode that accesses memory
in an offset from a register::
mov eax, [ebx + 5]
For every access, the struct-referencing registers, in this case
`ebx`, are cou... | [
"def",
"get_common_register",
"(",
"start",
",",
"end",
")",
":",
"registers",
"=",
"defaultdict",
"(",
"int",
")",
"for",
"line",
"in",
"lines",
"(",
"start",
",",
"end",
")",
":",
"insn",
"=",
"line",
".",
"insn",
"for",
"operand",
"in",
"insn",
".... | Get the register most commonly used in accessing structs.
Access to is considered for every opcode that accesses memory
in an offset from a register::
mov eax, [ebx + 5]
For every access, the struct-referencing registers, in this case
`ebx`, are counted. The most used one is returned.
Ar... | [
"Get",
"the",
"register",
"most",
"commonly",
"used",
"in",
"accessing",
"structs",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/structure.py#L143-L173 | train |
tmr232/Sark | sark/enum.py | _enum_member_error | def _enum_member_error(err, eid, name, value, bitmask):
"""Format enum member error."""
exception, msg = ENUM_ERROR_MAP[err]
enum_name = idaapi.get_enum_name(eid)
return exception(('add_enum_member(enum="{}", member="{}", value={}, bitmask=0x{:08X}) '
'failed: {}').format(
... | python | def _enum_member_error(err, eid, name, value, bitmask):
"""Format enum member error."""
exception, msg = ENUM_ERROR_MAP[err]
enum_name = idaapi.get_enum_name(eid)
return exception(('add_enum_member(enum="{}", member="{}", value={}, bitmask=0x{:08X}) '
'failed: {}').format(
... | [
"def",
"_enum_member_error",
"(",
"err",
",",
"eid",
",",
"name",
",",
"value",
",",
"bitmask",
")",
":",
"exception",
",",
"msg",
"=",
"ENUM_ERROR_MAP",
"[",
"err",
"]",
"enum_name",
"=",
"idaapi",
".",
"get_enum_name",
"(",
"eid",
")",
"return",
"excep... | Format enum member error. | [
"Format",
"enum",
"member",
"error",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L21-L32 | train |
tmr232/Sark | sark/enum.py | _get_enum | def _get_enum(name):
"""Get an existing enum ID"""
eid = idaapi.get_enum(name)
if eid == idaapi.BADADDR:
raise exceptions.EnumNotFound('Enum "{}" does not exist.'.format(name))
return eid | python | def _get_enum(name):
"""Get an existing enum ID"""
eid = idaapi.get_enum(name)
if eid == idaapi.BADADDR:
raise exceptions.EnumNotFound('Enum "{}" does not exist.'.format(name))
return eid | [
"def",
"_get_enum",
"(",
"name",
")",
":",
"eid",
"=",
"idaapi",
".",
"get_enum",
"(",
"name",
")",
"if",
"eid",
"==",
"idaapi",
".",
"BADADDR",
":",
"raise",
"exceptions",
".",
"EnumNotFound",
"(",
"'Enum \"{}\" does not exist.'",
".",
"format",
"(",
"nam... | Get an existing enum ID | [
"Get",
"an",
"existing",
"enum",
"ID"
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L35-L40 | train |
tmr232/Sark | sark/enum.py | add_enum | def add_enum(name=None, index=None, flags=idaapi.hexflag(), bitfield=False):
"""Create a new enum.
Args:
name: Name of the enum to create.
index: The index of the enum. Leave at default to append the enum as the last enum.
flags: Enum type flags.
bitfield: Is the enum a bitfield... | python | def add_enum(name=None, index=None, flags=idaapi.hexflag(), bitfield=False):
"""Create a new enum.
Args:
name: Name of the enum to create.
index: The index of the enum. Leave at default to append the enum as the last enum.
flags: Enum type flags.
bitfield: Is the enum a bitfield... | [
"def",
"add_enum",
"(",
"name",
"=",
"None",
",",
"index",
"=",
"None",
",",
"flags",
"=",
"idaapi",
".",
"hexflag",
"(",
")",
",",
"bitfield",
"=",
"False",
")",
":",
"if",
"name",
"is",
"not",
"None",
":",
"with",
"ignored",
"(",
"exceptions",
".... | Create a new enum.
Args:
name: Name of the enum to create.
index: The index of the enum. Leave at default to append the enum as the last enum.
flags: Enum type flags.
bitfield: Is the enum a bitfield.
Returns:
An `Enum` object. | [
"Create",
"a",
"new",
"enum",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L43-L71 | train |
tmr232/Sark | sark/enum.py | _add_enum_member | def _add_enum_member(enum, name, value, bitmask=DEFMASK):
"""Add an enum member."""
error = idaapi.add_enum_member(enum, name, value, bitmask)
if error:
raise _enum_member_error(error, enum, name, value, bitmask) | python | def _add_enum_member(enum, name, value, bitmask=DEFMASK):
"""Add an enum member."""
error = idaapi.add_enum_member(enum, name, value, bitmask)
if error:
raise _enum_member_error(error, enum, name, value, bitmask) | [
"def",
"_add_enum_member",
"(",
"enum",
",",
"name",
",",
"value",
",",
"bitmask",
"=",
"DEFMASK",
")",
":",
"error",
"=",
"idaapi",
".",
"add_enum_member",
"(",
"enum",
",",
"name",
",",
"value",
",",
"bitmask",
")",
"if",
"error",
":",
"raise",
"_enu... | Add an enum member. | [
"Add",
"an",
"enum",
"member",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L79-L84 | train |
tmr232/Sark | sark/enum.py | _iter_bitmasks | def _iter_bitmasks(eid):
"""Iterate all bitmasks in a given enum.
Note that while `DEFMASK` indicates no-more-bitmasks, it is also a
valid bitmask value. The only way to tell if it exists is when iterating
the serials.
"""
bitmask = idaapi.get_first_bmask(eid)
yield bitmask
while bitm... | python | def _iter_bitmasks(eid):
"""Iterate all bitmasks in a given enum.
Note that while `DEFMASK` indicates no-more-bitmasks, it is also a
valid bitmask value. The only way to tell if it exists is when iterating
the serials.
"""
bitmask = idaapi.get_first_bmask(eid)
yield bitmask
while bitm... | [
"def",
"_iter_bitmasks",
"(",
"eid",
")",
":",
"bitmask",
"=",
"idaapi",
".",
"get_first_bmask",
"(",
"eid",
")",
"yield",
"bitmask",
"while",
"bitmask",
"!=",
"DEFMASK",
":",
"bitmask",
"=",
"idaapi",
".",
"get_next_bmask",
"(",
"eid",
",",
"bitmask",
")"... | Iterate all bitmasks in a given enum.
Note that while `DEFMASK` indicates no-more-bitmasks, it is also a
valid bitmask value. The only way to tell if it exists is when iterating
the serials. | [
"Iterate",
"all",
"bitmasks",
"in",
"a",
"given",
"enum",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L352-L365 | train |
tmr232/Sark | sark/enum.py | _iter_enum_member_values | def _iter_enum_member_values(eid, bitmask):
"""Iterate member values with given bitmask inside the enum
Note that `DEFMASK` can either indicate end-of-values or a valid value.
Iterate serials to tell apart.
"""
value = idaapi.get_first_enum_member(eid, bitmask)
yield value
while value != D... | python | def _iter_enum_member_values(eid, bitmask):
"""Iterate member values with given bitmask inside the enum
Note that `DEFMASK` can either indicate end-of-values or a valid value.
Iterate serials to tell apart.
"""
value = idaapi.get_first_enum_member(eid, bitmask)
yield value
while value != D... | [
"def",
"_iter_enum_member_values",
"(",
"eid",
",",
"bitmask",
")",
":",
"value",
"=",
"idaapi",
".",
"get_first_enum_member",
"(",
"eid",
",",
"bitmask",
")",
"yield",
"value",
"while",
"value",
"!=",
"DEFMASK",
":",
"value",
"=",
"idaapi",
".",
"get_next_e... | Iterate member values with given bitmask inside the enum
Note that `DEFMASK` can either indicate end-of-values or a valid value.
Iterate serials to tell apart. | [
"Iterate",
"member",
"values",
"with",
"given",
"bitmask",
"inside",
"the",
"enum"
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L368-L379 | train |
tmr232/Sark | sark/enum.py | _iter_serial_enum_member | def _iter_serial_enum_member(eid, value, bitmask):
"""Iterate serial and CID of enum members with given value and bitmask.
Here only valid values are returned, as `idaapi.BADNODE` always indicates
an invalid member.
"""
cid, serial = idaapi.get_first_serial_enum_member(eid, value, bitmask)
whil... | python | def _iter_serial_enum_member(eid, value, bitmask):
"""Iterate serial and CID of enum members with given value and bitmask.
Here only valid values are returned, as `idaapi.BADNODE` always indicates
an invalid member.
"""
cid, serial = idaapi.get_first_serial_enum_member(eid, value, bitmask)
whil... | [
"def",
"_iter_serial_enum_member",
"(",
"eid",
",",
"value",
",",
"bitmask",
")",
":",
"cid",
",",
"serial",
"=",
"idaapi",
".",
"get_first_serial_enum_member",
"(",
"eid",
",",
"value",
",",
"bitmask",
")",
"while",
"cid",
"!=",
"idaapi",
".",
"BADNODE",
... | Iterate serial and CID of enum members with given value and bitmask.
Here only valid values are returned, as `idaapi.BADNODE` always indicates
an invalid member. | [
"Iterate",
"serial",
"and",
"CID",
"of",
"enum",
"members",
"with",
"given",
"value",
"and",
"bitmask",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L382-L391 | train |
tmr232/Sark | sark/enum.py | _iter_enum_constant_ids | def _iter_enum_constant_ids(eid):
"""Iterate the constant IDs of all members in the given enum"""
for bitmask in _iter_bitmasks(eid):
for value in _iter_enum_member_values(eid, bitmask):
for cid, serial in _iter_serial_enum_member(eid, value, bitmask):
yield cid | python | def _iter_enum_constant_ids(eid):
"""Iterate the constant IDs of all members in the given enum"""
for bitmask in _iter_bitmasks(eid):
for value in _iter_enum_member_values(eid, bitmask):
for cid, serial in _iter_serial_enum_member(eid, value, bitmask):
yield cid | [
"def",
"_iter_enum_constant_ids",
"(",
"eid",
")",
":",
"for",
"bitmask",
"in",
"_iter_bitmasks",
"(",
"eid",
")",
":",
"for",
"value",
"in",
"_iter_enum_member_values",
"(",
"eid",
",",
"bitmask",
")",
":",
"for",
"cid",
",",
"serial",
"in",
"_iter_serial_e... | Iterate the constant IDs of all members in the given enum | [
"Iterate",
"the",
"constant",
"IDs",
"of",
"all",
"members",
"in",
"the",
"given",
"enum"
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L394-L399 | train |
tmr232/Sark | sark/enum.py | EnumMembers.add | def add(self, name, value, bitmask=DEFMASK):
"""Add an enum member
Args:
name: Name of the member
value: value of the member
bitmask: bitmask. Only use if enum is a bitfield.
"""
_add_enum_member(self._eid, name, value, bitmask) | python | def add(self, name, value, bitmask=DEFMASK):
"""Add an enum member
Args:
name: Name of the member
value: value of the member
bitmask: bitmask. Only use if enum is a bitfield.
"""
_add_enum_member(self._eid, name, value, bitmask) | [
"def",
"add",
"(",
"self",
",",
"name",
",",
"value",
",",
"bitmask",
"=",
"DEFMASK",
")",
":",
"_add_enum_member",
"(",
"self",
".",
"_eid",
",",
"name",
",",
"value",
",",
"bitmask",
")"
] | Add an enum member
Args:
name: Name of the member
value: value of the member
bitmask: bitmask. Only use if enum is a bitfield. | [
"Add",
"an",
"enum",
"member"
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L141-L149 | train |
tmr232/Sark | sark/enum.py | EnumMembers.remove | def remove(self, name):
"""Remove an enum member by name"""
member = self[name]
serial = member.serial
value = member.value
bmask = member.bmask
success = idaapi.del_enum_member(self._eid, value, serial, bmask)
if not success:
raise exceptions.CantDel... | python | def remove(self, name):
"""Remove an enum member by name"""
member = self[name]
serial = member.serial
value = member.value
bmask = member.bmask
success = idaapi.del_enum_member(self._eid, value, serial, bmask)
if not success:
raise exceptions.CantDel... | [
"def",
"remove",
"(",
"self",
",",
"name",
")",
":",
"member",
"=",
"self",
"[",
"name",
"]",
"serial",
"=",
"member",
".",
"serial",
"value",
"=",
"member",
".",
"value",
"bmask",
"=",
"member",
".",
"bmask",
"success",
"=",
"idaapi",
".",
"del_enum... | Remove an enum member by name | [
"Remove",
"an",
"enum",
"member",
"by",
"name"
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L158-L167 | train |
tmr232/Sark | sark/enum.py | Enum.name | def name(self, name):
"""Set the enum name."""
success = idaapi.set_enum_name(self.eid, name)
if not success:
raise exceptions.CantRenameEnum("Cant rename enum {!r} to {!r}.".format(self.name, name)) | python | def name(self, name):
"""Set the enum name."""
success = idaapi.set_enum_name(self.eid, name)
if not success:
raise exceptions.CantRenameEnum("Cant rename enum {!r} to {!r}.".format(self.name, name)) | [
"def",
"name",
"(",
"self",
",",
"name",
")",
":",
"success",
"=",
"idaapi",
".",
"set_enum_name",
"(",
"self",
".",
"eid",
",",
"name",
")",
"if",
"not",
"success",
":",
"raise",
"exceptions",
".",
"CantRenameEnum",
"(",
"\"Cant rename enum {!r} to {!r}.\""... | Set the enum name. | [
"Set",
"the",
"enum",
"name",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L201-L205 | train |
tmr232/Sark | sark/enum.py | EnumMember.name | def name(self, name):
"""Set the member name.
Note that a member name cannot appear in other enums, or generally
anywhere else in the IDB.
"""
success = idaapi.set_enum_member_name(self.cid, name)
if not success:
raise exceptions.CantRenameEnumMember(
... | python | def name(self, name):
"""Set the member name.
Note that a member name cannot appear in other enums, or generally
anywhere else in the IDB.
"""
success = idaapi.set_enum_member_name(self.cid, name)
if not success:
raise exceptions.CantRenameEnumMember(
... | [
"def",
"name",
"(",
"self",
",",
"name",
")",
":",
"success",
"=",
"idaapi",
".",
"set_enum_member_name",
"(",
"self",
".",
"cid",
",",
"name",
")",
"if",
"not",
"success",
":",
"raise",
"exceptions",
".",
"CantRenameEnumMember",
"(",
"\"Failed renaming {!r}... | Set the member name.
Note that a member name cannot appear in other enums, or generally
anywhere else in the IDB. | [
"Set",
"the",
"member",
"name",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/enum.py#L310-L319 | train |
tmr232/Sark | sark/code/function.py | functions | def functions(start=None, end=None):
"""Get all functions in range.
Args:
start: Start address of the range. Defaults to IDB start.
end: End address of the range. Defaults to IDB end.
Returns:
This is a generator that iterates over all the functions in the IDB.
"""
start, e... | python | def functions(start=None, end=None):
"""Get all functions in range.
Args:
start: Start address of the range. Defaults to IDB start.
end: End address of the range. Defaults to IDB end.
Returns:
This is a generator that iterates over all the functions in the IDB.
"""
start, e... | [
"def",
"functions",
"(",
"start",
"=",
"None",
",",
"end",
"=",
"None",
")",
":",
"start",
",",
"end",
"=",
"fix_addresses",
"(",
"start",
",",
"end",
")",
"for",
"func_t",
"in",
"idautils",
".",
"Functions",
"(",
"start",
",",
"end",
")",
":",
"yi... | Get all functions in range.
Args:
start: Start address of the range. Defaults to IDB start.
end: End address of the range. Defaults to IDB end.
Returns:
This is a generator that iterates over all the functions in the IDB. | [
"Get",
"all",
"functions",
"in",
"range",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/function.py#L400-L413 | train |
tmr232/Sark | sark/code/function.py | Function.xrefs_from | def xrefs_from(self):
"""Xrefs from the function.
This includes the xrefs from every line in the function, as `Xref` objects.
Xrefs are filtered to exclude code references that are internal to the function. This
means that every xrefs to the function's code will NOT be returned (yet, re... | python | def xrefs_from(self):
"""Xrefs from the function.
This includes the xrefs from every line in the function, as `Xref` objects.
Xrefs are filtered to exclude code references that are internal to the function. This
means that every xrefs to the function's code will NOT be returned (yet, re... | [
"def",
"xrefs_from",
"(",
"self",
")",
":",
"for",
"line",
"in",
"self",
".",
"lines",
":",
"for",
"xref",
"in",
"line",
".",
"xrefs_from",
":",
"if",
"xref",
".",
"type",
".",
"is_flow",
":",
"continue",
"if",
"xref",
".",
"to",
"in",
"self",
"and... | Xrefs from the function.
This includes the xrefs from every line in the function, as `Xref` objects.
Xrefs are filtered to exclude code references that are internal to the function. This
means that every xrefs to the function's code will NOT be returned (yet, references
to the function'... | [
"Xrefs",
"from",
"the",
"function",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/function.py#L234-L251 | train |
tmr232/Sark | sark/code/function.py | Function.set_name | def set_name(self, name, anyway=False):
"""Set Function Name.
Default behavior throws an exception when setting to a name that already exists in
the IDB. to make IDA automatically add a counter to the name (like in the GUI,)
use `anyway=True`.
Args:
name: Desired na... | python | def set_name(self, name, anyway=False):
"""Set Function Name.
Default behavior throws an exception when setting to a name that already exists in
the IDB. to make IDA automatically add a counter to the name (like in the GUI,)
use `anyway=True`.
Args:
name: Desired na... | [
"def",
"set_name",
"(",
"self",
",",
"name",
",",
"anyway",
"=",
"False",
")",
":",
"set_name",
"(",
"self",
".",
"startEA",
",",
"name",
",",
"anyway",
"=",
"anyway",
")"
] | Set Function Name.
Default behavior throws an exception when setting to a name that already exists in
the IDB. to make IDA automatically add a counter to the name (like in the GUI,)
use `anyway=True`.
Args:
name: Desired name.
anyway: `True` to set anyway. | [
"Set",
"Function",
"Name",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/function.py#L308-L319 | train |
tmr232/Sark | sark/code/function.py | Function.color | def color(self):
"""Function color in IDA View"""
color = idc.GetColor(self.ea, idc.CIC_FUNC)
if color == 0xFFFFFFFF:
return None
return color | python | def color(self):
"""Function color in IDA View"""
color = idc.GetColor(self.ea, idc.CIC_FUNC)
if color == 0xFFFFFFFF:
return None
return color | [
"def",
"color",
"(",
"self",
")",
":",
"color",
"=",
"idc",
".",
"GetColor",
"(",
"self",
".",
"ea",
",",
"idc",
".",
"CIC_FUNC",
")",
"if",
"color",
"==",
"0xFFFFFFFF",
":",
"return",
"None",
"return",
"color"
] | Function color in IDA View | [
"Function",
"color",
"in",
"IDA",
"View"
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/function.py#L336-L342 | train |
tmr232/Sark | sark/code/function.py | Function.color | def color(self, color):
"""Function Color in IDA View.
Set color to `None` to clear the color.
"""
if color is None:
color = 0xFFFFFFFF
idc.SetColor(self.ea, idc.CIC_FUNC, color) | python | def color(self, color):
"""Function Color in IDA View.
Set color to `None` to clear the color.
"""
if color is None:
color = 0xFFFFFFFF
idc.SetColor(self.ea, idc.CIC_FUNC, color) | [
"def",
"color",
"(",
"self",
",",
"color",
")",
":",
"if",
"color",
"is",
"None",
":",
"color",
"=",
"0xFFFFFFFF",
"idc",
".",
"SetColor",
"(",
"self",
".",
"ea",
",",
"idc",
".",
"CIC_FUNC",
",",
"color",
")"
] | Function Color in IDA View.
Set color to `None` to clear the color. | [
"Function",
"Color",
"in",
"IDA",
"View",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/function.py#L346-L354 | train |
tmr232/Sark | sark/code/line.py | lines | def lines(start=None, end=None, reverse=False, selection=False):
"""Iterate lines in range.
Args:
start: Starting address, start of IDB if `None`.
end: End address, end of IDB if `None`.
reverse: Set to true to iterate in reverse order.
selection: If set to True, replaces start ... | python | def lines(start=None, end=None, reverse=False, selection=False):
"""Iterate lines in range.
Args:
start: Starting address, start of IDB if `None`.
end: End address, end of IDB if `None`.
reverse: Set to true to iterate in reverse order.
selection: If set to True, replaces start ... | [
"def",
"lines",
"(",
"start",
"=",
"None",
",",
"end",
"=",
"None",
",",
"reverse",
"=",
"False",
",",
"selection",
"=",
"False",
")",
":",
"if",
"selection",
":",
"start",
",",
"end",
"=",
"get_selection",
"(",
")",
"else",
":",
"start",
",",
"end... | Iterate lines in range.
Args:
start: Starting address, start of IDB if `None`.
end: End address, end of IDB if `None`.
reverse: Set to true to iterate in reverse order.
selection: If set to True, replaces start and end with current selection.
Returns:
iterator of `Line`... | [
"Iterate",
"lines",
"in",
"range",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/line.py#L327-L355 | train |
tmr232/Sark | sark/code/line.py | Line.type | def type(self):
"""return the type of the Line """
properties = {self.is_code: "code",
self.is_data: "data",
self.is_string: "string",
self.is_tail: "tail",
self.is_unknown: "unknown"}
for k, v in properties.... | python | def type(self):
"""return the type of the Line """
properties = {self.is_code: "code",
self.is_data: "data",
self.is_string: "string",
self.is_tail: "tail",
self.is_unknown: "unknown"}
for k, v in properties.... | [
"def",
"type",
"(",
"self",
")",
":",
"properties",
"=",
"{",
"self",
".",
"is_code",
":",
"\"code\"",
",",
"self",
".",
"is_data",
":",
"\"data\"",
",",
"self",
".",
"is_string",
":",
"\"string\"",
",",
"self",
".",
"is_tail",
":",
"\"tail\"",
",",
... | return the type of the Line | [
"return",
"the",
"type",
"of",
"the",
"Line"
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/line.py#L195-L203 | train |
tmr232/Sark | sark/code/line.py | Line.color | def color(self):
"""Line color in IDA View"""
color = idc.GetColor(self.ea, idc.CIC_ITEM)
if color == 0xFFFFFFFF:
return None
return color | python | def color(self):
"""Line color in IDA View"""
color = idc.GetColor(self.ea, idc.CIC_ITEM)
if color == 0xFFFFFFFF:
return None
return color | [
"def",
"color",
"(",
"self",
")",
":",
"color",
"=",
"idc",
".",
"GetColor",
"(",
"self",
".",
"ea",
",",
"idc",
".",
"CIC_ITEM",
")",
"if",
"color",
"==",
"0xFFFFFFFF",
":",
"return",
"None",
"return",
"color"
] | Line color in IDA View | [
"Line",
"color",
"in",
"IDA",
"View"
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/line.py#L274-L280 | train |
tmr232/Sark | sark/code/line.py | Line.color | def color(self, color):
"""Line Color in IDA View.
Set color to `None` to clear the color.
"""
if color is None:
color = 0xFFFFFFFF
idc.SetColor(self.ea, idc.CIC_ITEM, color) | python | def color(self, color):
"""Line Color in IDA View.
Set color to `None` to clear the color.
"""
if color is None:
color = 0xFFFFFFFF
idc.SetColor(self.ea, idc.CIC_ITEM, color) | [
"def",
"color",
"(",
"self",
",",
"color",
")",
":",
"if",
"color",
"is",
"None",
":",
"color",
"=",
"0xFFFFFFFF",
"idc",
".",
"SetColor",
"(",
"self",
".",
"ea",
",",
"idc",
".",
"CIC_ITEM",
",",
"color",
")"
] | Line Color in IDA View.
Set color to `None` to clear the color. | [
"Line",
"Color",
"in",
"IDA",
"View",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/line.py#L284-L292 | train |
tmr232/Sark | sark/qt.py | capture_widget | def capture_widget(widget, path=None):
"""Grab an image of a Qt widget
Args:
widget: The Qt Widget to capture
path (optional): The path to save to. If not provided - will return image data.
Returns:
If a path is provided, the image will be saved to it.
If not, the PNG buffe... | python | def capture_widget(widget, path=None):
"""Grab an image of a Qt widget
Args:
widget: The Qt Widget to capture
path (optional): The path to save to. If not provided - will return image data.
Returns:
If a path is provided, the image will be saved to it.
If not, the PNG buffe... | [
"def",
"capture_widget",
"(",
"widget",
",",
"path",
"=",
"None",
")",
":",
"if",
"use_qt5",
":",
"pixmap",
"=",
"widget",
".",
"grab",
"(",
")",
"else",
":",
"pixmap",
"=",
"QtGui",
".",
"QPixmap",
".",
"grabWidget",
"(",
"widget",
")",
"if",
"path"... | Grab an image of a Qt widget
Args:
widget: The Qt Widget to capture
path (optional): The path to save to. If not provided - will return image data.
Returns:
If a path is provided, the image will be saved to it.
If not, the PNG buffer will be returned. | [
"Grab",
"an",
"image",
"of",
"a",
"Qt",
"widget"
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/qt.py#L14-L39 | train |
tmr232/Sark | sark/qt.py | get_widget | def get_widget(title):
"""Get the Qt widget of the IDA window with the given title."""
tform = idaapi.find_tform(title)
if not tform:
raise exceptions.FormNotFound("No form titled {!r} found.".format(title))
return form_to_widget(tform) | python | def get_widget(title):
"""Get the Qt widget of the IDA window with the given title."""
tform = idaapi.find_tform(title)
if not tform:
raise exceptions.FormNotFound("No form titled {!r} found.".format(title))
return form_to_widget(tform) | [
"def",
"get_widget",
"(",
"title",
")",
":",
"tform",
"=",
"idaapi",
".",
"find_tform",
"(",
"title",
")",
"if",
"not",
"tform",
":",
"raise",
"exceptions",
".",
"FormNotFound",
"(",
"\"No form titled {!r} found.\"",
".",
"format",
"(",
"title",
")",
")",
... | Get the Qt widget of the IDA window with the given title. | [
"Get",
"the",
"Qt",
"widget",
"of",
"the",
"IDA",
"window",
"with",
"the",
"given",
"title",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/qt.py#L42-L48 | train |
tmr232/Sark | sark/qt.py | get_window | def get_window():
"""Get IDA's top level window."""
tform = idaapi.get_current_tform()
# Required sometimes when closing IDBs and not IDA.
if not tform:
tform = idaapi.find_tform("Output window")
widget = form_to_widget(tform)
window = widget.window()
return window | python | def get_window():
"""Get IDA's top level window."""
tform = idaapi.get_current_tform()
# Required sometimes when closing IDBs and not IDA.
if not tform:
tform = idaapi.find_tform("Output window")
widget = form_to_widget(tform)
window = widget.window()
return window | [
"def",
"get_window",
"(",
")",
":",
"tform",
"=",
"idaapi",
".",
"get_current_tform",
"(",
")",
"# Required sometimes when closing IDBs and not IDA.",
"if",
"not",
"tform",
":",
"tform",
"=",
"idaapi",
".",
"find_tform",
"(",
"\"Output window\"",
")",
"widget",
"=... | Get IDA's top level window. | [
"Get",
"IDA",
"s",
"top",
"level",
"window",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/qt.py#L56-L66 | train |
tmr232/Sark | sark/qt.py | MenuManager.add_menu | def add_menu(self, name):
"""Add a top-level menu.
The menu manager only allows one menu of the same name. However, it does
not make sure that there are no pre-existing menus of that name.
"""
if name in self._menus:
raise exceptions.MenuAlreadyExists("Menu name {!r}... | python | def add_menu(self, name):
"""Add a top-level menu.
The menu manager only allows one menu of the same name. However, it does
not make sure that there are no pre-existing menus of that name.
"""
if name in self._menus:
raise exceptions.MenuAlreadyExists("Menu name {!r}... | [
"def",
"add_menu",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"in",
"self",
".",
"_menus",
":",
"raise",
"exceptions",
".",
"MenuAlreadyExists",
"(",
"\"Menu name {!r} already exists.\"",
".",
"format",
"(",
"name",
")",
")",
"menu",
"=",
"self",
".... | Add a top-level menu.
The menu manager only allows one menu of the same name. However, it does
not make sure that there are no pre-existing menus of that name. | [
"Add",
"a",
"top",
"-",
"level",
"menu",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/qt.py#L109-L118 | train |
tmr232/Sark | sark/qt.py | MenuManager.remove_menu | def remove_menu(self, name):
"""Remove a top-level menu.
Only removes menus created by the same menu manager.
"""
if name not in self._menus:
raise exceptions.MenuNotFound(
"Menu {!r} was not found. It might be deleted, or belong to another menu manager.".for... | python | def remove_menu(self, name):
"""Remove a top-level menu.
Only removes menus created by the same menu manager.
"""
if name not in self._menus:
raise exceptions.MenuNotFound(
"Menu {!r} was not found. It might be deleted, or belong to another menu manager.".for... | [
"def",
"remove_menu",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"not",
"in",
"self",
".",
"_menus",
":",
"raise",
"exceptions",
".",
"MenuNotFound",
"(",
"\"Menu {!r} was not found. It might be deleted, or belong to another menu manager.\"",
".",
"format",
"("... | Remove a top-level menu.
Only removes menus created by the same menu manager. | [
"Remove",
"a",
"top",
"-",
"level",
"menu",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/qt.py#L120-L130 | train |
tmr232/Sark | sark/qt.py | MenuManager.clear | def clear(self):
"""Clear all menus created by this manager."""
for menu in self._menus.itervalues():
self._menu.removeAction(menu.menuAction())
self._menus = {} | python | def clear(self):
"""Clear all menus created by this manager."""
for menu in self._menus.itervalues():
self._menu.removeAction(menu.menuAction())
self._menus = {} | [
"def",
"clear",
"(",
"self",
")",
":",
"for",
"menu",
"in",
"self",
".",
"_menus",
".",
"itervalues",
"(",
")",
":",
"self",
".",
"_menu",
".",
"removeAction",
"(",
"menu",
".",
"menuAction",
"(",
")",
")",
"self",
".",
"_menus",
"=",
"{",
"}"
] | Clear all menus created by this manager. | [
"Clear",
"all",
"menus",
"created",
"by",
"this",
"manager",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/qt.py#L132-L136 | train |
tmr232/Sark | sark/debug.py | Registers.get_by_flags | def get_by_flags(self, flags):
"""Iterate all register infos matching the given flags."""
for reg in self._reg_infos:
if reg.flags & flags == flags:
yield reg | python | def get_by_flags(self, flags):
"""Iterate all register infos matching the given flags."""
for reg in self._reg_infos:
if reg.flags & flags == flags:
yield reg | [
"def",
"get_by_flags",
"(",
"self",
",",
"flags",
")",
":",
"for",
"reg",
"in",
"self",
".",
"_reg_infos",
":",
"if",
"reg",
".",
"flags",
"&",
"flags",
"==",
"flags",
":",
"yield",
"reg"
] | Iterate all register infos matching the given flags. | [
"Iterate",
"all",
"register",
"infos",
"matching",
"the",
"given",
"flags",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/debug.py#L39-L43 | train |
tmr232/Sark | sark/debug.py | Registers.get_single_by_flags | def get_single_by_flags(self, flags):
"""Get the register info matching the flag. Raises ValueError if more than one are found."""
regs = list(self.get_by_flags(flags))
if len(regs) != 1:
raise ValueError("Flags do not return unique resigter. {!r}", regs)
return regs[0] | python | def get_single_by_flags(self, flags):
"""Get the register info matching the flag. Raises ValueError if more than one are found."""
regs = list(self.get_by_flags(flags))
if len(regs) != 1:
raise ValueError("Flags do not return unique resigter. {!r}", regs)
return regs[0] | [
"def",
"get_single_by_flags",
"(",
"self",
",",
"flags",
")",
":",
"regs",
"=",
"list",
"(",
"self",
".",
"get_by_flags",
"(",
"flags",
")",
")",
"if",
"len",
"(",
"regs",
")",
"!=",
"1",
":",
"raise",
"ValueError",
"(",
"\"Flags do not return unique resig... | Get the register info matching the flag. Raises ValueError if more than one are found. | [
"Get",
"the",
"register",
"info",
"matching",
"the",
"flag",
".",
"Raises",
"ValueError",
"if",
"more",
"than",
"one",
"are",
"found",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/debug.py#L45-L51 | train |
tmr232/Sark | sark/code/segment.py | segments | def segments(seg_type=None):
"""Iterate segments based on type
Args:
seg_type: type of segment e.g. SEG_CODE
Returns:
iterator of `Segment` objects. if seg_type is None , returns all segments
otherwise returns only the relevant ones
"""
for index in xra... | python | def segments(seg_type=None):
"""Iterate segments based on type
Args:
seg_type: type of segment e.g. SEG_CODE
Returns:
iterator of `Segment` objects. if seg_type is None , returns all segments
otherwise returns only the relevant ones
"""
for index in xra... | [
"def",
"segments",
"(",
"seg_type",
"=",
"None",
")",
":",
"for",
"index",
"in",
"xrange",
"(",
"idaapi",
".",
"get_segm_qty",
"(",
")",
")",
":",
"seg",
"=",
"Segment",
"(",
"index",
"=",
"index",
")",
"if",
"(",
"seg_type",
"is",
"None",
")",
"or... | Iterate segments based on type
Args:
seg_type: type of segment e.g. SEG_CODE
Returns:
iterator of `Segment` objects. if seg_type is None , returns all segments
otherwise returns only the relevant ones | [
"Iterate",
"segments",
"based",
"on",
"type"
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/segment.py#L250-L264 | train |
tmr232/Sark | sark/code/segment.py | Segment.next | def next(self):
"""Get the next segment."""
seg = Segment(segment_t=idaapi.get_next_seg(self.ea))
if seg.ea <= self.ea:
raise exceptions.NoMoreSegments("This is the last segment. No segments exist after it.")
return seg | python | def next(self):
"""Get the next segment."""
seg = Segment(segment_t=idaapi.get_next_seg(self.ea))
if seg.ea <= self.ea:
raise exceptions.NoMoreSegments("This is the last segment. No segments exist after it.")
return seg | [
"def",
"next",
"(",
"self",
")",
":",
"seg",
"=",
"Segment",
"(",
"segment_t",
"=",
"idaapi",
".",
"get_next_seg",
"(",
"self",
".",
"ea",
")",
")",
"if",
"seg",
".",
"ea",
"<=",
"self",
".",
"ea",
":",
"raise",
"exceptions",
".",
"NoMoreSegments",
... | Get the next segment. | [
"Get",
"the",
"next",
"segment",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/segment.py#L211-L218 | train |
tmr232/Sark | sark/code/segment.py | Segment.prev | def prev(self):
"""Get the previous segment."""
seg = Segment(segment_t=idaapi.get_prev_seg(self.ea))
if seg.ea >= self.ea:
raise exceptions.NoMoreSegments("This is the first segment. no segments exist before it.")
return seg | python | def prev(self):
"""Get the previous segment."""
seg = Segment(segment_t=idaapi.get_prev_seg(self.ea))
if seg.ea >= self.ea:
raise exceptions.NoMoreSegments("This is the first segment. no segments exist before it.")
return seg | [
"def",
"prev",
"(",
"self",
")",
":",
"seg",
"=",
"Segment",
"(",
"segment_t",
"=",
"idaapi",
".",
"get_prev_seg",
"(",
"self",
".",
"ea",
")",
")",
"if",
"seg",
".",
"ea",
">=",
"self",
".",
"ea",
":",
"raise",
"exceptions",
".",
"NoMoreSegments",
... | Get the previous segment. | [
"Get",
"the",
"previous",
"segment",
"."
] | bee62879c2aea553a3924d887e2b30f2a6008581 | https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/code/segment.py#L221-L228 | train |
thoth-station/solver | thoth/solver/python/base.py | get_ecosystem_solver | def get_ecosystem_solver(ecosystem_name, parser_kwargs=None, fetcher_kwargs=None):
"""Get Solver subclass instance for particular ecosystem.
:param ecosystem_name: name of ecosystem for which solver should be get
:param parser_kwargs: parser key-value arguments for constructor
:param fetcher_kwargs: fe... | python | def get_ecosystem_solver(ecosystem_name, parser_kwargs=None, fetcher_kwargs=None):
"""Get Solver subclass instance for particular ecosystem.
:param ecosystem_name: name of ecosystem for which solver should be get
:param parser_kwargs: parser key-value arguments for constructor
:param fetcher_kwargs: fe... | [
"def",
"get_ecosystem_solver",
"(",
"ecosystem_name",
",",
"parser_kwargs",
"=",
"None",
",",
"fetcher_kwargs",
"=",
"None",
")",
":",
"from",
".",
"python",
"import",
"PythonSolver",
"if",
"ecosystem_name",
".",
"lower",
"(",
")",
"==",
"\"pypi\"",
":",
"sour... | Get Solver subclass instance for particular ecosystem.
:param ecosystem_name: name of ecosystem for which solver should be get
:param parser_kwargs: parser key-value arguments for constructor
:param fetcher_kwargs: fetcher key-value arguments for constructor
:return: Solver | [
"Get",
"Solver",
"subclass",
"instance",
"for",
"particular",
"ecosystem",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/base.py#L297-L311 | train |
thoth-station/solver | thoth/solver/python/base.py | Dependency.check | def check(self, version): # Ignore PyDocStyleBear
"""Check if `version` fits into our dependency specification.
:param version: str
:return: bool
"""
def _compare_spec(spec):
if len(spec) == 1:
spec = ("=", spec[0])
token = Tokens.opera... | python | def check(self, version): # Ignore PyDocStyleBear
"""Check if `version` fits into our dependency specification.
:param version: str
:return: bool
"""
def _compare_spec(spec):
if len(spec) == 1:
spec = ("=", spec[0])
token = Tokens.opera... | [
"def",
"check",
"(",
"self",
",",
"version",
")",
":",
"# Ignore PyDocStyleBear",
"def",
"_compare_spec",
"(",
"spec",
")",
":",
"if",
"len",
"(",
"spec",
")",
"==",
"1",
":",
"spec",
"=",
"(",
"\"=\"",
",",
"spec",
"[",
"0",
"]",
")",
"token",
"="... | Check if `version` fits into our dependency specification.
:param version: str
:return: bool | [
"Check",
"if",
"version",
"fits",
"into",
"our",
"dependency",
"specification",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/base.py#L143-L181 | train |
thoth-station/solver | thoth/solver/python/base.py | Solver.solve | def solve(self, dependencies, graceful=True, all_versions=False): # Ignore PyDocStyleBear
"""Solve `dependencies` against upstream repository.
:param dependencies: List, List of dependencies in native format
:param graceful: bool, Print info output to stdout
:param all_versions: bool, ... | python | def solve(self, dependencies, graceful=True, all_versions=False): # Ignore PyDocStyleBear
"""Solve `dependencies` against upstream repository.
:param dependencies: List, List of dependencies in native format
:param graceful: bool, Print info output to stdout
:param all_versions: bool, ... | [
"def",
"solve",
"(",
"self",
",",
"dependencies",
",",
"graceful",
"=",
"True",
",",
"all_versions",
"=",
"False",
")",
":",
"# Ignore PyDocStyleBear",
"def",
"_compare_version_index_url",
"(",
"v1",
",",
"v2",
")",
":",
"\"\"\"Get a wrapper around compare version t... | Solve `dependencies` against upstream repository.
:param dependencies: List, List of dependencies in native format
:param graceful: bool, Print info output to stdout
:param all_versions: bool, Return all matched versions instead of the latest
:return: Dict[str, str], Matched versions | [
"Solve",
"dependencies",
"against",
"upstream",
"repository",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/base.py#L250-L294 | train |
thoth-station/solver | thoth/solver/compile.py | pip_compile | def pip_compile(*packages: str):
"""Run pip-compile to pin down packages, also resolve their transitive dependencies."""
result = None
packages = "\n".join(packages)
with tempfile.TemporaryDirectory() as tmp_dirname, cwd(tmp_dirname):
with open("requirements.in", "w") as requirements_file:
... | python | def pip_compile(*packages: str):
"""Run pip-compile to pin down packages, also resolve their transitive dependencies."""
result = None
packages = "\n".join(packages)
with tempfile.TemporaryDirectory() as tmp_dirname, cwd(tmp_dirname):
with open("requirements.in", "w") as requirements_file:
... | [
"def",
"pip_compile",
"(",
"*",
"packages",
":",
"str",
")",
":",
"result",
"=",
"None",
"packages",
"=",
"\"\\n\"",
".",
"join",
"(",
"packages",
")",
"with",
"tempfile",
".",
"TemporaryDirectory",
"(",
")",
"as",
"tmp_dirname",
",",
"cwd",
"(",
"tmp_di... | Run pip-compile to pin down packages, also resolve their transitive dependencies. | [
"Run",
"pip",
"-",
"compile",
"to",
"pin",
"down",
"packages",
"also",
"resolve",
"their",
"transitive",
"dependencies",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/compile.py#L30-L52 | train |
thoth-station/solver | thoth/solver/cli.py | _print_version | def _print_version(ctx, _, value):
"""Print solver version and exit."""
if not value or ctx.resilient_parsing:
return
click.echo(analyzer_version)
ctx.exit() | python | def _print_version(ctx, _, value):
"""Print solver version and exit."""
if not value or ctx.resilient_parsing:
return
click.echo(analyzer_version)
ctx.exit() | [
"def",
"_print_version",
"(",
"ctx",
",",
"_",
",",
"value",
")",
":",
"if",
"not",
"value",
"or",
"ctx",
".",
"resilient_parsing",
":",
"return",
"click",
".",
"echo",
"(",
"analyzer_version",
")",
"ctx",
".",
"exit",
"(",
")"
] | Print solver version and exit. | [
"Print",
"solver",
"version",
"and",
"exit",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/cli.py#L37-L42 | train |
thoth-station/solver | thoth/solver/cli.py | cli | def cli(ctx=None, verbose=0):
"""Thoth solver command line interface."""
if ctx:
ctx.auto_envvar_prefix = "THOTH_SOLVER"
if verbose:
_LOG.setLevel(logging.DEBUG)
_LOG.debug("Debug mode is on") | python | def cli(ctx=None, verbose=0):
"""Thoth solver command line interface."""
if ctx:
ctx.auto_envvar_prefix = "THOTH_SOLVER"
if verbose:
_LOG.setLevel(logging.DEBUG)
_LOG.debug("Debug mode is on") | [
"def",
"cli",
"(",
"ctx",
"=",
"None",
",",
"verbose",
"=",
"0",
")",
":",
"if",
"ctx",
":",
"ctx",
".",
"auto_envvar_prefix",
"=",
"\"THOTH_SOLVER\"",
"if",
"verbose",
":",
"_LOG",
".",
"setLevel",
"(",
"logging",
".",
"DEBUG",
")",
"_LOG",
".",
"de... | Thoth solver command line interface. | [
"Thoth",
"solver",
"command",
"line",
"interface",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/cli.py#L56-L64 | train |
thoth-station/solver | thoth/solver/cli.py | pypi | def pypi(
click_ctx,
requirements,
index=None,
python_version=3,
exclude_packages=None,
output=None,
subgraph_check_api=None,
no_transitive=True,
no_pretty=False,
):
"""Manipulate with dependency requirements using PyPI."""
requirements = [requirement.strip() for requirement ... | python | def pypi(
click_ctx,
requirements,
index=None,
python_version=3,
exclude_packages=None,
output=None,
subgraph_check_api=None,
no_transitive=True,
no_pretty=False,
):
"""Manipulate with dependency requirements using PyPI."""
requirements = [requirement.strip() for requirement ... | [
"def",
"pypi",
"(",
"click_ctx",
",",
"requirements",
",",
"index",
"=",
"None",
",",
"python_version",
"=",
"3",
",",
"exclude_packages",
"=",
"None",
",",
"output",
"=",
"None",
",",
"subgraph_check_api",
"=",
"None",
",",
"no_transitive",
"=",
"True",
"... | Manipulate with dependency requirements using PyPI. | [
"Manipulate",
"with",
"dependency",
"requirements",
"using",
"PyPI",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/cli.py#L110-L149 | train |
thoth-station/solver | thoth/solver/python/python.py | _create_entry | def _create_entry(entry: dict, source: Source = None) -> dict:
"""Filter and normalize the output of pipdeptree entry."""
entry["package_name"] = entry["package"].pop("package_name")
entry["package_version"] = entry["package"].pop("installed_version")
if source:
entry["index_url"] = source.url
... | python | def _create_entry(entry: dict, source: Source = None) -> dict:
"""Filter and normalize the output of pipdeptree entry."""
entry["package_name"] = entry["package"].pop("package_name")
entry["package_version"] = entry["package"].pop("installed_version")
if source:
entry["index_url"] = source.url
... | [
"def",
"_create_entry",
"(",
"entry",
":",
"dict",
",",
"source",
":",
"Source",
"=",
"None",
")",
"->",
"dict",
":",
"entry",
"[",
"\"package_name\"",
"]",
"=",
"entry",
"[",
"\"package\"",
"]",
".",
"pop",
"(",
"\"package_name\"",
")",
"entry",
"[",
... | Filter and normalize the output of pipdeptree entry. | [
"Filter",
"and",
"normalize",
"the",
"output",
"of",
"pipdeptree",
"entry",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/python.py#L40-L56 | train |
thoth-station/solver | thoth/solver/python/python.py | _get_environment_details | def _get_environment_details(python_bin: str) -> list:
"""Get information about packages in environment where packages get installed."""
cmd = "{} -m pipdeptree --json".format(python_bin)
output = run_command(cmd, is_json=True).stdout
return [_create_entry(entry) for entry in output] | python | def _get_environment_details(python_bin: str) -> list:
"""Get information about packages in environment where packages get installed."""
cmd = "{} -m pipdeptree --json".format(python_bin)
output = run_command(cmd, is_json=True).stdout
return [_create_entry(entry) for entry in output] | [
"def",
"_get_environment_details",
"(",
"python_bin",
":",
"str",
")",
"->",
"list",
":",
"cmd",
"=",
"\"{} -m pipdeptree --json\"",
".",
"format",
"(",
"python_bin",
")",
"output",
"=",
"run_command",
"(",
"cmd",
",",
"is_json",
"=",
"True",
")",
".",
"stdo... | Get information about packages in environment where packages get installed. | [
"Get",
"information",
"about",
"packages",
"in",
"environment",
"where",
"packages",
"get",
"installed",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/python.py#L59-L63 | train |
thoth-station/solver | thoth/solver/python/python.py | _should_resolve_subgraph | def _should_resolve_subgraph(subgraph_check_api: str, package_name: str, package_version: str, index_url: str) -> bool:
"""Ask the given subgraph check API if the given package in the given version should be included in the resolution.
This subgraph resolving avoidence serves two purposes - we don't need to
... | python | def _should_resolve_subgraph(subgraph_check_api: str, package_name: str, package_version: str, index_url: str) -> bool:
"""Ask the given subgraph check API if the given package in the given version should be included in the resolution.
This subgraph resolving avoidence serves two purposes - we don't need to
... | [
"def",
"_should_resolve_subgraph",
"(",
"subgraph_check_api",
":",
"str",
",",
"package_name",
":",
"str",
",",
"package_version",
":",
"str",
",",
"index_url",
":",
"str",
")",
"->",
"bool",
":",
"_LOGGER",
".",
"info",
"(",
"\"Checking if the given dependency su... | Ask the given subgraph check API if the given package in the given version should be included in the resolution.
This subgraph resolving avoidence serves two purposes - we don't need to
resolve dependency subgraphs that were already analyzed and we also avoid
analyzing of "core" packages (like setuptools) ... | [
"Ask",
"the",
"given",
"subgraph",
"check",
"API",
"if",
"the",
"given",
"package",
"in",
"the",
"given",
"version",
"should",
"be",
"included",
"in",
"the",
"resolution",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/python.py#L66-L99 | train |
thoth-station/solver | thoth/solver/python/python.py | _install_requirement | def _install_requirement(
python_bin: str, package: str, version: str = None, index_url: str = None, clean: bool = True
) -> None:
"""Install requirements specified using suggested pip binary."""
previous_version = _pipdeptree(python_bin, package)
try:
cmd = "{} -m pip install --force-reinstall... | python | def _install_requirement(
python_bin: str, package: str, version: str = None, index_url: str = None, clean: bool = True
) -> None:
"""Install requirements specified using suggested pip binary."""
previous_version = _pipdeptree(python_bin, package)
try:
cmd = "{} -m pip install --force-reinstall... | [
"def",
"_install_requirement",
"(",
"python_bin",
":",
"str",
",",
"package",
":",
"str",
",",
"version",
":",
"str",
"=",
"None",
",",
"index_url",
":",
"str",
"=",
"None",
",",
"clean",
":",
"bool",
"=",
"True",
")",
"->",
"None",
":",
"previous_vers... | Install requirements specified using suggested pip binary. | [
"Install",
"requirements",
"specified",
"using",
"suggested",
"pip",
"binary",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/python.py#L103-L155 | train |
thoth-station/solver | thoth/solver/python/python.py | _pipdeptree | def _pipdeptree(python_bin, package_name: str = None, warn: bool = False) -> typing.Optional[dict]:
"""Get pip dependency tree by executing pipdeptree tool."""
cmd = "{} -m pipdeptree --json".format(python_bin)
_LOGGER.debug("Obtaining pip dependency tree using: %r", cmd)
output = run_command(cmd, is_j... | python | def _pipdeptree(python_bin, package_name: str = None, warn: bool = False) -> typing.Optional[dict]:
"""Get pip dependency tree by executing pipdeptree tool."""
cmd = "{} -m pipdeptree --json".format(python_bin)
_LOGGER.debug("Obtaining pip dependency tree using: %r", cmd)
output = run_command(cmd, is_j... | [
"def",
"_pipdeptree",
"(",
"python_bin",
",",
"package_name",
":",
"str",
"=",
"None",
",",
"warn",
":",
"bool",
"=",
"False",
")",
"->",
"typing",
".",
"Optional",
"[",
"dict",
"]",
":",
"cmd",
"=",
"\"{} -m pipdeptree --json\"",
".",
"format",
"(",
"py... | Get pip dependency tree by executing pipdeptree tool. | [
"Get",
"pip",
"dependency",
"tree",
"by",
"executing",
"pipdeptree",
"tool",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/python.py#L158-L177 | train |
thoth-station/solver | thoth/solver/python/python.py | _get_dependency_specification | def _get_dependency_specification(dep_spec: typing.List[tuple]) -> str:
"""Get string representation of dependency specification as provided by PythonDependencyParser."""
return ",".join(dep_range[0] + dep_range[1] for dep_range in dep_spec) | python | def _get_dependency_specification(dep_spec: typing.List[tuple]) -> str:
"""Get string representation of dependency specification as provided by PythonDependencyParser."""
return ",".join(dep_range[0] + dep_range[1] for dep_range in dep_spec) | [
"def",
"_get_dependency_specification",
"(",
"dep_spec",
":",
"typing",
".",
"List",
"[",
"tuple",
"]",
")",
"->",
"str",
":",
"return",
"\",\"",
".",
"join",
"(",
"dep_range",
"[",
"0",
"]",
"+",
"dep_range",
"[",
"1",
"]",
"for",
"dep_range",
"in",
"... | Get string representation of dependency specification as provided by PythonDependencyParser. | [
"Get",
"string",
"representation",
"of",
"dependency",
"specification",
"as",
"provided",
"by",
"PythonDependencyParser",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/python.py#L180-L182 | train |
thoth-station/solver | thoth/solver/python/python.py | resolve | def resolve(
requirements: typing.List[str],
index_urls: list = None,
python_version: int = 3,
exclude_packages: set = None,
transitive: bool = True,
subgraph_check_api: str = None,
) -> dict:
"""Resolve given requirements for the given Python version."""
assert python_version in (2, 3),... | python | def resolve(
requirements: typing.List[str],
index_urls: list = None,
python_version: int = 3,
exclude_packages: set = None,
transitive: bool = True,
subgraph_check_api: str = None,
) -> dict:
"""Resolve given requirements for the given Python version."""
assert python_version in (2, 3),... | [
"def",
"resolve",
"(",
"requirements",
":",
"typing",
".",
"List",
"[",
"str",
"]",
",",
"index_urls",
":",
"list",
"=",
"None",
",",
"python_version",
":",
"int",
"=",
"3",
",",
"exclude_packages",
":",
"set",
"=",
"None",
",",
"transitive",
":",
"boo... | Resolve given requirements for the given Python version. | [
"Resolve",
"given",
"requirements",
"for",
"the",
"given",
"Python",
"version",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/python.py#L356-L401 | train |
thoth-station/solver | thoth/solver/python/python_solver.py | PythonReleasesFetcher.fetch_releases | def fetch_releases(self, package_name):
"""Fetch package and index_url for a package_name."""
package_name = self.source.normalize_package_name(package_name)
releases = self.source.get_package_versions(package_name)
releases_with_index_url = [(item, self.index_url) for item in releases]
... | python | def fetch_releases(self, package_name):
"""Fetch package and index_url for a package_name."""
package_name = self.source.normalize_package_name(package_name)
releases = self.source.get_package_versions(package_name)
releases_with_index_url = [(item, self.index_url) for item in releases]
... | [
"def",
"fetch_releases",
"(",
"self",
",",
"package_name",
")",
":",
"package_name",
"=",
"self",
".",
"source",
".",
"normalize_package_name",
"(",
"package_name",
")",
"releases",
"=",
"self",
".",
"source",
".",
"get_package_versions",
"(",
"package_name",
")... | Fetch package and index_url for a package_name. | [
"Fetch",
"package",
"and",
"index_url",
"for",
"a",
"package_name",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/python_solver.py#L49-L54 | train |
thoth-station/solver | thoth/solver/python/python_solver.py | PythonDependencyParser.parse_python | def parse_python(spec): # Ignore PyDocStyleBear
"""Parse PyPI specification of a single dependency.
:param spec: str, for example "Django>=1.5,<1.8"
:return: [Django [[('>=', '1.5'), ('<', '1.8')]]]
"""
def _extract_op_version(spec):
# https://www.python.org/dev/pe... | python | def parse_python(spec): # Ignore PyDocStyleBear
"""Parse PyPI specification of a single dependency.
:param spec: str, for example "Django>=1.5,<1.8"
:return: [Django [[('>=', '1.5'), ('<', '1.8')]]]
"""
def _extract_op_version(spec):
# https://www.python.org/dev/pe... | [
"def",
"parse_python",
"(",
"spec",
")",
":",
"# Ignore PyDocStyleBear",
"def",
"_extract_op_version",
"(",
"spec",
")",
":",
"# https://www.python.org/dev/peps/pep-0440/#compatible-release",
"if",
"spec",
".",
"operator",
"==",
"\"~=\"",
":",
"version",
"=",
"spec",
... | Parse PyPI specification of a single dependency.
:param spec: str, for example "Django>=1.5,<1.8"
:return: [Django [[('>=', '1.5'), ('<', '1.8')]]] | [
"Parse",
"PyPI",
"specification",
"of",
"a",
"single",
"dependency",
"."
] | de9bd6e744cb4d5f70320ba77d6875ccb8b876c4 | https://github.com/thoth-station/solver/blob/de9bd6e744cb4d5f70320ba77d6875ccb8b876c4/thoth/solver/python/python_solver.py#L66-L122 | train |
floyernick/fleep-py | fleep/__init__.py | get | def get(obj):
"""
Determines file format and picks suitable file types, extensions and MIME types
Takes:
obj (bytes) -> byte sequence (128 bytes are enough)
Returns:
(<class 'fleep.Info'>) -> Class instance
"""
if not isinstance(obj, bytes):
raise TypeError("object typ... | python | def get(obj):
"""
Determines file format and picks suitable file types, extensions and MIME types
Takes:
obj (bytes) -> byte sequence (128 bytes are enough)
Returns:
(<class 'fleep.Info'>) -> Class instance
"""
if not isinstance(obj, bytes):
raise TypeError("object typ... | [
"def",
"get",
"(",
"obj",
")",
":",
"if",
"not",
"isinstance",
"(",
"obj",
",",
"bytes",
")",
":",
"raise",
"TypeError",
"(",
"\"object type must be bytes\"",
")",
"info",
"=",
"{",
"\"type\"",
":",
"dict",
"(",
")",
",",
"\"extension\"",
":",
"dict",
... | Determines file format and picks suitable file types, extensions and MIME types
Takes:
obj (bytes) -> byte sequence (128 bytes are enough)
Returns:
(<class 'fleep.Info'>) -> Class instance | [
"Determines",
"file",
"format",
"and",
"picks",
"suitable",
"file",
"types",
"extensions",
"and",
"MIME",
"types"
] | 994bc2c274482d80ab13d89d8f7343eb316d3e44 | https://github.com/floyernick/fleep-py/blob/994bc2c274482d80ab13d89d8f7343eb316d3e44/fleep/__init__.py#L50-L82 | train |
scikit-tda/persim | persim/plot.py | bottleneck_matching | def bottleneck_matching(I1, I2, matchidx, D, labels=["dgm1", "dgm2"], ax=None):
""" Visualize bottleneck matching between two diagrams
Parameters
===========
I1: array
A diagram
I2: array
A diagram
matchidx: tuples of matched indices
if input `matching=True`, then retur... | python | def bottleneck_matching(I1, I2, matchidx, D, labels=["dgm1", "dgm2"], ax=None):
""" Visualize bottleneck matching between two diagrams
Parameters
===========
I1: array
A diagram
I2: array
A diagram
matchidx: tuples of matched indices
if input `matching=True`, then retur... | [
"def",
"bottleneck_matching",
"(",
"I1",
",",
"I2",
",",
"matchidx",
",",
"D",
",",
"labels",
"=",
"[",
"\"dgm1\"",
",",
"\"dgm2\"",
"]",
",",
"ax",
"=",
"None",
")",
":",
"plot_diagrams",
"(",
"[",
"I1",
",",
"I2",
"]",
",",
"labels",
"=",
"labels... | Visualize bottleneck matching between two diagrams
Parameters
===========
I1: array
A diagram
I2: array
A diagram
matchidx: tuples of matched indices
if input `matching=True`, then return matching
D: array
cross-similarity matrix
labels: list of strings
... | [
"Visualize",
"bottleneck",
"matching",
"between",
"two",
"diagrams"
] | f234f543058bdedb9729bf8c4a90da41e57954e0 | https://github.com/scikit-tda/persim/blob/f234f543058bdedb9729bf8c4a90da41e57954e0/persim/plot.py#L9-L53 | train |
scikit-tda/persim | persim/images.py | PersImage.transform | def transform(self, diagrams):
""" Convert diagram or list of diagrams to a persistence image.
Parameters
-----------
diagrams : list of or singleton diagram, list of pairs. [(birth, death)]
Persistence diagrams to be converted to persistence images. It is assumed they are ... | python | def transform(self, diagrams):
""" Convert diagram or list of diagrams to a persistence image.
Parameters
-----------
diagrams : list of or singleton diagram, list of pairs. [(birth, death)]
Persistence diagrams to be converted to persistence images. It is assumed they are ... | [
"def",
"transform",
"(",
"self",
",",
"diagrams",
")",
":",
"# if diagram is empty, return empty image",
"if",
"len",
"(",
"diagrams",
")",
"==",
"0",
":",
"return",
"np",
".",
"zeros",
"(",
"(",
"self",
".",
"nx",
",",
"self",
".",
"ny",
")",
")",
"# ... | Convert diagram or list of diagrams to a persistence image.
Parameters
-----------
diagrams : list of or singleton diagram, list of pairs. [(birth, death)]
Persistence diagrams to be converted to persistence images. It is assumed they are in (birth, death) format. Can input a list ... | [
"Convert",
"diagram",
"or",
"list",
"of",
"diagrams",
"to",
"a",
"persistence",
"image",
"."
] | f234f543058bdedb9729bf8c4a90da41e57954e0 | https://github.com/scikit-tda/persim/blob/f234f543058bdedb9729bf8c4a90da41e57954e0/persim/images.py#L72-L110 | train |
scikit-tda/persim | persim/images.py | PersImage.weighting | def weighting(self, landscape=None):
""" Define a weighting function,
for stability results to hold, the function must be 0 at y=0.
"""
# TODO: Implement a logistic function
# TODO: use self.weighting_type to choose function
if landscape is not None:
... | python | def weighting(self, landscape=None):
""" Define a weighting function,
for stability results to hold, the function must be 0 at y=0.
"""
# TODO: Implement a logistic function
# TODO: use self.weighting_type to choose function
if landscape is not None:
... | [
"def",
"weighting",
"(",
"self",
",",
"landscape",
"=",
"None",
")",
":",
"# TODO: Implement a logistic function",
"# TODO: use self.weighting_type to choose function",
"if",
"landscape",
"is",
"not",
"None",
":",
"if",
"len",
"(",
"landscape",
")",
">",
"0",
":",
... | Define a weighting function,
for stability results to hold, the function must be 0 at y=0. | [
"Define",
"a",
"weighting",
"function",
"for",
"stability",
"results",
"to",
"hold",
"the",
"function",
"must",
"be",
"0",
"at",
"y",
"=",
"0",
"."
] | f234f543058bdedb9729bf8c4a90da41e57954e0 | https://github.com/scikit-tda/persim/blob/f234f543058bdedb9729bf8c4a90da41e57954e0/persim/images.py#L143-L178 | train |
scikit-tda/persim | persim/images.py | PersImage.show | def show(self, imgs, ax=None):
""" Visualize the persistence image
"""
ax = ax or plt.gca()
if type(imgs) is not list:
imgs = [imgs]
for i, img in enumerate(imgs):
ax.imshow(img, cmap=plt.get_cmap("plasma"))
ax.axis("off") | python | def show(self, imgs, ax=None):
""" Visualize the persistence image
"""
ax = ax or plt.gca()
if type(imgs) is not list:
imgs = [imgs]
for i, img in enumerate(imgs):
ax.imshow(img, cmap=plt.get_cmap("plasma"))
ax.axis("off") | [
"def",
"show",
"(",
"self",
",",
"imgs",
",",
"ax",
"=",
"None",
")",
":",
"ax",
"=",
"ax",
"or",
"plt",
".",
"gca",
"(",
")",
"if",
"type",
"(",
"imgs",
")",
"is",
"not",
"list",
":",
"imgs",
"=",
"[",
"imgs",
"]",
"for",
"i",
",",
"img",
... | Visualize the persistence image | [
"Visualize",
"the",
"persistence",
"image"
] | f234f543058bdedb9729bf8c4a90da41e57954e0 | https://github.com/scikit-tda/persim/blob/f234f543058bdedb9729bf8c4a90da41e57954e0/persim/images.py#L200-L212 | train |
pivotal-energy-solutions/django-datatable-view | datatableview/utils.py | resolve_orm_path | def resolve_orm_path(model, orm_path):
"""
Follows the queryset-style query path of ``orm_path`` starting from ``model`` class. If the
path ends up referring to a bad field name, ``django.db.models.fields.FieldDoesNotExist`` will
be raised.
"""
bits = orm_path.split('__')
endpoint_model =... | python | def resolve_orm_path(model, orm_path):
"""
Follows the queryset-style query path of ``orm_path`` starting from ``model`` class. If the
path ends up referring to a bad field name, ``django.db.models.fields.FieldDoesNotExist`` will
be raised.
"""
bits = orm_path.split('__')
endpoint_model =... | [
"def",
"resolve_orm_path",
"(",
"model",
",",
"orm_path",
")",
":",
"bits",
"=",
"orm_path",
".",
"split",
"(",
"'__'",
")",
"endpoint_model",
"=",
"reduce",
"(",
"get_model_at_related_field",
",",
"[",
"model",
"]",
"+",
"bits",
"[",
":",
"-",
"1",
"]",... | Follows the queryset-style query path of ``orm_path`` starting from ``model`` class. If the
path ends up referring to a bad field name, ``django.db.models.fields.FieldDoesNotExist`` will
be raised. | [
"Follows",
"the",
"queryset",
"-",
"style",
"query",
"path",
"of",
"orm_path",
"starting",
"from",
"model",
"class",
".",
"If",
"the",
"path",
"ends",
"up",
"referring",
"to",
"a",
"bad",
"field",
"name",
"django",
".",
"db",
".",
"models",
".",
"fields"... | 00b77a9b5051c34e258c51b06c020e92edf15034 | https://github.com/pivotal-energy-solutions/django-datatable-view/blob/00b77a9b5051c34e258c51b06c020e92edf15034/datatableview/utils.py#L56-L70 | train |
pivotal-energy-solutions/django-datatable-view | datatableview/utils.py | get_model_at_related_field | def get_model_at_related_field(model, attr):
"""
Looks up ``attr`` as a field of ``model`` and returns the related model class. If ``attr`` is
not a relationship field, ``ValueError`` is raised.
"""
field = model._meta.get_field(attr)
if hasattr(field, 'related_model'):
return field.... | python | def get_model_at_related_field(model, attr):
"""
Looks up ``attr`` as a field of ``model`` and returns the related model class. If ``attr`` is
not a relationship field, ``ValueError`` is raised.
"""
field = model._meta.get_field(attr)
if hasattr(field, 'related_model'):
return field.... | [
"def",
"get_model_at_related_field",
"(",
"model",
",",
"attr",
")",
":",
"field",
"=",
"model",
".",
"_meta",
".",
"get_field",
"(",
"attr",
")",
"if",
"hasattr",
"(",
"field",
",",
"'related_model'",
")",
":",
"return",
"field",
".",
"related_model",
"ra... | Looks up ``attr`` as a field of ``model`` and returns the related model class. If ``attr`` is
not a relationship field, ``ValueError`` is raised. | [
"Looks",
"up",
"attr",
"as",
"a",
"field",
"of",
"model",
"and",
"returns",
"the",
"related",
"model",
"class",
".",
"If",
"attr",
"is",
"not",
"a",
"relationship",
"field",
"ValueError",
"is",
"raised",
"."
] | 00b77a9b5051c34e258c51b06c020e92edf15034 | https://github.com/pivotal-energy-solutions/django-datatable-view/blob/00b77a9b5051c34e258c51b06c020e92edf15034/datatableview/utils.py#L72-L88 | train |
pivotal-energy-solutions/django-datatable-view | datatableview/utils.py | contains_plural_field | def contains_plural_field(model, fields):
""" Returns a boolean indicating if ``fields`` contains a relationship to multiple items. """
source_model = model
for orm_path in fields:
model = source_model
bits = orm_path.lstrip('+-').split('__')
for bit in bits[:-1]:
field =... | python | def contains_plural_field(model, fields):
""" Returns a boolean indicating if ``fields`` contains a relationship to multiple items. """
source_model = model
for orm_path in fields:
model = source_model
bits = orm_path.lstrip('+-').split('__')
for bit in bits[:-1]:
field =... | [
"def",
"contains_plural_field",
"(",
"model",
",",
"fields",
")",
":",
"source_model",
"=",
"model",
"for",
"orm_path",
"in",
"fields",
":",
"model",
"=",
"source_model",
"bits",
"=",
"orm_path",
".",
"lstrip",
"(",
"'+-'",
")",
".",
"split",
"(",
"'__'",
... | Returns a boolean indicating if ``fields`` contains a relationship to multiple items. | [
"Returns",
"a",
"boolean",
"indicating",
"if",
"fields",
"contains",
"a",
"relationship",
"to",
"multiple",
"items",
"."
] | 00b77a9b5051c34e258c51b06c020e92edf15034 | https://github.com/pivotal-energy-solutions/django-datatable-view/blob/00b77a9b5051c34e258c51b06c020e92edf15034/datatableview/utils.py#L97-L108 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.