partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | Object.connect | connect(detailed_signal: str, handler: function, *args) -> handler_id: int
The connect() method adds a function or method (handler) to the end
of the list of signal handlers for the named detailed_signal but
before the default class signal handler. An optional set of
parameters may be s... | pgi/obj.py | def connect(self, detailed_signal, handler, *args):
"""connect(detailed_signal: str, handler: function, *args) -> handler_id: int
The connect() method adds a function or method (handler) to the end
of the list of signal handlers for the named detailed_signal but
before the default class... | def connect(self, detailed_signal, handler, *args):
"""connect(detailed_signal: str, handler: function, *args) -> handler_id: int
The connect() method adds a function or method (handler) to the end
of the list of signal handlers for the named detailed_signal but
before the default class... | [
"connect",
"(",
"detailed_signal",
":",
"str",
"handler",
":",
"function",
"*",
"args",
")",
"-",
">",
"handler_id",
":",
"int"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/obj.py#L127-L156 | [
"def",
"connect",
"(",
"self",
",",
"detailed_signal",
",",
"handler",
",",
"*",
"args",
")",
":",
"return",
"self",
".",
"__connect",
"(",
"0",
",",
"detailed_signal",
",",
"handler",
",",
"*",
"args",
")"
] | 2090435df6241a15ec2a78379a36b738b728652c |
train | Object.connect_after | connect_after(detailed_signal: str, handler: function, *args) -> handler_id: int
The connect_after() method is similar to the connect() method
except that the handler is added to the signal handler list after
the default class signal handler. Otherwise the details of handler
definition ... | pgi/obj.py | def connect_after(self, detailed_signal, handler, *args):
"""connect_after(detailed_signal: str, handler: function, *args) -> handler_id: int
The connect_after() method is similar to the connect() method
except that the handler is added to the signal handler list after
the default class... | def connect_after(self, detailed_signal, handler, *args):
"""connect_after(detailed_signal: str, handler: function, *args) -> handler_id: int
The connect_after() method is similar to the connect() method
except that the handler is added to the signal handler list after
the default class... | [
"connect_after",
"(",
"detailed_signal",
":",
"str",
"handler",
":",
"function",
"*",
"args",
")",
"-",
">",
"handler_id",
":",
"int"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/obj.py#L158-L168 | [
"def",
"connect_after",
"(",
"self",
",",
"detailed_signal",
",",
"handler",
",",
"*",
"args",
")",
":",
"flags",
"=",
"GConnectFlags",
".",
"CONNECT_AFTER",
"return",
"self",
".",
"__connect",
"(",
"flags",
",",
"detailed_signal",
",",
"handler",
",",
"*",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | GIBaseInfo._take_ownership | Make the Python instance take ownership of the GIBaseInfo. i.e.
unref if the python instance gets gc'ed. | pgi/clib/gir/gibaseinfo.py | def _take_ownership(self):
"""Make the Python instance take ownership of the GIBaseInfo. i.e.
unref if the python instance gets gc'ed.
"""
if self:
ptr = cast(self.value, GIBaseInfo)
_UnrefFinalizer.track(self, ptr)
self.__owns = True | def _take_ownership(self):
"""Make the Python instance take ownership of the GIBaseInfo. i.e.
unref if the python instance gets gc'ed.
"""
if self:
ptr = cast(self.value, GIBaseInfo)
_UnrefFinalizer.track(self, ptr)
self.__owns = True | [
"Make",
"the",
"Python",
"instance",
"take",
"ownership",
"of",
"the",
"GIBaseInfo",
".",
"i",
".",
"e",
".",
"unref",
"if",
"the",
"python",
"instance",
"gets",
"gc",
"ed",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/clib/gir/gibaseinfo.py#L61-L69 | [
"def",
"_take_ownership",
"(",
"self",
")",
":",
"if",
"self",
":",
"ptr",
"=",
"cast",
"(",
"self",
".",
"value",
",",
"GIBaseInfo",
")",
"_UnrefFinalizer",
".",
"track",
"(",
"self",
",",
"ptr",
")",
"self",
".",
"__owns",
"=",
"True"
] | 2090435df6241a15ec2a78379a36b738b728652c |
train | GIBaseInfo._cast | Casts a GIBaseInfo instance to the right sub type.
The original GIBaseInfo can't have ownership.
Will take ownership. | pgi/clib/gir/gibaseinfo.py | def _cast(cls, base_info, take_ownership=True):
"""Casts a GIBaseInfo instance to the right sub type.
The original GIBaseInfo can't have ownership.
Will take ownership.
"""
type_value = base_info.type.value
try:
new_obj = cast(base_info, cls.__types[type_val... | def _cast(cls, base_info, take_ownership=True):
"""Casts a GIBaseInfo instance to the right sub type.
The original GIBaseInfo can't have ownership.
Will take ownership.
"""
type_value = base_info.type.value
try:
new_obj = cast(base_info, cls.__types[type_val... | [
"Casts",
"a",
"GIBaseInfo",
"instance",
"to",
"the",
"right",
"sub",
"type",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/clib/gir/gibaseinfo.py#L72-L89 | [
"def",
"_cast",
"(",
"cls",
",",
"base_info",
",",
"take_ownership",
"=",
"True",
")",
":",
"type_value",
"=",
"base_info",
".",
"type",
".",
"value",
"try",
":",
"new_obj",
"=",
"cast",
"(",
"base_info",
",",
"cls",
".",
"__types",
"[",
"type_value",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | decode_return | Decodes the return value of it isn't None | pgi/util.py | def decode_return(codec="ascii"):
"""Decodes the return value of it isn't None"""
def outer(f):
def wrap(*args, **kwargs):
res = f(*args, **kwargs)
if res is not None:
return res.decode(codec)
return res
return wrap
return outer | def decode_return(codec="ascii"):
"""Decodes the return value of it isn't None"""
def outer(f):
def wrap(*args, **kwargs):
res = f(*args, **kwargs)
if res is not None:
return res.decode(codec)
return res
return wrap
return outer | [
"Decodes",
"the",
"return",
"value",
"of",
"it",
"isn",
"t",
"None"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/util.py#L27-L37 | [
"def",
"decode_return",
"(",
"codec",
"=",
"\"ascii\"",
")",
":",
"def",
"outer",
"(",
"f",
")",
":",
"def",
"wrap",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"res",
"=",
"f",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"... | 2090435df6241a15ec2a78379a36b738b728652c |
train | load_ctypes_library | Takes a library name and calls find_library in case loading fails,
since some girs don't include the real .so name.
Raises OSError like LoadLibrary if loading fails.
e.g. javascriptcoregtk-3.0 should be libjavascriptcoregtk-3.0.so on unix | pgi/util.py | def load_ctypes_library(name):
"""Takes a library name and calls find_library in case loading fails,
since some girs don't include the real .so name.
Raises OSError like LoadLibrary if loading fails.
e.g. javascriptcoregtk-3.0 should be libjavascriptcoregtk-3.0.so on unix
"""
try:
ret... | def load_ctypes_library(name):
"""Takes a library name and calls find_library in case loading fails,
since some girs don't include the real .so name.
Raises OSError like LoadLibrary if loading fails.
e.g. javascriptcoregtk-3.0 should be libjavascriptcoregtk-3.0.so on unix
"""
try:
ret... | [
"Takes",
"a",
"library",
"name",
"and",
"calls",
"find_library",
"in",
"case",
"loading",
"fails",
"since",
"some",
"girs",
"don",
"t",
"include",
"the",
"real",
".",
"so",
"name",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/util.py#L50-L65 | [
"def",
"load_ctypes_library",
"(",
"name",
")",
":",
"try",
":",
"return",
"cdll",
".",
"LoadLibrary",
"(",
"name",
")",
"except",
"OSError",
":",
"name",
"=",
"find_library",
"(",
"name",
")",
"if",
"name",
"is",
"None",
":",
"raise",
"return",
"cdll",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | escape_identifier | Escape partial C identifiers so they can be used as
attributes/arguments | pgi/util.py | def escape_identifier(text, reg=KWD_RE):
"""Escape partial C identifiers so they can be used as
attributes/arguments"""
# see http://docs.python.org/reference/lexical_analysis.html#identifiers
if not text:
return "_"
if text[0].isdigit():
text = "_" + text
return reg.sub(r"\1_",... | def escape_identifier(text, reg=KWD_RE):
"""Escape partial C identifiers so they can be used as
attributes/arguments"""
# see http://docs.python.org/reference/lexical_analysis.html#identifiers
if not text:
return "_"
if text[0].isdigit():
text = "_" + text
return reg.sub(r"\1_",... | [
"Escape",
"partial",
"C",
"identifiers",
"so",
"they",
"can",
"be",
"used",
"as",
"attributes",
"/",
"arguments"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/util.py#L226-L235 | [
"def",
"escape_identifier",
"(",
"text",
",",
"reg",
"=",
"KWD_RE",
")",
":",
"# see http://docs.python.org/reference/lexical_analysis.html#identifiers",
"if",
"not",
"text",
":",
"return",
"\"_\"",
"if",
"text",
"[",
"0",
"]",
".",
"isdigit",
"(",
")",
":",
"te... | 2090435df6241a15ec2a78379a36b738b728652c |
train | cache_return | Cache the return value of a function without arguments | pgi/util.py | def cache_return(func):
"""Cache the return value of a function without arguments"""
_cache = []
def wrap():
if not _cache:
_cache.append(func())
return _cache[0]
return wrap | def cache_return(func):
"""Cache the return value of a function without arguments"""
_cache = []
def wrap():
if not _cache:
_cache.append(func())
return _cache[0]
return wrap | [
"Cache",
"the",
"return",
"value",
"of",
"a",
"function",
"without",
"arguments"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/util.py#L263-L272 | [
"def",
"cache_return",
"(",
"func",
")",
":",
"_cache",
"=",
"[",
"]",
"def",
"wrap",
"(",
")",
":",
"if",
"not",
"_cache",
":",
"_cache",
".",
"append",
"(",
"func",
"(",
")",
")",
"return",
"_cache",
"[",
"0",
"]",
"return",
"wrap"
] | 2090435df6241a15ec2a78379a36b738b728652c |
train | InfoIterWrapper.lookup_name_fast | Might return a struct | pgi/util.py | def lookup_name_fast(self, name):
"""Might return a struct"""
if name in self.__names:
return self.__names[name]
count = self.__get_count_cached()
lo = 0
hi = count
while lo < hi:
mid = (lo + hi) // 2
if self.__get_name_cached(mid) < ... | def lookup_name_fast(self, name):
"""Might return a struct"""
if name in self.__names:
return self.__names[name]
count = self.__get_count_cached()
lo = 0
hi = count
while lo < hi:
mid = (lo + hi) // 2
if self.__get_name_cached(mid) < ... | [
"Might",
"return",
"a",
"struct"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/util.py#L115-L132 | [
"def",
"lookup_name_fast",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"in",
"self",
".",
"__names",
":",
"return",
"self",
".",
"__names",
"[",
"name",
"]",
"count",
"=",
"self",
".",
"__get_count_cached",
"(",
")",
"lo",
"=",
"0",
"hi",
"=",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | InfoIterWrapper.lookup_name_slow | Returns a struct if one exists | pgi/util.py | def lookup_name_slow(self, name):
"""Returns a struct if one exists"""
for index in xrange(self.__get_count_cached()):
if self.__get_name_cached(index) == name:
return self.__get_info_cached(index) | def lookup_name_slow(self, name):
"""Returns a struct if one exists"""
for index in xrange(self.__get_count_cached()):
if self.__get_name_cached(index) == name:
return self.__get_info_cached(index) | [
"Returns",
"a",
"struct",
"if",
"one",
"exists"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/util.py#L134-L139 | [
"def",
"lookup_name_slow",
"(",
"self",
",",
"name",
")",
":",
"for",
"index",
"in",
"xrange",
"(",
"self",
".",
"__get_count_cached",
"(",
")",
")",
":",
"if",
"self",
".",
"__get_name_cached",
"(",
"index",
")",
"==",
"name",
":",
"return",
"self",
"... | 2090435df6241a15ec2a78379a36b738b728652c |
train | InfoIterWrapper.lookup_name | Returns a struct if one exists | pgi/util.py | def lookup_name(self, name):
"""Returns a struct if one exists"""
try:
info = self._get_by_name(self._source, name)
except NotImplementedError:
pass
else:
if info:
return info
return
info = self.lookup_name_fast(na... | def lookup_name(self, name):
"""Returns a struct if one exists"""
try:
info = self._get_by_name(self._source, name)
except NotImplementedError:
pass
else:
if info:
return info
return
info = self.lookup_name_fast(na... | [
"Returns",
"a",
"struct",
"if",
"one",
"exists"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/util.py#L141-L156 | [
"def",
"lookup_name",
"(",
"self",
",",
"name",
")",
":",
"try",
":",
"info",
"=",
"self",
".",
"_get_by_name",
"(",
"self",
".",
"_source",
",",
"name",
")",
"except",
"NotImplementedError",
":",
"pass",
"else",
":",
"if",
"info",
":",
"return",
"info... | 2090435df6241a15ec2a78379a36b738b728652c |
train | ResultTuple._new_type | Creates a new class similar to namedtuple.
Pass a list of field names or None for no field name.
>>> x = ResultTuple._new_type([None, "bar"])
>>> x((1, 3))
ResultTuple(1, bar=3) | pgi/util.py | def _new_type(cls, args):
"""Creates a new class similar to namedtuple.
Pass a list of field names or None for no field name.
>>> x = ResultTuple._new_type([None, "bar"])
>>> x((1, 3))
ResultTuple(1, bar=3)
"""
fformat = ["%r" if f is None else "%s=%%r" % f for... | def _new_type(cls, args):
"""Creates a new class similar to namedtuple.
Pass a list of field names or None for no field name.
>>> x = ResultTuple._new_type([None, "bar"])
>>> x((1, 3))
ResultTuple(1, bar=3)
"""
fformat = ["%r" if f is None else "%s=%%r" % f for... | [
"Creates",
"a",
"new",
"class",
"similar",
"to",
"namedtuple",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/util.py#L320-L342 | [
"def",
"_new_type",
"(",
"cls",
",",
"args",
")",
":",
"fformat",
"=",
"[",
"\"%r\"",
"if",
"f",
"is",
"None",
"else",
"\"%s=%%r\"",
"%",
"f",
"for",
"f",
"in",
"args",
"]",
"fformat",
"=",
"\"(%s)\"",
"%",
"\", \"",
".",
"join",
"(",
"fformat",
")... | 2090435df6241a15ec2a78379a36b738b728652c |
train | signal_list_names | Returns a list of signal names for the given type
:param type\\_:
:type type\\_: :obj:`GObject.GType`
:returns: A list of signal names
:rtype: :obj:`list` | pgi/overrides/GObject.py | def signal_list_names(type_):
"""Returns a list of signal names for the given type
:param type\\_:
:type type\\_: :obj:`GObject.GType`
:returns: A list of signal names
:rtype: :obj:`list`
"""
ids = signal_list_ids(type_)
return tuple(GObjectModule.signal_name(i) for i in ids) | def signal_list_names(type_):
"""Returns a list of signal names for the given type
:param type\\_:
:type type\\_: :obj:`GObject.GType`
:returns: A list of signal names
:rtype: :obj:`list`
"""
ids = signal_list_ids(type_)
return tuple(GObjectModule.signal_name(i) for i in ids) | [
"Returns",
"a",
"list",
"of",
"signal",
"names",
"for",
"the",
"given",
"type"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/overrides/GObject.py#L392-L402 | [
"def",
"signal_list_names",
"(",
"type_",
")",
":",
"ids",
"=",
"signal_list_ids",
"(",
"type_",
")",
"return",
"tuple",
"(",
"GObjectModule",
".",
"signal_name",
"(",
"i",
")",
"for",
"i",
"in",
"ids",
")"
] | 2090435df6241a15ec2a78379a36b738b728652c |
train | signal_handler_block | Blocks the signal handler from being invoked until
handler_unblock() is called.
:param GObject.Object obj:
Object instance to block handlers for.
:param int handler_id:
Id of signal to block.
:returns:
A context manager which optionally can be used to
automatically unblo... | pgi/overrides/GObject.py | def signal_handler_block(obj, handler_id):
"""Blocks the signal handler from being invoked until
handler_unblock() is called.
:param GObject.Object obj:
Object instance to block handlers for.
:param int handler_id:
Id of signal to block.
:returns:
A context manager which opt... | def signal_handler_block(obj, handler_id):
"""Blocks the signal handler from being invoked until
handler_unblock() is called.
:param GObject.Object obj:
Object instance to block handlers for.
:param int handler_id:
Id of signal to block.
:returns:
A context manager which opt... | [
"Blocks",
"the",
"signal",
"handler",
"from",
"being",
"invoked",
"until",
"handler_unblock",
"()",
"is",
"called",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/overrides/GObject.py#L458-L476 | [
"def",
"signal_handler_block",
"(",
"obj",
",",
"handler_id",
")",
":",
"GObjectModule",
".",
"signal_handler_block",
"(",
"obj",
",",
"handler_id",
")",
"return",
"_HandlerBlockManager",
"(",
"obj",
",",
"handler_id",
")"
] | 2090435df6241a15ec2a78379a36b738b728652c |
train | signal_parse_name | Parse a detailed signal name into (signal_id, detail).
:param str detailed_signal:
Signal name which can include detail.
For example: "notify:prop_name"
:returns:
Tuple of (signal_id, detail)
:raises ValueError:
If the given signal is unknown. | pgi/overrides/GObject.py | def signal_parse_name(detailed_signal, itype, force_detail_quark):
"""Parse a detailed signal name into (signal_id, detail).
:param str detailed_signal:
Signal name which can include detail.
For example: "notify:prop_name"
:returns:
Tuple of (signal_id, detail)
:raises ValueErro... | def signal_parse_name(detailed_signal, itype, force_detail_quark):
"""Parse a detailed signal name into (signal_id, detail).
:param str detailed_signal:
Signal name which can include detail.
For example: "notify:prop_name"
:returns:
Tuple of (signal_id, detail)
:raises ValueErro... | [
"Parse",
"a",
"detailed",
"signal",
"name",
"into",
"(",
"signal_id",
"detail",
")",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/overrides/GObject.py#L481-L497 | [
"def",
"signal_parse_name",
"(",
"detailed_signal",
",",
"itype",
",",
"force_detail_quark",
")",
":",
"res",
",",
"signal_id",
",",
"detail",
"=",
"GObjectModule",
".",
"signal_parse_name",
"(",
"detailed_signal",
",",
"itype",
",",
"force_detail_quark",
")",
"if... | 2090435df6241a15ec2a78379a36b738b728652c |
train | find_library | cached: Return a new instance
internal: return a shared instance that's not the ctypes cached one | pgi/clib/_utils.py | def find_library(name, cached=True, internal=True):
"""
cached: Return a new instance
internal: return a shared instance that's not the ctypes cached one
"""
# a new one
if not cached:
return cdll.LoadLibrary(_so_mapping[name])
# from the shared internal set or a new one
... | def find_library(name, cached=True, internal=True):
"""
cached: Return a new instance
internal: return a shared instance that's not the ctypes cached one
"""
# a new one
if not cached:
return cdll.LoadLibrary(_so_mapping[name])
# from the shared internal set or a new one
... | [
"cached",
":",
"Return",
"a",
"new",
"instance",
"internal",
":",
"return",
"a",
"shared",
"instance",
"that",
"s",
"not",
"the",
"ctypes",
"cached",
"one"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/clib/_utils.py#L86-L103 | [
"def",
"find_library",
"(",
"name",
",",
"cached",
"=",
"True",
",",
"internal",
"=",
"True",
")",
":",
"# a new one",
"if",
"not",
"cached",
":",
"return",
"cdll",
".",
"LoadLibrary",
"(",
"_so_mapping",
"[",
"name",
"]",
")",
"# from the shared internal se... | 2090435df6241a15ec2a78379a36b738b728652c |
train | _BaseFinalizer.track | Track an object which needs destruction when it is garbage collected. | pgi/clib/_utils.py | def track(cls, obj, ptr):
"""
Track an object which needs destruction when it is garbage collected.
"""
cls._objects.add(cls(obj, ptr)) | def track(cls, obj, ptr):
"""
Track an object which needs destruction when it is garbage collected.
"""
cls._objects.add(cls(obj, ptr)) | [
"Track",
"an",
"object",
"which",
"needs",
"destruction",
"when",
"it",
"is",
"garbage",
"collected",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/clib/_utils.py#L23-L27 | [
"def",
"track",
"(",
"cls",
",",
"obj",
",",
"ptr",
")",
":",
"cls",
".",
"_objects",
".",
"add",
"(",
"cls",
"(",
"obj",
",",
"ptr",
")",
")"
] | 2090435df6241a15ec2a78379a36b738b728652c |
train | _DBusProxyMethodCall._unpack_result | Convert a D-BUS return variant into an appropriate return value | pgi/overrides/Gio.py | def _unpack_result(klass, result):
'''Convert a D-BUS return variant into an appropriate return value'''
result = result.unpack()
# to be compatible with standard Python behaviour, unbox
# single-element tuples and return None for empty result tuples
if len(result) == 1:
... | def _unpack_result(klass, result):
'''Convert a D-BUS return variant into an appropriate return value'''
result = result.unpack()
# to be compatible with standard Python behaviour, unbox
# single-element tuples and return None for empty result tuples
if len(result) == 1:
... | [
"Convert",
"a",
"D",
"-",
"BUS",
"return",
"variant",
"into",
"an",
"appropriate",
"return",
"value"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/overrides/Gio.py#L173-L185 | [
"def",
"_unpack_result",
"(",
"klass",
",",
"result",
")",
":",
"result",
"=",
"result",
".",
"unpack",
"(",
")",
"# to be compatible with standard Python behaviour, unbox",
"# single-element tuples and return None for empty result tuples",
"if",
"len",
"(",
"result",
")",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | list_properties | :param type: a Python GObject instance or type that the signal is associated with
:type type: :obj:`GObject.Object`
:returns: a list of :obj:`GObject.ParamSpec`
:rtype: [:obj:`GObject.ParamSpec`]
Takes a GObject/GInterface subclass or a GType and returns a list of
GParamSpecs for all properties of... | pgi/properties.py | def list_properties(type):
"""
:param type: a Python GObject instance or type that the signal is associated with
:type type: :obj:`GObject.Object`
:returns: a list of :obj:`GObject.ParamSpec`
:rtype: [:obj:`GObject.ParamSpec`]
Takes a GObject/GInterface subclass or a GType and returns a list o... | def list_properties(type):
"""
:param type: a Python GObject instance or type that the signal is associated with
:type type: :obj:`GObject.Object`
:returns: a list of :obj:`GObject.ParamSpec`
:rtype: [:obj:`GObject.ParamSpec`]
Takes a GObject/GInterface subclass or a GType and returns a list o... | [
":",
"param",
"type",
":",
"a",
"Python",
"GObject",
"instance",
"or",
"type",
"that",
"the",
"signal",
"is",
"associated",
"with",
":",
"type",
"type",
":",
":",
"obj",
":",
"GObject",
".",
"Object"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/properties.py#L282-L307 | [
"def",
"list_properties",
"(",
"type",
")",
":",
"if",
"isinstance",
"(",
"type",
",",
"PGType",
")",
":",
"type",
"=",
"type",
".",
"pytype",
"from",
"pgi",
".",
"obj",
"import",
"Object",
",",
"InterfaceBase",
"if",
"not",
"issubclass",
"(",
"type",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | load_overrides | Loads overrides for an introspection module.
Either returns the same module again in case there are no overrides or a
proxy module including overrides. Doesn't cache the result. | pgi/overrides/__init__.py | def load_overrides(introspection_module):
"""Loads overrides for an introspection module.
Either returns the same module again in case there are no overrides or a
proxy module including overrides. Doesn't cache the result.
"""
namespace = introspection_module.__name__.rsplit(".", 1)[-1]
module... | def load_overrides(introspection_module):
"""Loads overrides for an introspection module.
Either returns the same module again in case there are no overrides or a
proxy module including overrides. Doesn't cache the result.
"""
namespace = introspection_module.__name__.rsplit(".", 1)[-1]
module... | [
"Loads",
"overrides",
"for",
"an",
"introspection",
"module",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/overrides/__init__.py#L82-L160 | [
"def",
"load_overrides",
"(",
"introspection_module",
")",
":",
"namespace",
"=",
"introspection_module",
".",
"__name__",
".",
"rsplit",
"(",
"\".\"",
",",
"1",
")",
"[",
"-",
"1",
"]",
"module_keys",
"=",
"[",
"prefix",
"+",
"\".\"",
"+",
"namespace",
"f... | 2090435df6241a15ec2a78379a36b738b728652c |
train | override | Takes a override class or function and assigns it dunder arguments
form the overidden one. | pgi/overrides/__init__.py | def override(klass):
"""Takes a override class or function and assigns it dunder arguments
form the overidden one.
"""
namespace = klass.__module__.rsplit(".", 1)[-1]
mod_name = const.PREFIX[-1] + "." + namespace
module = sys.modules[mod_name]
if isinstance(klass, types.FunctionType):
... | def override(klass):
"""Takes a override class or function and assigns it dunder arguments
form the overidden one.
"""
namespace = klass.__module__.rsplit(".", 1)[-1]
mod_name = const.PREFIX[-1] + "." + namespace
module = sys.modules[mod_name]
if isinstance(klass, types.FunctionType):
... | [
"Takes",
"a",
"override",
"class",
"or",
"function",
"and",
"assigns",
"it",
"dunder",
"arguments",
"form",
"the",
"overidden",
"one",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/overrides/__init__.py#L163-L185 | [
"def",
"override",
"(",
"klass",
")",
":",
"namespace",
"=",
"klass",
".",
"__module__",
".",
"rsplit",
"(",
"\".\"",
",",
"1",
")",
"[",
"-",
"1",
"]",
"mod_name",
"=",
"const",
".",
"PREFIX",
"[",
"-",
"1",
"]",
"+",
"\".\"",
"+",
"namespace",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | deprecated | Mark a function deprecated so calling it issues a warning | pgi/overrides/__init__.py | def deprecated(function, instead):
"""Mark a function deprecated so calling it issues a warning"""
# skip for classes, breaks doc generation
if not isinstance(function, types.FunctionType):
return function
@wraps(function)
def wrap(*args, **kwargs):
warnings.warn("Deprecated, use %... | def deprecated(function, instead):
"""Mark a function deprecated so calling it issues a warning"""
# skip for classes, breaks doc generation
if not isinstance(function, types.FunctionType):
return function
@wraps(function)
def wrap(*args, **kwargs):
warnings.warn("Deprecated, use %... | [
"Mark",
"a",
"function",
"deprecated",
"so",
"calling",
"it",
"issues",
"a",
"warning"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/overrides/__init__.py#L188-L201 | [
"def",
"deprecated",
"(",
"function",
",",
"instead",
")",
":",
"# skip for classes, breaks doc generation",
"if",
"not",
"isinstance",
"(",
"function",
",",
"types",
".",
"FunctionType",
")",
":",
"return",
"function",
"@",
"wraps",
"(",
"function",
")",
"def",... | 2090435df6241a15ec2a78379a36b738b728652c |
train | deprecated_attr | Marks a module level attribute as deprecated. Accessing it will emit
a PyGIDeprecationWarning warning.
e.g. for ``deprecated_attr("GObject", "STATUS_FOO", "GLib.Status.FOO")``
accessing GObject.STATUS_FOO will emit:
"GObject.STATUS_FOO is deprecated; use GLib.Status.FOO instead"
:param str na... | pgi/overrides/__init__.py | def deprecated_attr(namespace, attr, replacement):
"""Marks a module level attribute as deprecated. Accessing it will emit
a PyGIDeprecationWarning warning.
e.g. for ``deprecated_attr("GObject", "STATUS_FOO", "GLib.Status.FOO")``
accessing GObject.STATUS_FOO will emit:
"GObject.STATUS_FOO is d... | def deprecated_attr(namespace, attr, replacement):
"""Marks a module level attribute as deprecated. Accessing it will emit
a PyGIDeprecationWarning warning.
e.g. for ``deprecated_attr("GObject", "STATUS_FOO", "GLib.Status.FOO")``
accessing GObject.STATUS_FOO will emit:
"GObject.STATUS_FOO is d... | [
"Marks",
"a",
"module",
"level",
"attribute",
"as",
"deprecated",
".",
"Accessing",
"it",
"will",
"emit",
"a",
"PyGIDeprecationWarning",
"warning",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/overrides/__init__.py#L204-L221 | [
"def",
"deprecated_attr",
"(",
"namespace",
",",
"attr",
",",
"replacement",
")",
":",
"_deprecated_attrs",
".",
"setdefault",
"(",
"namespace",
",",
"[",
"]",
")",
".",
"append",
"(",
"(",
"attr",
",",
"replacement",
")",
")"
] | 2090435df6241a15ec2a78379a36b738b728652c |
train | deprecated_init | Wrapper for deprecating GObject based __init__ methods which specify
defaults already available or non-standard defaults.
:param callable super_init_func:
Initializer to wrap.
:param list arg_names:
Ordered argument name list.
:param list ignore:
List of argument names to ignore... | pgi/overrides/__init__.py | def deprecated_init(super_init_func, arg_names, ignore=tuple(),
deprecated_aliases={}, deprecated_defaults={},
category=PyGIDeprecationWarning,
stacklevel=2):
"""Wrapper for deprecating GObject based __init__ methods which specify
defaults already avai... | def deprecated_init(super_init_func, arg_names, ignore=tuple(),
deprecated_aliases={}, deprecated_defaults={},
category=PyGIDeprecationWarning,
stacklevel=2):
"""Wrapper for deprecating GObject based __init__ methods which specify
defaults already avai... | [
"Wrapper",
"for",
"deprecating",
"GObject",
"based",
"__init__",
"methods",
"which",
"specify",
"defaults",
"already",
"available",
"or",
"non",
"-",
"standard",
"defaults",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/overrides/__init__.py#L224-L305 | [
"def",
"deprecated_init",
"(",
"super_init_func",
",",
"arg_names",
",",
"ignore",
"=",
"tuple",
"(",
")",
",",
"deprecated_aliases",
"=",
"{",
"}",
",",
"deprecated_defaults",
"=",
"{",
"}",
",",
"category",
"=",
"PyGIDeprecationWarning",
",",
"stacklevel",
"... | 2090435df6241a15ec2a78379a36b738b728652c |
train | strip_boolean_result | Translate method's return value for stripping off success flag.
There are a lot of methods which return a "success" boolean and have
several out arguments. Translate such a method to return the out arguments
on success and None on failure. | pgi/overrides/__init__.py | def strip_boolean_result(method, exc_type=None, exc_str=None, fail_ret=None):
"""Translate method's return value for stripping off success flag.
There are a lot of methods which return a "success" boolean and have
several out arguments. Translate such a method to return the out arguments
on success and... | def strip_boolean_result(method, exc_type=None, exc_str=None, fail_ret=None):
"""Translate method's return value for stripping off success flag.
There are a lot of methods which return a "success" boolean and have
several out arguments. Translate such a method to return the out arguments
on success and... | [
"Translate",
"method",
"s",
"return",
"value",
"for",
"stripping",
"off",
"success",
"flag",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/overrides/__init__.py#L308-L327 | [
"def",
"strip_boolean_result",
"(",
"method",
",",
"exc_type",
"=",
"None",
",",
"exc_str",
"=",
"None",
",",
"fail_ret",
"=",
"None",
")",
":",
"@",
"wraps",
"(",
"method",
")",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | get_introspection_module | Raises ImportError | pgi/module.py | def get_introspection_module(namespace):
"""Raises ImportError"""
if namespace in _introspection_modules:
return _introspection_modules[namespace]
from . import get_required_version
repository = GIRepository()
version = get_required_version(namespace)
try:
repository.require(... | def get_introspection_module(namespace):
"""Raises ImportError"""
if namespace in _introspection_modules:
return _introspection_modules[namespace]
from . import get_required_version
repository = GIRepository()
version = get_required_version(namespace)
try:
repository.require(... | [
"Raises",
"ImportError"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/module.py#L100-L135 | [
"def",
"get_introspection_module",
"(",
"namespace",
")",
":",
"if",
"namespace",
"in",
"_introspection_modules",
":",
"return",
"_introspection_modules",
"[",
"namespace",
"]",
"from",
".",
"import",
"get_required_version",
"repository",
"=",
"GIRepository",
"(",
")"... | 2090435df6241a15ec2a78379a36b738b728652c |
train | ReturnValue.get_param_type | Returns a ReturnValue instance for param type 'index | pgi/codegen/returnvalues.py | def get_param_type(self, index):
"""Returns a ReturnValue instance for param type 'index'"""
assert index in (0, 1)
type_info = self.type.get_param_type(index)
type_cls = get_return_class(type_info)
instance = type_cls(None, type_info, [], self.backend)
instance.setup()... | def get_param_type(self, index):
"""Returns a ReturnValue instance for param type 'index'"""
assert index in (0, 1)
type_info = self.type.get_param_type(index)
type_cls = get_return_class(type_info)
instance = type_cls(None, type_info, [], self.backend)
instance.setup()... | [
"Returns",
"a",
"ReturnValue",
"instance",
"for",
"param",
"type",
"index"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/returnvalues.py#L45-L54 | [
"def",
"get_param_type",
"(",
"self",
",",
"index",
")",
":",
"assert",
"index",
"in",
"(",
"0",
",",
"1",
")",
"type_info",
"=",
"self",
".",
"type",
".",
"get_param_type",
"(",
"index",
")",
"type_cls",
"=",
"get_return_class",
"(",
"type_info",
")",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | parse_code | Parse a piece of text and substitude $var by either unique
variable names or by the given kwargs mapping. Use $$ to escape $.
Returns a CodeBlock and the resulting variable mapping.
parse("$foo = $foo + $bar", bar="1")
("t1 = t1 + 1", {'foo': 't1', 'bar': '1'}) | pgi/codegen/utils.py | def parse_code(code, var_factory, **kwargs):
"""Parse a piece of text and substitude $var by either unique
variable names or by the given kwargs mapping. Use $$ to escape $.
Returns a CodeBlock and the resulting variable mapping.
parse("$foo = $foo + $bar", bar="1")
("t1 = t1 + 1", {'foo': 't1', '... | def parse_code(code, var_factory, **kwargs):
"""Parse a piece of text and substitude $var by either unique
variable names or by the given kwargs mapping. Use $$ to escape $.
Returns a CodeBlock and the resulting variable mapping.
parse("$foo = $foo + $bar", bar="1")
("t1 = t1 + 1", {'foo': 't1', '... | [
"Parse",
"a",
"piece",
"of",
"text",
"and",
"substitude",
"$var",
"by",
"either",
"unique",
"variable",
"names",
"or",
"by",
"the",
"given",
"kwargs",
"mapping",
".",
"Use",
"$$",
"to",
"escape",
"$",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/utils.py#L179-L217 | [
"def",
"parse_code",
"(",
"code",
",",
"var_factory",
",",
"*",
"*",
"kwargs",
")",
":",
"block",
"=",
"CodeBlock",
"(",
")",
"defdict",
"=",
"collections",
".",
"defaultdict",
"(",
"var_factory",
")",
"defdict",
".",
"update",
"(",
"kwargs",
")",
"inden... | 2090435df6241a15ec2a78379a36b738b728652c |
train | parse_with_objects | Parse code and include non string/codeblock kwargs as
dependencies.
int/long will be inlined.
Returns a CodeBlock and the resulting variable mapping. | pgi/codegen/utils.py | def parse_with_objects(code, var, **kwargs):
"""Parse code and include non string/codeblock kwargs as
dependencies.
int/long will be inlined.
Returns a CodeBlock and the resulting variable mapping.
"""
deps = {}
for key, value in kwargs.items():
if isinstance(value, _compat.intege... | def parse_with_objects(code, var, **kwargs):
"""Parse code and include non string/codeblock kwargs as
dependencies.
int/long will be inlined.
Returns a CodeBlock and the resulting variable mapping.
"""
deps = {}
for key, value in kwargs.items():
if isinstance(value, _compat.intege... | [
"Parse",
"code",
"and",
"include",
"non",
"string",
"/",
"codeblock",
"kwargs",
"as",
"dependencies",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/utils.py#L220-L248 | [
"def",
"parse_with_objects",
"(",
"code",
",",
"var",
",",
"*",
"*",
"kwargs",
")",
":",
"deps",
"=",
"{",
"}",
"for",
"key",
",",
"value",
"in",
"kwargs",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"_compat",
".",
"integer... | 2090435df6241a15ec2a78379a36b738b728652c |
train | VariableFactory.request_name | Request a name, might return the name or a similar one if already
used or reserved | pgi/codegen/utils.py | def request_name(self, name):
"""Request a name, might return the name or a similar one if already
used or reserved
"""
while name in self._blacklist:
name += "_"
self._blacklist.add(name)
return name | def request_name(self, name):
"""Request a name, might return the name or a similar one if already
used or reserved
"""
while name in self._blacklist:
name += "_"
self._blacklist.add(name)
return name | [
"Request",
"a",
"name",
"might",
"return",
"the",
"name",
"or",
"a",
"similar",
"one",
"if",
"already",
"used",
"or",
"reserved"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/utils.py#L68-L76 | [
"def",
"request_name",
"(",
"self",
",",
"name",
")",
":",
"while",
"name",
"in",
"self",
".",
"_blacklist",
":",
"name",
"+=",
"\"_\"",
"self",
".",
"_blacklist",
".",
"add",
"(",
"name",
")",
"return",
"name"
] | 2090435df6241a15ec2a78379a36b738b728652c |
train | CodeBlock.add_dependency | Add a code dependency so it gets inserted into globals | pgi/codegen/utils.py | def add_dependency(self, name, obj):
"""Add a code dependency so it gets inserted into globals"""
if name in self._deps:
if self._deps[name] is obj:
return
raise ValueError(
"There exists a different dep with the same name : %r" % name)
se... | def add_dependency(self, name, obj):
"""Add a code dependency so it gets inserted into globals"""
if name in self._deps:
if self._deps[name] is obj:
return
raise ValueError(
"There exists a different dep with the same name : %r" % name)
se... | [
"Add",
"a",
"code",
"dependency",
"so",
"it",
"gets",
"inserted",
"into",
"globals"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/utils.py#L94-L102 | [
"def",
"add_dependency",
"(",
"self",
",",
"name",
",",
"obj",
")",
":",
"if",
"name",
"in",
"self",
".",
"_deps",
":",
"if",
"self",
".",
"_deps",
"[",
"name",
"]",
"is",
"obj",
":",
"return",
"raise",
"ValueError",
"(",
"\"There exists a different dep ... | 2090435df6241a15ec2a78379a36b738b728652c |
train | CodeBlock.write_into | Append this block to another one, passing all dependencies | pgi/codegen/utils.py | def write_into(self, block, level=0):
"""Append this block to another one, passing all dependencies"""
for line, l in self._lines:
block.write_line(line, level + l)
for name, obj in _compat.iteritems(self._deps):
block.add_dependency(name, obj) | def write_into(self, block, level=0):
"""Append this block to another one, passing all dependencies"""
for line, l in self._lines:
block.write_line(line, level + l)
for name, obj in _compat.iteritems(self._deps):
block.add_dependency(name, obj) | [
"Append",
"this",
"block",
"to",
"another",
"one",
"passing",
"all",
"dependencies"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/utils.py#L104-L111 | [
"def",
"write_into",
"(",
"self",
",",
"block",
",",
"level",
"=",
"0",
")",
":",
"for",
"line",
",",
"l",
"in",
"self",
".",
"_lines",
":",
"block",
".",
"write_line",
"(",
"line",
",",
"level",
"+",
"l",
")",
"for",
"name",
",",
"obj",
"in",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | CodeBlock.write_lines | Append multiple new lines | pgi/codegen/utils.py | def write_lines(self, lines, level=0):
"""Append multiple new lines"""
for line in lines:
self.write_line(line, level) | def write_lines(self, lines, level=0):
"""Append multiple new lines"""
for line in lines:
self.write_line(line, level) | [
"Append",
"multiple",
"new",
"lines"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/utils.py#L118-L122 | [
"def",
"write_lines",
"(",
"self",
",",
"lines",
",",
"level",
"=",
"0",
")",
":",
"for",
"line",
"in",
"lines",
":",
"self",
".",
"write_line",
"(",
"line",
",",
"level",
")"
] | 2090435df6241a15ec2a78379a36b738b728652c |
train | CodeBlock.compile | Execute the python code and returns the global dict.
kwargs can contain extra dependencies that get only used
at compile time. | pgi/codegen/utils.py | def compile(self, **kwargs):
"""Execute the python code and returns the global dict.
kwargs can contain extra dependencies that get only used
at compile time.
"""
code = compile(str(self), "<string>", "exec")
global_dict = dict(self._deps)
global_dict.update(kwar... | def compile(self, **kwargs):
"""Execute the python code and returns the global dict.
kwargs can contain extra dependencies that get only used
at compile time.
"""
code = compile(str(self), "<string>", "exec")
global_dict = dict(self._deps)
global_dict.update(kwar... | [
"Execute",
"the",
"python",
"code",
"and",
"returns",
"the",
"global",
"dict",
".",
"kwargs",
"can",
"contain",
"extra",
"dependencies",
"that",
"get",
"only",
"used",
"at",
"compile",
"time",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/utils.py#L124-L134 | [
"def",
"compile",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"code",
"=",
"compile",
"(",
"str",
"(",
"self",
")",
",",
"\"<string>\"",
",",
"\"exec\"",
")",
"global_dict",
"=",
"dict",
"(",
"self",
".",
"_deps",
")",
"global_dict",
".",
"update... | 2090435df6241a15ec2a78379a36b738b728652c |
train | CodeBlock.pprint | Print the code block to stdout.
Does syntax highlighting if possible. | pgi/codegen/utils.py | def pprint(self, file_=sys.stdout):
"""Print the code block to stdout.
Does syntax highlighting if possible.
"""
code = []
if self._deps:
code.append("# dependencies:")
for k, v in _compat.iteritems(self._deps):
code.append("# %s: %r" % (k, v))
... | def pprint(self, file_=sys.stdout):
"""Print the code block to stdout.
Does syntax highlighting if possible.
"""
code = []
if self._deps:
code.append("# dependencies:")
for k, v in _compat.iteritems(self._deps):
code.append("# %s: %r" % (k, v))
... | [
"Print",
"the",
"code",
"block",
"to",
"stdout",
".",
"Does",
"syntax",
"highlighting",
"if",
"possible",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/utils.py#L136-L161 | [
"def",
"pprint",
"(",
"self",
",",
"file_",
"=",
"sys",
".",
"stdout",
")",
":",
"code",
"=",
"[",
"]",
"if",
"self",
".",
"_deps",
":",
"code",
".",
"append",
"(",
"\"# dependencies:\"",
")",
"for",
"k",
",",
"v",
"in",
"_compat",
".",
"iteritems"... | 2090435df6241a15ec2a78379a36b738b728652c |
train | ForeignStruct.register | Class decorator | pgi/foreign/_base.py | def register(cls, namespace, name):
"""Class decorator"""
def func(kind):
cls._FOREIGN[(namespace, name)] = kind()
return kind
return func | def register(cls, namespace, name):
"""Class decorator"""
def func(kind):
cls._FOREIGN[(namespace, name)] = kind()
return kind
return func | [
"Class",
"decorator"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/foreign/_base.py#L27-L33 | [
"def",
"register",
"(",
"cls",
",",
"namespace",
",",
"name",
")",
":",
"def",
"func",
"(",
"kind",
")",
":",
"cls",
".",
"_FOREIGN",
"[",
"(",
"namespace",
",",
"name",
")",
"]",
"=",
"kind",
"(",
")",
"return",
"kind",
"return",
"func"
] | 2090435df6241a15ec2a78379a36b738b728652c |
train | may_be_null_is_nullable | If may_be_null returns nullable or if NULL can be passed in.
This can still be wrong if the specific typelib is older than the linked
libgirepository.
https://bugzilla.gnome.org/show_bug.cgi?id=660879#c47 | pgi/codegen/funcgen.py | def may_be_null_is_nullable():
"""If may_be_null returns nullable or if NULL can be passed in.
This can still be wrong if the specific typelib is older than the linked
libgirepository.
https://bugzilla.gnome.org/show_bug.cgi?id=660879#c47
"""
repo = GIRepository()
repo.require("GLib", "2.... | def may_be_null_is_nullable():
"""If may_be_null returns nullable or if NULL can be passed in.
This can still be wrong if the specific typelib is older than the linked
libgirepository.
https://bugzilla.gnome.org/show_bug.cgi?id=660879#c47
"""
repo = GIRepository()
repo.require("GLib", "2.... | [
"If",
"may_be_null",
"returns",
"nullable",
"or",
"if",
"NULL",
"can",
"be",
"passed",
"in",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/funcgen.py#L23-L36 | [
"def",
"may_be_null_is_nullable",
"(",
")",
":",
"repo",
"=",
"GIRepository",
"(",
")",
"repo",
".",
"require",
"(",
"\"GLib\"",
",",
"\"2.0\"",
",",
"0",
")",
"info",
"=",
"repo",
".",
"find_by_name",
"(",
"\"GLib\"",
",",
"\"spawn_sync\"",
")",
"# this a... | 2090435df6241a15ec2a78379a36b738b728652c |
train | get_type_name | Gives a name for a type that is suitable for a docstring.
int -> "int"
Gtk.Window -> "Gtk.Window"
[int] -> "[int]"
{int: Gtk.Button} -> "{int: Gtk.Button}" | pgi/codegen/funcgen.py | def get_type_name(type_):
"""Gives a name for a type that is suitable for a docstring.
int -> "int"
Gtk.Window -> "Gtk.Window"
[int] -> "[int]"
{int: Gtk.Button} -> "{int: Gtk.Button}"
"""
if type_ is None:
return ""
if isinstance(type_, string_types):
return type_
... | def get_type_name(type_):
"""Gives a name for a type that is suitable for a docstring.
int -> "int"
Gtk.Window -> "Gtk.Window"
[int] -> "[int]"
{int: Gtk.Button} -> "{int: Gtk.Button}"
"""
if type_ is None:
return ""
if isinstance(type_, string_types):
return type_
... | [
"Gives",
"a",
"name",
"for",
"a",
"type",
"that",
"is",
"suitable",
"for",
"a",
"docstring",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/funcgen.py#L39-L62 | [
"def",
"get_type_name",
"(",
"type_",
")",
":",
"if",
"type_",
"is",
"None",
":",
"return",
"\"\"",
"if",
"isinstance",
"(",
"type_",
",",
"string_types",
")",
":",
"return",
"type_",
"elif",
"isinstance",
"(",
"type_",
",",
"list",
")",
":",
"assert",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | build_docstring | Create a docstring in the form:
name(in_name: type) -> (ret_type, out_name: type) | pgi/codegen/funcgen.py | def build_docstring(func_name, args, ret, throws, signal_owner_type=None):
"""Create a docstring in the form:
name(in_name: type) -> (ret_type, out_name: type)
"""
out_args = []
if ret and not ret.ignore:
if ret.py_type is None:
out_args.append("unknown")
else:
... | def build_docstring(func_name, args, ret, throws, signal_owner_type=None):
"""Create a docstring in the form:
name(in_name: type) -> (ret_type, out_name: type)
"""
out_args = []
if ret and not ret.ignore:
if ret.py_type is None:
out_args.append("unknown")
else:
... | [
"Create",
"a",
"docstring",
"in",
"the",
"form",
":",
"name",
"(",
"in_name",
":",
"type",
")",
"-",
">",
"(",
"ret_type",
"out_name",
":",
"type",
")"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/funcgen.py#L71-L132 | [
"def",
"build_docstring",
"(",
"func_name",
",",
"args",
",",
"ret",
",",
"throws",
",",
"signal_owner_type",
"=",
"None",
")",
":",
"out_args",
"=",
"[",
"]",
"if",
"ret",
"and",
"not",
"ret",
".",
"ignore",
":",
"if",
"ret",
".",
"py_type",
"is",
"... | 2090435df6241a15ec2a78379a36b738b728652c |
train | generate_function | Creates a Python callable for a GIFunctionInfo instance | pgi/codegen/funcgen.py | def generate_function(info, method=False):
"""Creates a Python callable for a GIFunctionInfo instance"""
assert isinstance(info, GIFunctionInfo)
arg_infos = list(info.get_args())
arg_types = [a.get_type() for a in arg_infos]
return_type = info.get_return_type()
func = None
messages = []
... | def generate_function(info, method=False):
"""Creates a Python callable for a GIFunctionInfo instance"""
assert isinstance(info, GIFunctionInfo)
arg_infos = list(info.get_args())
arg_types = [a.get_type() for a in arg_infos]
return_type = info.get_return_type()
func = None
messages = []
... | [
"Creates",
"a",
"Python",
"callable",
"for",
"a",
"GIFunctionInfo",
"instance"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/funcgen.py#L287-L311 | [
"def",
"generate_function",
"(",
"info",
",",
"method",
"=",
"False",
")",
":",
"assert",
"isinstance",
"(",
"info",
",",
"GIFunctionInfo",
")",
"arg_infos",
"=",
"list",
"(",
"info",
".",
"get_args",
"(",
")",
")",
"arg_types",
"=",
"[",
"a",
".",
"ge... | 2090435df6241a15ec2a78379a36b738b728652c |
train | generate_dummy_callable | Takes a GICallableInfo and generates a dummy callback function which
just raises but has a correct docstring. They are mainly accessible for
documentation, so the API reference can reference a real thing.
func_name can be different than info.name because vfuncs, for example,
get prefixed with 'do_' whe... | pgi/codegen/funcgen.py | def generate_dummy_callable(info, func_name, method=False,
signal_owner_type=None):
"""Takes a GICallableInfo and generates a dummy callback function which
just raises but has a correct docstring. They are mainly accessible for
documentation, so the API reference can reference a ... | def generate_dummy_callable(info, func_name, method=False,
signal_owner_type=None):
"""Takes a GICallableInfo and generates a dummy callback function which
just raises but has a correct docstring. They are mainly accessible for
documentation, so the API reference can reference a ... | [
"Takes",
"a",
"GICallableInfo",
"and",
"generates",
"a",
"dummy",
"callback",
"function",
"which",
"just",
"raises",
"but",
"has",
"a",
"correct",
"docstring",
".",
"They",
"are",
"mainly",
"accessible",
"for",
"documentation",
"so",
"the",
"API",
"reference",
... | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/codegen/funcgen.py#L314-L382 | [
"def",
"generate_dummy_callable",
"(",
"info",
",",
"func_name",
",",
"method",
"=",
"False",
",",
"signal_owner_type",
"=",
"None",
")",
":",
"assert",
"isinstance",
"(",
"info",
",",
"GICallableInfo",
")",
"# FIXME: handle out args and trailing user_data ?",
"arg_in... | 2090435df6241a15ec2a78379a36b738b728652c |
train | _create_enum_class | Returns a new shiny class for the given enum type | pgi/cffilib/_utils.py | def _create_enum_class(ffi, type_name, prefix, flags=False):
"""Returns a new shiny class for the given enum type"""
class _template(int):
_map = {}
@property
def value(self):
return int(self)
def __str__(self):
return self._map.get(self, "Unknown")
... | def _create_enum_class(ffi, type_name, prefix, flags=False):
"""Returns a new shiny class for the given enum type"""
class _template(int):
_map = {}
@property
def value(self):
return int(self)
def __str__(self):
return self._map.get(self, "Unknown")
... | [
"Returns",
"a",
"new",
"shiny",
"class",
"for",
"the",
"given",
"enum",
"type"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/cffilib/_utils.py#L58-L108 | [
"def",
"_create_enum_class",
"(",
"ffi",
",",
"type_name",
",",
"prefix",
",",
"flags",
"=",
"False",
")",
":",
"class",
"_template",
"(",
"int",
")",
":",
"_map",
"=",
"{",
"}",
"@",
"property",
"def",
"value",
"(",
"self",
")",
":",
"return",
"int"... | 2090435df6241a15ec2a78379a36b738b728652c |
train | _fixup_cdef_enums | Converts some common enum expressions to constants | pgi/cffilib/_utils.py | def _fixup_cdef_enums(string, reg=re.compile(r"=\s*(\d+)\s*<<\s*(\d+)")):
"""Converts some common enum expressions to constants"""
def repl_shift(match):
shift_by = int(match.group(2))
value = int(match.group(1))
int_value = ctypes.c_int(value << shift_by).value
return "= %s" % ... | def _fixup_cdef_enums(string, reg=re.compile(r"=\s*(\d+)\s*<<\s*(\d+)")):
"""Converts some common enum expressions to constants"""
def repl_shift(match):
shift_by = int(match.group(2))
value = int(match.group(1))
int_value = ctypes.c_int(value << shift_by).value
return "= %s" % ... | [
"Converts",
"some",
"common",
"enum",
"expressions",
"to",
"constants"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/cffilib/_utils.py#L111-L119 | [
"def",
"_fixup_cdef_enums",
"(",
"string",
",",
"reg",
"=",
"re",
".",
"compile",
"(",
"r\"=\\s*(\\d+)\\s*<<\\s*(\\d+)\"",
")",
")",
":",
"def",
"repl_shift",
"(",
"match",
")",
":",
"shift_by",
"=",
"int",
"(",
"match",
".",
"group",
"(",
"2",
")",
")",... | 2090435df6241a15ec2a78379a36b738b728652c |
train | unpack_glist | Takes a glist, copies the values casted to type_ in to a list
and frees all items and the list. | pgi/clib/glib.py | def unpack_glist(g, type_, transfer_full=True):
"""Takes a glist, copies the values casted to type_ in to a list
and frees all items and the list.
"""
values = []
item = g
while item:
ptr = item.contents.data
value = cast(ptr, type_).value
values.append(value)
if... | def unpack_glist(g, type_, transfer_full=True):
"""Takes a glist, copies the values casted to type_ in to a list
and frees all items and the list.
"""
values = []
item = g
while item:
ptr = item.contents.data
value = cast(ptr, type_).value
values.append(value)
if... | [
"Takes",
"a",
"glist",
"copies",
"the",
"values",
"casted",
"to",
"type_",
"in",
"to",
"a",
"list",
"and",
"frees",
"all",
"items",
"and",
"the",
"list",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/clib/glib.py#L281-L297 | [
"def",
"unpack_glist",
"(",
"g",
",",
"type_",
",",
"transfer_full",
"=",
"True",
")",
":",
"values",
"=",
"[",
"]",
"item",
"=",
"g",
"while",
"item",
":",
"ptr",
"=",
"item",
".",
"contents",
".",
"data",
"value",
"=",
"cast",
"(",
"ptr",
",",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | unpack_nullterm_array | Takes a null terminated array, copies the values into a list
and frees each value and the list. | pgi/clib/glib.py | def unpack_nullterm_array(array):
"""Takes a null terminated array, copies the values into a list
and frees each value and the list.
"""
addrs = cast(array, POINTER(ctypes.c_void_p))
l = []
i = 0
value = array[i]
while value:
l.append(value)
free(addrs[i])
i += 1... | def unpack_nullterm_array(array):
"""Takes a null terminated array, copies the values into a list
and frees each value and the list.
"""
addrs = cast(array, POINTER(ctypes.c_void_p))
l = []
i = 0
value = array[i]
while value:
l.append(value)
free(addrs[i])
i += 1... | [
"Takes",
"a",
"null",
"terminated",
"array",
"copies",
"the",
"values",
"into",
"a",
"list",
"and",
"frees",
"each",
"value",
"and",
"the",
"list",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/clib/glib.py#L300-L315 | [
"def",
"unpack_nullterm_array",
"(",
"array",
")",
":",
"addrs",
"=",
"cast",
"(",
"array",
",",
"POINTER",
"(",
"ctypes",
".",
"c_void_p",
")",
")",
"l",
"=",
"[",
"]",
"i",
"=",
"0",
"value",
"=",
"array",
"[",
"i",
"]",
"while",
"value",
":",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | require_version | Set a version for the namespace to be loaded.
This needs to be called before importing the namespace or any
namespace that depends on it. | pgi/importer.py | def require_version(namespace, version):
"""Set a version for the namespace to be loaded.
This needs to be called before importing the namespace or any
namespace that depends on it.
"""
global _versions
repo = GIRepository()
namespaces = repo.get_loaded_namespaces()
if namespace in na... | def require_version(namespace, version):
"""Set a version for the namespace to be loaded.
This needs to be called before importing the namespace or any
namespace that depends on it.
"""
global _versions
repo = GIRepository()
namespaces = repo.get_loaded_namespaces()
if namespace in na... | [
"Set",
"a",
"version",
"for",
"the",
"namespace",
"to",
"be",
"loaded",
".",
"This",
"needs",
"to",
"be",
"called",
"before",
"importing",
"the",
"namespace",
"or",
"any",
"namespace",
"that",
"depends",
"on",
"it",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/importer.py#L23-L52 | [
"def",
"require_version",
"(",
"namespace",
",",
"version",
")",
":",
"global",
"_versions",
"repo",
"=",
"GIRepository",
"(",
")",
"namespaces",
"=",
"repo",
".",
"get_loaded_namespaces",
"(",
")",
"if",
"namespace",
"in",
"namespaces",
":",
"loaded_version",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | _check_require_version | A context manager which tries to give helpful warnings
about missing gi.require_version() which could potentially
break code if only an older version than expected is installed
or a new version gets introduced.
::
with _check_require_version("Gtk", stacklevel):
load_namespace_and_o... | pgi/importer.py | def _check_require_version(namespace, stacklevel):
"""A context manager which tries to give helpful warnings
about missing gi.require_version() which could potentially
break code if only an older version than expected is installed
or a new version gets introduced.
::
with _check_require_ve... | def _check_require_version(namespace, stacklevel):
"""A context manager which tries to give helpful warnings
about missing gi.require_version() which could potentially
break code if only an older version than expected is installed
or a new version gets introduced.
::
with _check_require_ve... | [
"A",
"context",
"manager",
"which",
"tries",
"to",
"give",
"helpful",
"warnings",
"about",
"missing",
"gi",
".",
"require_version",
"()",
"which",
"could",
"potentially",
"break",
"code",
"if",
"only",
"an",
"older",
"version",
"than",
"expected",
"is",
"insta... | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/importer.py#L78-L114 | [
"def",
"_check_require_version",
"(",
"namespace",
",",
"stacklevel",
")",
":",
"repository",
"=",
"GIRepository",
"(",
")",
"was_loaded",
"=",
"repository",
".",
"is_registered",
"(",
"namespace",
")",
"yield",
"if",
"was_loaded",
":",
"# it was loaded before by an... | 2090435df6241a15ec2a78379a36b738b728652c |
train | get_import_stacklevel | Returns the stacklevel value for warnings.warn() for when the warning
gets emitted by an imported module, but the warning should point at the
code doing the import.
Pass import_hook=True if the warning gets generated by an import hook
(warn() gets called in load_module(), see PEP302) | pgi/importer.py | def get_import_stacklevel(import_hook):
"""Returns the stacklevel value for warnings.warn() for when the warning
gets emitted by an imported module, but the warning should point at the
code doing the import.
Pass import_hook=True if the warning gets generated by an import hook
(warn() gets called i... | def get_import_stacklevel(import_hook):
"""Returns the stacklevel value for warnings.warn() for when the warning
gets emitted by an imported module, but the warning should point at the
code doing the import.
Pass import_hook=True if the warning gets generated by an import hook
(warn() gets called i... | [
"Returns",
"the",
"stacklevel",
"value",
"for",
"warnings",
".",
"warn",
"()",
"for",
"when",
"the",
"warning",
"gets",
"emitted",
"by",
"an",
"imported",
"module",
"but",
"the",
"warning",
"should",
"point",
"at",
"the",
"code",
"doing",
"the",
"import",
... | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/importer.py#L117-L136 | [
"def",
"get_import_stacklevel",
"(",
"import_hook",
")",
":",
"py_version",
"=",
"sys",
".",
"version_info",
"[",
":",
"2",
"]",
"if",
"py_version",
"<=",
"(",
"3",
",",
"2",
")",
":",
"# 2.7 included",
"return",
"4",
"if",
"import_hook",
"else",
"2",
"e... | 2090435df6241a15ec2a78379a36b738b728652c |
train | unpack_glist | Takes a glist ptr, copies the values casted to type_ in to a list
and frees all items and the list.
If an item is returned all yielded before are invalid. | pgi/cffilib/glib/glib.py | def unpack_glist(glist_ptr, cffi_type, transfer_full=True):
"""Takes a glist ptr, copies the values casted to type_ in to a list
and frees all items and the list.
If an item is returned all yielded before are invalid.
"""
current = glist_ptr
while current:
yield ffi.cast(cffi_type, cur... | def unpack_glist(glist_ptr, cffi_type, transfer_full=True):
"""Takes a glist ptr, copies the values casted to type_ in to a list
and frees all items and the list.
If an item is returned all yielded before are invalid.
"""
current = glist_ptr
while current:
yield ffi.cast(cffi_type, cur... | [
"Takes",
"a",
"glist",
"ptr",
"copies",
"the",
"values",
"casted",
"to",
"type_",
"in",
"to",
"a",
"list",
"and",
"frees",
"all",
"items",
"and",
"the",
"list",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/cffilib/glib/glib.py#L227-L241 | [
"def",
"unpack_glist",
"(",
"glist_ptr",
",",
"cffi_type",
",",
"transfer_full",
"=",
"True",
")",
":",
"current",
"=",
"glist_ptr",
"while",
"current",
":",
"yield",
"ffi",
".",
"cast",
"(",
"cffi_type",
",",
"current",
".",
"data",
")",
"if",
"transfer_f... | 2090435df6241a15ec2a78379a36b738b728652c |
train | unpack_zeroterm_array | Converts a zero terminated array to a list and frees each element
and the list itself.
If an item is returned all yielded before are invalid. | pgi/cffilib/glib/glib.py | def unpack_zeroterm_array(ptr):
"""Converts a zero terminated array to a list and frees each element
and the list itself.
If an item is returned all yielded before are invalid.
"""
assert ptr
index = 0
current = ptr[index]
while current:
yield current
free(ffi.cast("gp... | def unpack_zeroterm_array(ptr):
"""Converts a zero terminated array to a list and frees each element
and the list itself.
If an item is returned all yielded before are invalid.
"""
assert ptr
index = 0
current = ptr[index]
while current:
yield current
free(ffi.cast("gp... | [
"Converts",
"a",
"zero",
"terminated",
"array",
"to",
"a",
"list",
"and",
"frees",
"each",
"element",
"and",
"the",
"list",
"itself",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/cffilib/glib/glib.py#L244-L260 | [
"def",
"unpack_zeroterm_array",
"(",
"ptr",
")",
":",
"assert",
"ptr",
"index",
"=",
"0",
"current",
"=",
"ptr",
"[",
"index",
"]",
"while",
"current",
":",
"yield",
"current",
"free",
"(",
"ffi",
".",
"cast",
"(",
"\"gpointer\"",
",",
"current",
")",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | StructureAttribute | Creates a new struct class. | pgi/structure.py | def StructureAttribute(struct_info):
"""Creates a new struct class."""
# Copy the template and add the gtype
cls_dict = dict(_Structure.__dict__)
cls = type(struct_info.name, _Structure.__bases__, cls_dict)
cls.__module__ = struct_info.namespace
cls.__gtype__ = PGType(struct_info.g_type)
cl... | def StructureAttribute(struct_info):
"""Creates a new struct class."""
# Copy the template and add the gtype
cls_dict = dict(_Structure.__dict__)
cls = type(struct_info.name, _Structure.__bases__, cls_dict)
cls.__module__ = struct_info.namespace
cls.__gtype__ = PGType(struct_info.g_type)
cl... | [
"Creates",
"a",
"new",
"struct",
"class",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/structure.py#L110-L131 | [
"def",
"StructureAttribute",
"(",
"struct_info",
")",
":",
"# Copy the template and add the gtype",
"cls_dict",
"=",
"dict",
"(",
"_Structure",
".",
"__dict__",
")",
"cls",
"=",
"type",
"(",
"struct_info",
".",
"name",
",",
"_Structure",
".",
"__bases__",
",",
"... | 2090435df6241a15ec2a78379a36b738b728652c |
train | PGError._from_gerror | Creates a GError exception and takes ownership if own is True | pgi/gerror.py | def _from_gerror(cls, error, own=True):
"""Creates a GError exception and takes ownership if own is True"""
if not own:
error = error.copy()
self = cls()
self._error = error
return self | def _from_gerror(cls, error, own=True):
"""Creates a GError exception and takes ownership if own is True"""
if not own:
error = error.copy()
self = cls()
self._error = error
return self | [
"Creates",
"a",
"GError",
"exception",
"and",
"takes",
"ownership",
"if",
"own",
"is",
"True"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/gerror.py#L17-L25 | [
"def",
"_from_gerror",
"(",
"cls",
",",
"error",
",",
"own",
"=",
"True",
")",
":",
"if",
"not",
"own",
":",
"error",
"=",
"error",
".",
"copy",
"(",
")",
"self",
"=",
"cls",
"(",
")",
"self",
".",
"_error",
"=",
"error",
"return",
"self"
] | 2090435df6241a15ec2a78379a36b738b728652c |
train | check_version | Takes a version string or tuple and raises ValueError in case
the passed version is newer than the current version of pgi.
Keep in mind that the pgi version is different from the pygobject one. | pgi/__init__.py | def check_version(version):
"""Takes a version string or tuple and raises ValueError in case
the passed version is newer than the current version of pgi.
Keep in mind that the pgi version is different from the pygobject one.
"""
if isinstance(version, string_types):
version = tuple(map(int... | def check_version(version):
"""Takes a version string or tuple and raises ValueError in case
the passed version is newer than the current version of pgi.
Keep in mind that the pgi version is different from the pygobject one.
"""
if isinstance(version, string_types):
version = tuple(map(int... | [
"Takes",
"a",
"version",
"string",
"or",
"tuple",
"and",
"raises",
"ValueError",
"in",
"case",
"the",
"passed",
"version",
"is",
"newer",
"than",
"the",
"current",
"version",
"of",
"pgi",
"."
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/__init__.py#L27-L40 | [
"def",
"check_version",
"(",
"version",
")",
":",
"if",
"isinstance",
"(",
"version",
",",
"string_types",
")",
":",
"version",
"=",
"tuple",
"(",
"map",
"(",
"int",
",",
"version",
".",
"split",
"(",
"\".\"",
")",
")",
")",
"if",
"version",
">",
"ve... | 2090435df6241a15ec2a78379a36b738b728652c |
train | install_as_gi | Call before the first gi import to redirect gi imports to pgi | pgi/__init__.py | def install_as_gi():
"""Call before the first gi import to redirect gi imports to pgi"""
import sys
# check if gi has already been replaces
if "gi.repository" in const.PREFIX:
return
# make sure gi isn't loaded first
for mod in iterkeys(sys.modules):
if mod == "gi" or mod.star... | def install_as_gi():
"""Call before the first gi import to redirect gi imports to pgi"""
import sys
# check if gi has already been replaces
if "gi.repository" in const.PREFIX:
return
# make sure gi isn't loaded first
for mod in iterkeys(sys.modules):
if mod == "gi" or mod.star... | [
"Call",
"before",
"the",
"first",
"gi",
"import",
"to",
"redirect",
"gi",
"imports",
"to",
"pgi"
] | pygobject/pgi | python | https://github.com/pygobject/pgi/blob/2090435df6241a15ec2a78379a36b738b728652c/pgi/__init__.py#L43-L62 | [
"def",
"install_as_gi",
"(",
")",
":",
"import",
"sys",
"# check if gi has already been replaces",
"if",
"\"gi.repository\"",
"in",
"const",
".",
"PREFIX",
":",
"return",
"# make sure gi isn't loaded first",
"for",
"mod",
"in",
"iterkeys",
"(",
"sys",
".",
"modules",
... | 2090435df6241a15ec2a78379a36b738b728652c |
train | add_panel_to_edit_handler | Adds specified panel class to model class.
:param model: the model class.
:param panel_cls: the panel class.
:param heading: the panel heading.
:param index: the index position to insert at. | wagtailplus/utils/edit_handlers.py | def add_panel_to_edit_handler(model, panel_cls, heading, index=None):
"""
Adds specified panel class to model class.
:param model: the model class.
:param panel_cls: the panel class.
:param heading: the panel heading.
:param index: the index position to insert at.
"""
from wagtail.wagta... | def add_panel_to_edit_handler(model, panel_cls, heading, index=None):
"""
Adds specified panel class to model class.
:param model: the model class.
:param panel_cls: the panel class.
:param heading: the panel heading.
:param index: the index position to insert at.
"""
from wagtail.wagta... | [
"Adds",
"specified",
"panel",
"class",
"to",
"model",
"class",
"."
] | rfosterslo/wagtailplus | python | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/edit_handlers.py#L7-L27 | [
"def",
"add_panel_to_edit_handler",
"(",
"model",
",",
"panel_cls",
",",
"heading",
",",
"index",
"=",
"None",
")",
":",
"from",
"wagtail",
".",
"wagtailadmin",
".",
"views",
".",
"pages",
"import",
"get_page_edit_handler",
"edit_handler",
"=",
"get_page_edit_hand... | 22cac857175d8a6f77e470751831c14a92ccd768 |
train | IndexView.get_context_data | Returns context dictionary for view.
:rtype: dict. | wagtailplus/utils/views/crud.py | def get_context_data(self, **kwargs):
"""
Returns context dictionary for view.
:rtype: dict.
"""
#noinspection PyUnresolvedReferences
query_str = self.request.GET.get('q', None)
queryset = kwargs.pop('object_list', self.object_list)
c... | def get_context_data(self, **kwargs):
"""
Returns context dictionary for view.
:rtype: dict.
"""
#noinspection PyUnresolvedReferences
query_str = self.request.GET.get('q', None)
queryset = kwargs.pop('object_list', self.object_list)
c... | [
"Returns",
"context",
"dictionary",
"for",
"view",
"."
] | rfosterslo/wagtailplus | python | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L51-L83 | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"#noinspection PyUnresolvedReferences",
"query_str",
"=",
"self",
".",
"request",
".",
"GET",
".",
"get",
"(",
"'q'",
",",
"None",
")",
"queryset",
"=",
"kwargs",
".",
"pop",
"(",
... | 22cac857175d8a6f77e470751831c14a92ccd768 |
train | IndexView.get_ordering | Returns ordering value for list.
:rtype: str. | wagtailplus/utils/views/crud.py | def get_ordering(self):
"""
Returns ordering value for list.
:rtype: str.
"""
#noinspection PyUnresolvedReferences
ordering = self.request.GET.get('ordering', None)
if ordering not in ['title', '-created_at']:
ordering = '-created_at'
return... | def get_ordering(self):
"""
Returns ordering value for list.
:rtype: str.
"""
#noinspection PyUnresolvedReferences
ordering = self.request.GET.get('ordering', None)
if ordering not in ['title', '-created_at']:
ordering = '-created_at'
return... | [
"Returns",
"ordering",
"value",
"for",
"list",
"."
] | rfosterslo/wagtailplus | python | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L85-L97 | [
"def",
"get_ordering",
"(",
"self",
")",
":",
"#noinspection PyUnresolvedReferences",
"ordering",
"=",
"self",
".",
"request",
".",
"GET",
".",
"get",
"(",
"'ordering'",
",",
"None",
")",
"if",
"ordering",
"not",
"in",
"[",
"'title'",
",",
"'-created_at'",
"... | 22cac857175d8a6f77e470751831c14a92ccd768 |
train | IndexView.get_queryset | Returns queryset instance.
:rtype: django.db.models.query.QuerySet. | wagtailplus/utils/views/crud.py | def get_queryset(self):
"""
Returns queryset instance.
:rtype: django.db.models.query.QuerySet.
"""
queryset = super(IndexView, self).get_queryset()
search_form = self.get_search_form()
if search_form.is_valid():
query_str = search_form.cleaned_... | def get_queryset(self):
"""
Returns queryset instance.
:rtype: django.db.models.query.QuerySet.
"""
queryset = super(IndexView, self).get_queryset()
search_form = self.get_search_form()
if search_form.is_valid():
query_str = search_form.cleaned_... | [
"Returns",
"queryset",
"instance",
"."
] | rfosterslo/wagtailplus | python | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L99-L112 | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"queryset",
"=",
"super",
"(",
"IndexView",
",",
"self",
")",
".",
"get_queryset",
"(",
")",
"search_form",
"=",
"self",
".",
"get_search_form",
"(",
")",
"if",
"search_form",
".",
"is_valid",
"(",
")",
":",
... | 22cac857175d8a6f77e470751831c14a92ccd768 |
train | IndexView.get_search_form | Returns search form instance.
:rtype: django.forms.ModelForm. | wagtailplus/utils/views/crud.py | def get_search_form(self):
"""
Returns search form instance.
:rtype: django.forms.ModelForm.
"""
#noinspection PyUnresolvedReferences
if 'q' in self.request.GET:
#noinspection PyUnresolvedReferences
return self.search_form_class(self.request.GET)
... | def get_search_form(self):
"""
Returns search form instance.
:rtype: django.forms.ModelForm.
"""
#noinspection PyUnresolvedReferences
if 'q' in self.request.GET:
#noinspection PyUnresolvedReferences
return self.search_form_class(self.request.GET)
... | [
"Returns",
"search",
"form",
"instance",
"."
] | rfosterslo/wagtailplus | python | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L114-L125 | [
"def",
"get_search_form",
"(",
"self",
")",
":",
"#noinspection PyUnresolvedReferences",
"if",
"'q'",
"in",
"self",
".",
"request",
".",
"GET",
":",
"#noinspection PyUnresolvedReferences",
"return",
"self",
".",
"search_form_class",
"(",
"self",
".",
"request",
".",... | 22cac857175d8a6f77e470751831c14a92ccd768 |
train | IndexView.get_template_names | Returns a list of template names for the view.
:rtype: list. | wagtailplus/utils/views/crud.py | def get_template_names(self):
"""
Returns a list of template names for the view.
:rtype: list.
"""
#noinspection PyUnresolvedReferences
if self.request.is_ajax():
template_name = '/results.html'
else:
template_name = '/index.html'
... | def get_template_names(self):
"""
Returns a list of template names for the view.
:rtype: list.
"""
#noinspection PyUnresolvedReferences
if self.request.is_ajax():
template_name = '/results.html'
else:
template_name = '/index.html'
... | [
"Returns",
"a",
"list",
"of",
"template",
"names",
"for",
"the",
"view",
"."
] | rfosterslo/wagtailplus | python | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L127-L139 | [
"def",
"get_template_names",
"(",
"self",
")",
":",
"#noinspection PyUnresolvedReferences",
"if",
"self",
".",
"request",
".",
"is_ajax",
"(",
")",
":",
"template_name",
"=",
"'/results.html'",
"else",
":",
"template_name",
"=",
"'/index.html'",
"return",
"[",
"'{... | 22cac857175d8a6f77e470751831c14a92ccd768 |
train | IndexView.paginate_queryset | Returns tuple containing paginator instance, page instance,
object list, and whether there are other pages.
:param queryset: the queryset instance to paginate.
:param page_size: the number of instances per page.
:rtype: tuple. | wagtailplus/utils/views/crud.py | def paginate_queryset(self, queryset, page_size):
"""
Returns tuple containing paginator instance, page instance,
object list, and whether there are other pages.
:param queryset: the queryset instance to paginate.
:param page_size: the number of instances per page.
:rtyp... | def paginate_queryset(self, queryset, page_size):
"""
Returns tuple containing paginator instance, page instance,
object list, and whether there are other pages.
:param queryset: the queryset instance to paginate.
:param page_size: the number of instances per page.
:rtyp... | [
"Returns",
"tuple",
"containing",
"paginator",
"instance",
"page",
"instance",
"object",
"list",
"and",
"whether",
"there",
"are",
"other",
"pages",
"."
] | rfosterslo/wagtailplus | python | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L141-L170 | [
"def",
"paginate_queryset",
"(",
"self",
",",
"queryset",
",",
"page_size",
")",
":",
"paginator",
"=",
"self",
".",
"get_paginator",
"(",
"queryset",
",",
"page_size",
",",
"orphans",
"=",
"self",
".",
"get_paginate_orphans",
"(",
")",
",",
"allow_empty_first... | 22cac857175d8a6f77e470751831c14a92ccd768 |
train | BaseEditView.form_invalid | Processes an invalid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse. | wagtailplus/utils/views/crud.py | def form_invalid(self, form):
"""
Processes an invalid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse.
"""
meta = getattr(self.model, '_meta')
#noinspection PyUnresolvedReferences
messages.error(
self.request... | def form_invalid(self, form):
"""
Processes an invalid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse.
"""
meta = getattr(self.model, '_meta')
#noinspection PyUnresolvedReferences
messages.error(
self.request... | [
"Processes",
"an",
"invalid",
"form",
"submittal",
"."
] | rfosterslo/wagtailplus | python | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L205-L222 | [
"def",
"form_invalid",
"(",
"self",
",",
"form",
")",
":",
"meta",
"=",
"getattr",
"(",
"self",
".",
"model",
",",
"'_meta'",
")",
"#noinspection PyUnresolvedReferences",
"messages",
".",
"error",
"(",
"self",
".",
"request",
",",
"_",
"(",
"u'The {0} could ... | 22cac857175d8a6f77e470751831c14a92ccd768 |
train | BaseEditView.form_valid | Processes a valid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse. | wagtailplus/utils/views/crud.py | def form_valid(self, form):
"""
Processes a valid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse.
"""
#noinspection PyAttributeOutsideInit
self.object = form.save()
meta = getattr(self.object, '_meta')
# I... | def form_valid(self, form):
"""
Processes a valid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse.
"""
#noinspection PyAttributeOutsideInit
self.object = form.save()
meta = getattr(self.object, '_meta')
# I... | [
"Processes",
"a",
"valid",
"form",
"submittal",
"."
] | rfosterslo/wagtailplus | python | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L224-L255 | [
"def",
"form_valid",
"(",
"self",
",",
"form",
")",
":",
"#noinspection PyAttributeOutsideInit",
"self",
".",
"object",
"=",
"form",
".",
"save",
"(",
")",
"meta",
"=",
"getattr",
"(",
"self",
".",
"object",
",",
"'_meta'",
")",
"# Index the object.",
"for",... | 22cac857175d8a6f77e470751831c14a92ccd768 |
train | BaseEditView.get_success_url | Returns redirect URL for valid form submittal.
:rtype: str. | wagtailplus/utils/views/crud.py | def get_success_url(self):
"""
Returns redirect URL for valid form submittal.
:rtype: str.
"""
if self.success_url:
url = force_text(self.success_url)
else:
url = reverse('{0}:index'.format(self.url_namespace))
return url | def get_success_url(self):
"""
Returns redirect URL for valid form submittal.
:rtype: str.
"""
if self.success_url:
url = force_text(self.success_url)
else:
url = reverse('{0}:index'.format(self.url_namespace))
return url | [
"Returns",
"redirect",
"URL",
"for",
"valid",
"form",
"submittal",
"."
] | rfosterslo/wagtailplus | python | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L257-L268 | [
"def",
"get_success_url",
"(",
"self",
")",
":",
"if",
"self",
".",
"success_url",
":",
"url",
"=",
"force_text",
"(",
"self",
".",
"success_url",
")",
"else",
":",
"url",
"=",
"reverse",
"(",
"'{0}:index'",
".",
"format",
"(",
"self",
".",
"url_namespac... | 22cac857175d8a6f77e470751831c14a92ccd768 |
train | DeleteView.delete | Processes deletion of the specified instance.
:param request: the request instance.
:rtype: django.http.HttpResponse. | wagtailplus/utils/views/crud.py | def delete(self, request, *args, **kwargs):
"""
Processes deletion of the specified instance.
:param request: the request instance.
:rtype: django.http.HttpResponse.
"""
#noinspection PyAttributeOutsideInit
self.object = self.get_object()
success_url = se... | def delete(self, request, *args, **kwargs):
"""
Processes deletion of the specified instance.
:param request: the request instance.
:rtype: django.http.HttpResponse.
"""
#noinspection PyAttributeOutsideInit
self.object = self.get_object()
success_url = se... | [
"Processes",
"deletion",
"of",
"the",
"specified",
"instance",
"."
] | rfosterslo/wagtailplus | python | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L301-L323 | [
"def",
"delete",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"#noinspection PyAttributeOutsideInit",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
... | 22cac857175d8a6f77e470751831c14a92ccd768 |
train | chunked | Returns chunks of n length of iterable
If len(iterable) % n != 0, then the last chunk will have length
less than n.
Example:
>>> chunked([1, 2, 3, 4, 5], 2)
[(1, 2), (3, 4), (5,)] | elasticutils/utils.py | def chunked(iterable, n):
"""Returns chunks of n length of iterable
If len(iterable) % n != 0, then the last chunk will have length
less than n.
Example:
>>> chunked([1, 2, 3, 4, 5], 2)
[(1, 2), (3, 4), (5,)]
"""
iterable = iter(iterable)
while 1:
t = tuple(islice(iterab... | def chunked(iterable, n):
"""Returns chunks of n length of iterable
If len(iterable) % n != 0, then the last chunk will have length
less than n.
Example:
>>> chunked([1, 2, 3, 4, 5], 2)
[(1, 2), (3, 4), (5,)]
"""
iterable = iter(iterable)
while 1:
t = tuple(islice(iterab... | [
"Returns",
"chunks",
"of",
"n",
"length",
"of",
"iterable"
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/utils.py#L33-L52 | [
"def",
"chunked",
"(",
"iterable",
",",
"n",
")",
":",
"iterable",
"=",
"iter",
"(",
"iterable",
")",
"while",
"1",
":",
"t",
"=",
"tuple",
"(",
"islice",
"(",
"iterable",
",",
"n",
")",
")",
"if",
"t",
":",
"yield",
"t",
"else",
":",
"return"
] | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | format_explanation | Return explanation in an easier to read format
Easier to read for me, at least. | elasticutils/utils.py | def format_explanation(explanation, indent=' ', indent_level=0):
"""Return explanation in an easier to read format
Easier to read for me, at least.
"""
if not explanation:
return ''
# Note: This is probably a crap implementation, but it's an
# interesting starting point for a better ... | def format_explanation(explanation, indent=' ', indent_level=0):
"""Return explanation in an easier to read format
Easier to read for me, at least.
"""
if not explanation:
return ''
# Note: This is probably a crap implementation, but it's an
# interesting starting point for a better ... | [
"Return",
"explanation",
"in",
"an",
"easier",
"to",
"read",
"format"
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/utils.py#L55-L76 | [
"def",
"format_explanation",
"(",
"explanation",
",",
"indent",
"=",
"' '",
",",
"indent_level",
"=",
"0",
")",
":",
"if",
"not",
"explanation",
":",
"return",
"''",
"# Note: This is probably a crap implementation, but it's an",
"# interesting starting point for a better f... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | get_es | Return a elasticsearch Elasticsearch object using settings
from ``settings.py``.
:arg overrides: Allows you to override defaults to create the
ElasticSearch object. You can override any of the arguments
isted in :py:func:`elasticutils.get_es`.
For example, if you wanted to create an Elasti... | elasticutils/contrib/django/__init__.py | def get_es(**overrides):
"""Return a elasticsearch Elasticsearch object using settings
from ``settings.py``.
:arg overrides: Allows you to override defaults to create the
ElasticSearch object. You can override any of the arguments
isted in :py:func:`elasticutils.get_es`.
For example, i... | def get_es(**overrides):
"""Return a elasticsearch Elasticsearch object using settings
from ``settings.py``.
:arg overrides: Allows you to override defaults to create the
ElasticSearch object. You can override any of the arguments
isted in :py:func:`elasticutils.get_es`.
For example, i... | [
"Return",
"a",
"elasticsearch",
"Elasticsearch",
"object",
"using",
"settings",
"from",
"settings",
".",
"py",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L26-L47 | [
"def",
"get_es",
"(",
"*",
"*",
"overrides",
")",
":",
"defaults",
"=",
"{",
"'urls'",
":",
"settings",
".",
"ES_URLS",
",",
"'timeout'",
":",
"getattr",
"(",
"settings",
",",
"'ES_TIMEOUT'",
",",
"5",
")",
"}",
"defaults",
".",
"update",
"(",
"overrid... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | es_required | Wrap a callable and return None if ES_DISABLED is False.
This also adds an additional `es` argument to the callable
giving you an ElasticSearch instance to use. | elasticutils/contrib/django/__init__.py | def es_required(fun):
"""Wrap a callable and return None if ES_DISABLED is False.
This also adds an additional `es` argument to the callable
giving you an ElasticSearch instance to use.
"""
@wraps(fun)
def wrapper(*args, **kw):
if getattr(settings, 'ES_DISABLED', False):
lo... | def es_required(fun):
"""Wrap a callable and return None if ES_DISABLED is False.
This also adds an additional `es` argument to the callable
giving you an ElasticSearch instance to use.
"""
@wraps(fun)
def wrapper(*args, **kw):
if getattr(settings, 'ES_DISABLED', False):
lo... | [
"Wrap",
"a",
"callable",
"and",
"return",
"None",
"if",
"ES_DISABLED",
"is",
"False",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L50-L64 | [
"def",
"es_required",
"(",
"fun",
")",
":",
"@",
"wraps",
"(",
"fun",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"if",
"getattr",
"(",
"settings",
",",
"'ES_DISABLED'",
",",
"False",
")",
":",
"log",
".",
"debug",
"("... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.get_es | Returns the elasticsearch Elasticsearch object to use.
This uses the django get_es builder by default which takes
into account settings in ``settings.py``. | elasticutils/contrib/django/__init__.py | def get_es(self, default_builder=get_es):
"""Returns the elasticsearch Elasticsearch object to use.
This uses the django get_es builder by default which takes
into account settings in ``settings.py``.
"""
return super(S, self).get_es(default_builder=default_builder) | def get_es(self, default_builder=get_es):
"""Returns the elasticsearch Elasticsearch object to use.
This uses the django get_es builder by default which takes
into account settings in ``settings.py``.
"""
return super(S, self).get_es(default_builder=default_builder) | [
"Returns",
"the",
"elasticsearch",
"Elasticsearch",
"object",
"to",
"use",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L165-L172 | [
"def",
"get_es",
"(",
"self",
",",
"default_builder",
"=",
"get_es",
")",
":",
"return",
"super",
"(",
"S",
",",
"self",
")",
".",
"get_es",
"(",
"default_builder",
"=",
"default_builder",
")"
] | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.get_indexes | Returns the list of indexes to act on based on ES_INDEXES setting | elasticutils/contrib/django/__init__.py | def get_indexes(self, default_indexes=None):
"""Returns the list of indexes to act on based on ES_INDEXES setting
"""
doctype = self.type.get_mapping_type_name()
indexes = (settings.ES_INDEXES.get(doctype) or
settings.ES_INDEXES['default'])
if isinstance(index... | def get_indexes(self, default_indexes=None):
"""Returns the list of indexes to act on based on ES_INDEXES setting
"""
doctype = self.type.get_mapping_type_name()
indexes = (settings.ES_INDEXES.get(doctype) or
settings.ES_INDEXES['default'])
if isinstance(index... | [
"Returns",
"the",
"list",
"of",
"indexes",
"to",
"act",
"on",
"based",
"on",
"ES_INDEXES",
"setting"
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L174-L183 | [
"def",
"get_indexes",
"(",
"self",
",",
"default_indexes",
"=",
"None",
")",
":",
"doctype",
"=",
"self",
".",
"type",
".",
"get_mapping_type_name",
"(",
")",
"indexes",
"=",
"(",
"settings",
".",
"ES_INDEXES",
".",
"get",
"(",
"doctype",
")",
"or",
"set... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.get_doctypes | Returns the doctypes (or mapping type names) to use. | elasticutils/contrib/django/__init__.py | def get_doctypes(self, default_doctypes=None):
"""Returns the doctypes (or mapping type names) to use."""
doctypes = self.type.get_mapping_type_name()
if isinstance(doctypes, six.string_types):
doctypes = [doctypes]
return super(S, self).get_doctypes(default_doctypes=doctypes... | def get_doctypes(self, default_doctypes=None):
"""Returns the doctypes (or mapping type names) to use."""
doctypes = self.type.get_mapping_type_name()
if isinstance(doctypes, six.string_types):
doctypes = [doctypes]
return super(S, self).get_doctypes(default_doctypes=doctypes... | [
"Returns",
"the",
"doctypes",
"(",
"or",
"mapping",
"type",
"names",
")",
"to",
"use",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L185-L190 | [
"def",
"get_doctypes",
"(",
"self",
",",
"default_doctypes",
"=",
"None",
")",
":",
"doctypes",
"=",
"self",
".",
"type",
".",
"get_mapping_type_name",
"(",
")",
"if",
"isinstance",
"(",
"doctypes",
",",
"six",
".",
"string_types",
")",
":",
"doctypes",
"=... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | MappingType.get_index | Gets the index for this model.
The index for this model is specified in `settings.ES_INDEXES`
which is a dict of mapping type -> index name.
By default, this uses `.get_mapping_type()` to determine the
mapping and returns the value in `settings.ES_INDEXES` for that
or ``setting... | elasticutils/contrib/django/__init__.py | def get_index(cls):
"""Gets the index for this model.
The index for this model is specified in `settings.ES_INDEXES`
which is a dict of mapping type -> index name.
By default, this uses `.get_mapping_type()` to determine the
mapping and returns the value in `settings.ES_INDEXES... | def get_index(cls):
"""Gets the index for this model.
The index for this model is specified in `settings.ES_INDEXES`
which is a dict of mapping type -> index name.
By default, this uses `.get_mapping_type()` to determine the
mapping and returns the value in `settings.ES_INDEXES... | [
"Gets",
"the",
"index",
"for",
"this",
"model",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L225-L246 | [
"def",
"get_index",
"(",
"cls",
")",
":",
"indexes",
"=",
"settings",
".",
"ES_INDEXES",
"index",
"=",
"indexes",
".",
"get",
"(",
"cls",
".",
"get_mapping_type_name",
"(",
")",
")",
"or",
"indexes",
"[",
"'default'",
"]",
"if",
"not",
"(",
"isinstance",... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | Indexable.get_indexable | Returns the queryset of ids of all things to be indexed.
Defaults to::
cls.get_model().objects.order_by('id').values_list(
'id', flat=True)
:returns: iterable of ids of objects to be indexed | elasticutils/contrib/django/__init__.py | def get_indexable(cls):
"""Returns the queryset of ids of all things to be indexed.
Defaults to::
cls.get_model().objects.order_by('id').values_list(
'id', flat=True)
:returns: iterable of ids of objects to be indexed
"""
model = cls.get_model()
... | def get_indexable(cls):
"""Returns the queryset of ids of all things to be indexed.
Defaults to::
cls.get_model().objects.order_by('id').values_list(
'id', flat=True)
:returns: iterable of ids of objects to be indexed
"""
model = cls.get_model()
... | [
"Returns",
"the",
"queryset",
"of",
"ids",
"of",
"all",
"things",
"to",
"be",
"indexed",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L298-L310 | [
"def",
"get_indexable",
"(",
"cls",
")",
":",
"model",
"=",
"cls",
".",
"get_model",
"(",
")",
"return",
"model",
".",
"objects",
".",
"order_by",
"(",
"'id'",
")",
".",
"values_list",
"(",
"'id'",
",",
"flat",
"=",
"True",
")"
] | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | get_es | Create an elasticsearch `Elasticsearch` object and return it.
This will aggressively re-use `Elasticsearch` objects with the
following rules:
1. if you pass the same argument values to `get_es()`, then it
will return the same `Elasticsearch` object
2. if you pass different argument values to `g... | elasticutils/__init__.py | def get_es(urls=None, timeout=DEFAULT_TIMEOUT, force_new=False, **settings):
"""Create an elasticsearch `Elasticsearch` object and return it.
This will aggressively re-use `Elasticsearch` objects with the
following rules:
1. if you pass the same argument values to `get_es()`, then it
will retur... | def get_es(urls=None, timeout=DEFAULT_TIMEOUT, force_new=False, **settings):
"""Create an elasticsearch `Elasticsearch` object and return it.
This will aggressively re-use `Elasticsearch` objects with the
following rules:
1. if you pass the same argument values to `get_es()`, then it
will retur... | [
"Create",
"an",
"elasticsearch",
"Elasticsearch",
"object",
"and",
"return",
"it",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L109-L167 | [
"def",
"get_es",
"(",
"urls",
"=",
"None",
",",
"timeout",
"=",
"DEFAULT_TIMEOUT",
",",
"force_new",
"=",
"False",
",",
"*",
"*",
"settings",
")",
":",
"# Cheap way of de-None-ifying things",
"urls",
"=",
"urls",
"or",
"DEFAULT_URLS",
"# v0.7: Check for 'hosts' in... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | _facet_counts | Returns facet counts as dict.
Given the `items()` on the raw dictionary from Elasticsearch this processes
it and returns the counts keyed on the facet name provided in the original
query. | elasticutils/__init__.py | def _facet_counts(items):
"""Returns facet counts as dict.
Given the `items()` on the raw dictionary from Elasticsearch this processes
it and returns the counts keyed on the facet name provided in the original
query.
"""
facets = {}
for name, data in items:
facets[name] = FacetResu... | def _facet_counts(items):
"""Returns facet counts as dict.
Given the `items()` on the raw dictionary from Elasticsearch this processes
it and returns the counts keyed on the facet name provided in the original
query.
"""
facets = {}
for name, data in items:
facets[name] = FacetResu... | [
"Returns",
"facet",
"counts",
"as",
"dict",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L203-L214 | [
"def",
"_facet_counts",
"(",
"items",
")",
":",
"facets",
"=",
"{",
"}",
"for",
"name",
",",
"data",
"in",
"items",
":",
"facets",
"[",
"name",
"]",
"=",
"FacetResult",
"(",
"name",
",",
"data",
")",
"return",
"facets"
] | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | _boosted_value | Boost a value if we should in _process_queries | elasticutils/__init__.py | def _boosted_value(name, action, key, value, boost):
"""Boost a value if we should in _process_queries"""
if boost is not None:
# Note: Most queries use 'value' for the key name except
# Match queries which use 'query'. So we have to do some
# switcheroo for that.
value_key = 'qu... | def _boosted_value(name, action, key, value, boost):
"""Boost a value if we should in _process_queries"""
if boost is not None:
# Note: Most queries use 'value' for the key name except
# Match queries which use 'query'. So we have to do some
# switcheroo for that.
value_key = 'qu... | [
"Boost",
"a",
"value",
"if",
"we",
"should",
"in",
"_process_queries"
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L397-L405 | [
"def",
"_boosted_value",
"(",
"name",
",",
"action",
",",
"key",
",",
"value",
",",
"boost",
")",
":",
"if",
"boost",
"is",
"not",
"None",
":",
"# Note: Most queries use 'value' for the key name except",
"# Match queries which use 'query'. So we have to do some",
"# switc... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | decorate_with_metadata | Return obj decorated with es_meta object | elasticutils/__init__.py | def decorate_with_metadata(obj, result):
"""Return obj decorated with es_meta object"""
# Create es_meta object with Elasticsearch metadata about this
# search result
obj.es_meta = Metadata(
# Elasticsearch id
id=result.get('_id', 0),
# Source data
source=result.get('_sou... | def decorate_with_metadata(obj, result):
"""Return obj decorated with es_meta object"""
# Create es_meta object with Elasticsearch metadata about this
# search result
obj.es_meta = Metadata(
# Elasticsearch id
id=result.get('_id', 0),
# Source data
source=result.get('_sou... | [
"Return",
"obj",
"decorated",
"with",
"es_meta",
"object"
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1918-L1938 | [
"def",
"decorate_with_metadata",
"(",
"obj",
",",
"result",
")",
":",
"# Create es_meta object with Elasticsearch metadata about this",
"# search result",
"obj",
".",
"es_meta",
"=",
"Metadata",
"(",
"# Elasticsearch id",
"id",
"=",
"result",
".",
"get",
"(",
"'_id'",
... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | F._combine | OR and AND will create a new F, with the filters from both F
objects combined with the connector `conn`. | elasticutils/__init__.py | def _combine(self, other, conn='and'):
"""
OR and AND will create a new F, with the filters from both F
objects combined with the connector `conn`.
"""
f = F()
self_filters = copy.deepcopy(self.filters)
other_filters = copy.deepcopy(other.filters)
if not... | def _combine(self, other, conn='and'):
"""
OR and AND will create a new F, with the filters from both F
objects combined with the connector `conn`.
"""
f = F()
self_filters = copy.deepcopy(self.filters)
other_filters = copy.deepcopy(other.filters)
if not... | [
"OR",
"and",
"AND",
"will",
"create",
"a",
"new",
"F",
"with",
"the",
"filters",
"from",
"both",
"F",
"objects",
"combined",
"with",
"the",
"connector",
"conn",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L277-L300 | [
"def",
"_combine",
"(",
"self",
",",
"other",
",",
"conn",
"=",
"'and'",
")",
":",
"f",
"=",
"F",
"(",
")",
"self_filters",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"filters",
")",
"other_filters",
"=",
"copy",
".",
"deepcopy",
"(",
"other",
... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | PythonMixin.to_python | Converts strings in a data structure to Python types
It converts datetime-ish things to Python datetimes.
Override if you want something different.
:arg obj: Python datastructure
:returns: Python datastructure with strings converted to
Python types
.. Note::
... | elasticutils/__init__.py | def to_python(self, obj):
"""Converts strings in a data structure to Python types
It converts datetime-ish things to Python datetimes.
Override if you want something different.
:arg obj: Python datastructure
:returns: Python datastructure with strings converted to
... | def to_python(self, obj):
"""Converts strings in a data structure to Python types
It converts datetime-ish things to Python datetimes.
Override if you want something different.
:arg obj: Python datastructure
:returns: Python datastructure with strings converted to
... | [
"Converts",
"strings",
"in",
"a",
"data",
"structure",
"to",
"Python",
"types"
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L410-L451 | [
"def",
"to_python",
"(",
"self",
",",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"string_types",
")",
":",
"if",
"len",
"(",
"obj",
")",
"==",
"26",
":",
"try",
":",
"return",
"datetime",
".",
"strptime",
"(",
"obj",
",",
"'%Y-%m-%dT%H:%M:... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.query | Return a new S instance with query args combined with existing
set in a must boolean query.
:arg queries: instances of Q
:arg kw: queries in the form of ``field__action=value``
There are three special flags you can use:
* ``must=True``: Specifies that the queries and kw querie... | elasticutils/__init__.py | def query(self, *queries, **kw):
"""
Return a new S instance with query args combined with existing
set in a must boolean query.
:arg queries: instances of Q
:arg kw: queries in the form of ``field__action=value``
There are three special flags you can use:
* ``... | def query(self, *queries, **kw):
"""
Return a new S instance with query args combined with existing
set in a must boolean query.
:arg queries: instances of Q
:arg kw: queries in the form of ``field__action=value``
There are three special flags you can use:
* ``... | [
"Return",
"a",
"new",
"S",
"instance",
"with",
"query",
"args",
"combined",
"with",
"existing",
"set",
"in",
"a",
"must",
"boolean",
"query",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L694-L759 | [
"def",
"query",
"(",
"self",
",",
"*",
"queries",
",",
"*",
"*",
"kw",
")",
":",
"q",
"=",
"Q",
"(",
")",
"for",
"query",
"in",
"queries",
":",
"q",
"+=",
"query",
"if",
"'or_'",
"in",
"kw",
":",
"# Backwards compatibile with pre-0.7 version.",
"or_que... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.filter | Return a new S instance with filter args combined with
existing set with AND.
:arg filters: this will be instances of F
:arg kw: this will be in the form of ``field__action=value``
Examples:
>>> s = S().filter(foo='bar')
>>> s = S().filter(F(foo='bar'))
>>> s =... | elasticutils/__init__.py | def filter(self, *filters, **kw):
"""
Return a new S instance with filter args combined with
existing set with AND.
:arg filters: this will be instances of F
:arg kw: this will be in the form of ``field__action=value``
Examples:
>>> s = S().filter(foo='bar')
... | def filter(self, *filters, **kw):
"""
Return a new S instance with filter args combined with
existing set with AND.
:arg filters: this will be instances of F
:arg kw: this will be in the form of ``field__action=value``
Examples:
>>> s = S().filter(foo='bar')
... | [
"Return",
"a",
"new",
"S",
"instance",
"with",
"filter",
"args",
"combined",
"with",
"existing",
"set",
"with",
"AND",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L782-L817 | [
"def",
"filter",
"(",
"self",
",",
"*",
"filters",
",",
"*",
"*",
"kw",
")",
":",
"items",
"=",
"kw",
".",
"items",
"(",
")",
"if",
"six",
".",
"PY3",
":",
"items",
"=",
"list",
"(",
"items",
")",
"return",
"self",
".",
"_clone",
"(",
"next_ste... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.boost | Return a new S instance with field boosts.
ElasticUtils allows you to specify query-time field boosts
with ``.boost()``. It takes a set of arguments where the keys
are either field names or field name + ``__`` + field action.
Examples::
q = (S().query(title='taco trucks',
... | elasticutils/__init__.py | def boost(self, **kw):
"""
Return a new S instance with field boosts.
ElasticUtils allows you to specify query-time field boosts
with ``.boost()``. It takes a set of arguments where the keys
are either field names or field name + ``__`` + field action.
Examples::
... | def boost(self, **kw):
"""
Return a new S instance with field boosts.
ElasticUtils allows you to specify query-time field boosts
with ``.boost()``. It takes a set of arguments where the keys
are either field names or field name + ``__`` + field action.
Examples::
... | [
"Return",
"a",
"new",
"S",
"instance",
"with",
"field",
"boosts",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L839-L897 | [
"def",
"boost",
"(",
"self",
",",
"*",
"*",
"kw",
")",
":",
"new",
"=",
"self",
".",
"_clone",
"(",
")",
"new",
".",
"field_boosts",
".",
"update",
"(",
"kw",
")",
"return",
"new"
] | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.demote | Returns a new S instance with boosting query and demotion.
You can demote documents that match query criteria::
q = (S().query(title='trucks')
.demote(0.5, description__match='gross'))
q = (S().query(title='trucks')
.demote(0.5, Q(description__m... | elasticutils/__init__.py | def demote(self, amount_, *queries, **kw):
"""
Returns a new S instance with boosting query and demotion.
You can demote documents that match query criteria::
q = (S().query(title='trucks')
.demote(0.5, description__match='gross'))
q = (S().query(ti... | def demote(self, amount_, *queries, **kw):
"""
Returns a new S instance with boosting query and demotion.
You can demote documents that match query criteria::
q = (S().query(title='trucks')
.demote(0.5, description__match='gross'))
q = (S().query(ti... | [
"Returns",
"a",
"new",
"S",
"instance",
"with",
"boosting",
"query",
"and",
"demotion",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L899-L928 | [
"def",
"demote",
"(",
"self",
",",
"amount_",
",",
"*",
"queries",
",",
"*",
"*",
"kw",
")",
":",
"q",
"=",
"Q",
"(",
")",
"for",
"query",
"in",
"queries",
":",
"q",
"+=",
"query",
"q",
"+=",
"Q",
"(",
"*",
"*",
"kw",
")",
"return",
"self",
... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.facet_raw | Return a new S instance with raw facet args combined with
existing set. | elasticutils/__init__.py | def facet_raw(self, **kw):
"""
Return a new S instance with raw facet args combined with
existing set.
"""
items = kw.items()
if six.PY3:
items = list(items)
return self._clone(next_step=('facet_raw', items)) | def facet_raw(self, **kw):
"""
Return a new S instance with raw facet args combined with
existing set.
"""
items = kw.items()
if six.PY3:
items = list(items)
return self._clone(next_step=('facet_raw', items)) | [
"Return",
"a",
"new",
"S",
"instance",
"with",
"raw",
"facet",
"args",
"combined",
"with",
"existing",
"set",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L944-L952 | [
"def",
"facet_raw",
"(",
"self",
",",
"*",
"*",
"kw",
")",
":",
"items",
"=",
"kw",
".",
"items",
"(",
")",
"if",
"six",
".",
"PY3",
":",
"items",
"=",
"list",
"(",
"items",
")",
"return",
"self",
".",
"_clone",
"(",
"next_step",
"=",
"(",
"'fa... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.suggest | Set suggestion options.
:arg name: The name to use for the suggestions.
:arg term: The term to suggest similar looking terms for.
Additional keyword options:
* ``field`` -- The field to base suggestions upon, defaults to _all
Results will have a ``_suggestions`` property cont... | elasticutils/__init__.py | def suggest(self, name, term, **kwargs):
"""Set suggestion options.
:arg name: The name to use for the suggestions.
:arg term: The term to suggest similar looking terms for.
Additional keyword options:
* ``field`` -- The field to base suggestions upon, defaults to _all
... | def suggest(self, name, term, **kwargs):
"""Set suggestion options.
:arg name: The name to use for the suggestions.
:arg term: The term to suggest similar looking terms for.
Additional keyword options:
* ``field`` -- The field to base suggestions upon, defaults to _all
... | [
"Set",
"suggestion",
"options",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1019-L1039 | [
"def",
"suggest",
"(",
"self",
",",
"name",
",",
"term",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_clone",
"(",
"next_step",
"=",
"(",
"'suggest'",
",",
"(",
"name",
",",
"term",
",",
"kwargs",
")",
")",
")"
] | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.extra | Return a new S instance with extra args combined with existing
set. | elasticutils/__init__.py | def extra(self, **kw):
"""
Return a new S instance with extra args combined with existing
set.
"""
new = self._clone()
actions = ['values_list', 'values_dict', 'order_by', 'query',
'filter', 'facet']
for key, vals in kw.items():
asse... | def extra(self, **kw):
"""
Return a new S instance with extra args combined with existing
set.
"""
new = self._clone()
actions = ['values_list', 'values_dict', 'order_by', 'query',
'filter', 'facet']
for key, vals in kw.items():
asse... | [
"Return",
"a",
"new",
"S",
"instance",
"with",
"extra",
"args",
"combined",
"with",
"existing",
"set",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1041-L1055 | [
"def",
"extra",
"(",
"self",
",",
"*",
"*",
"kw",
")",
":",
"new",
"=",
"self",
".",
"_clone",
"(",
")",
"actions",
"=",
"[",
"'values_list'",
",",
"'values_dict'",
",",
"'order_by'",
",",
"'query'",
",",
"'filter'",
",",
"'facet'",
"]",
"for",
"key"... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.build_search | Builds the Elasticsearch search body represented by this S.
Loop over self.steps to build the search body that will be
sent to Elasticsearch. This returns a Python dict.
If you want the JSON that actually gets sent, then pass the return
value through :py:func:`elasticutils.utils.to_jso... | elasticutils/__init__.py | def build_search(self):
"""Builds the Elasticsearch search body represented by this S.
Loop over self.steps to build the search body that will be
sent to Elasticsearch. This returns a Python dict.
If you want the JSON that actually gets sent, then pass the return
value through ... | def build_search(self):
"""Builds the Elasticsearch search body represented by this S.
Loop over self.steps to build the search body that will be
sent to Elasticsearch. This returns a Python dict.
If you want the JSON that actually gets sent, then pass the return
value through ... | [
"Builds",
"the",
"Elasticsearch",
"search",
"body",
"represented",
"by",
"this",
"S",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1067-L1227 | [
"def",
"build_search",
"(",
"self",
")",
":",
"filters",
"=",
"[",
"]",
"filters_raw",
"=",
"None",
"queries",
"=",
"[",
"]",
"query_raw",
"=",
"None",
"sort",
"=",
"[",
"]",
"dict_fields",
"=",
"set",
"(",
")",
"list_fields",
"=",
"set",
"(",
")",
... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S._build_highlight | Return the portion of the query that controls highlighting. | elasticutils/__init__.py | def _build_highlight(self, fields, options):
"""Return the portion of the query that controls highlighting."""
ret = {'fields': dict((f, {}) for f in fields),
'order': 'score'}
ret.update(options)
return ret | def _build_highlight(self, fields, options):
"""Return the portion of the query that controls highlighting."""
ret = {'fields': dict((f, {}) for f in fields),
'order': 'score'}
ret.update(options)
return ret | [
"Return",
"the",
"portion",
"of",
"the",
"query",
"that",
"controls",
"highlighting",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1229-L1234 | [
"def",
"_build_highlight",
"(",
"self",
",",
"fields",
",",
"options",
")",
":",
"ret",
"=",
"{",
"'fields'",
":",
"dict",
"(",
"(",
"f",
",",
"{",
"}",
")",
"for",
"f",
"in",
"fields",
")",
",",
"'order'",
":",
"'score'",
"}",
"ret",
".",
"updat... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S._process_filters | Takes a list of filters and returns ES JSON API
:arg filters: list of F, (key, val) tuples, or dicts
:returns: list of ES JSON API filters | elasticutils/__init__.py | def _process_filters(self, filters):
"""Takes a list of filters and returns ES JSON API
:arg filters: list of F, (key, val) tuples, or dicts
:returns: list of ES JSON API filters
"""
rv = []
for f in filters:
if isinstance(f, F):
if f.filter... | def _process_filters(self, filters):
"""Takes a list of filters and returns ES JSON API
:arg filters: list of F, (key, val) tuples, or dicts
:returns: list of ES JSON API filters
"""
rv = []
for f in filters:
if isinstance(f, F):
if f.filter... | [
"Takes",
"a",
"list",
"of",
"filters",
"and",
"returns",
"ES",
"JSON",
"API"
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1236-L1318 | [
"def",
"_process_filters",
"(",
"self",
",",
"filters",
")",
":",
"rv",
"=",
"[",
"]",
"for",
"f",
"in",
"filters",
":",
"if",
"isinstance",
"(",
"f",
",",
"F",
")",
":",
"if",
"f",
".",
"filters",
":",
"rv",
".",
"extend",
"(",
"self",
".",
"_... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S._process_query | Takes a key/val pair and returns the Elasticsearch code for it | elasticutils/__init__.py | def _process_query(self, query):
"""Takes a key/val pair and returns the Elasticsearch code for it"""
key, val = query
field_name, field_action = split_field_action(key)
# Boost by name__action overrides boost by name.
boost = self.field_boosts.get(key)
if boost is None:... | def _process_query(self, query):
"""Takes a key/val pair and returns the Elasticsearch code for it"""
key, val = query
field_name, field_action = split_field_action(key)
# Boost by name__action overrides boost by name.
boost = self.field_boosts.get(key)
if boost is None:... | [
"Takes",
"a",
"key",
"/",
"val",
"pair",
"and",
"returns",
"the",
"Elasticsearch",
"code",
"for",
"it"
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1320-L1371 | [
"def",
"_process_query",
"(",
"self",
",",
"query",
")",
":",
"key",
",",
"val",
"=",
"query",
"field_name",
",",
"field_action",
"=",
"split_field_action",
"(",
"key",
")",
"# Boost by name__action overrides boost by name.",
"boost",
"=",
"self",
".",
"field_boos... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S._process_queries | Takes a list of queries and returns query clause value
:arg queries: list of Q instances
:returns: dict which is the query clause value | elasticutils/__init__.py | def _process_queries(self, queries):
"""Takes a list of queries and returns query clause value
:arg queries: list of Q instances
:returns: dict which is the query clause value
"""
# First, let's mush everything into a single Q. Then we can
# parse that into bits.
... | def _process_queries(self, queries):
"""Takes a list of queries and returns query clause value
:arg queries: list of Q instances
:returns: dict which is the query clause value
"""
# First, let's mush everything into a single Q. Then we can
# parse that into bits.
... | [
"Takes",
"a",
"list",
"of",
"queries",
"and",
"returns",
"query",
"clause",
"value"
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1373-L1411 | [
"def",
"_process_queries",
"(",
"self",
",",
"queries",
")",
":",
"# First, let's mush everything into a single Q. Then we can",
"# parse that into bits.",
"new_q",
"=",
"Q",
"(",
")",
"for",
"query",
"in",
"queries",
":",
"new_q",
"+=",
"query",
"# Now we have a single... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S._do_search | Perform the search, then convert that raw format into a
SearchResults instance and return it. | elasticutils/__init__.py | def _do_search(self):
"""
Perform the search, then convert that raw format into a
SearchResults instance and return it.
"""
if self._results_cache is None:
response = self.raw()
ResultsClass = self.get_results_class()
results = self.to_python(r... | def _do_search(self):
"""
Perform the search, then convert that raw format into a
SearchResults instance and return it.
"""
if self._results_cache is None:
response = self.raw()
ResultsClass = self.get_results_class()
results = self.to_python(r... | [
"Perform",
"the",
"search",
"then",
"convert",
"that",
"raw",
"format",
"into",
"a",
"SearchResults",
"instance",
"and",
"return",
"it",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1426-L1437 | [
"def",
"_do_search",
"(",
"self",
")",
":",
"if",
"self",
".",
"_results_cache",
"is",
"None",
":",
"response",
"=",
"self",
".",
"raw",
"(",
")",
"ResultsClass",
"=",
"self",
".",
"get_results_class",
"(",
")",
"results",
"=",
"self",
".",
"to_python",
... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.get_es | Returns the Elasticsearch object to use.
:arg default_builder: The function that takes a bunch of
arguments and generates a elasticsearch Elasticsearch
object.
.. Note::
If you desire special behavior regarding building the
Elasticsearch object for this S... | elasticutils/__init__.py | def get_es(self, default_builder=get_es):
"""Returns the Elasticsearch object to use.
:arg default_builder: The function that takes a bunch of
arguments and generates a elasticsearch Elasticsearch
object.
.. Note::
If you desire special behavior regarding bu... | def get_es(self, default_builder=get_es):
"""Returns the Elasticsearch object to use.
:arg default_builder: The function that takes a bunch of
arguments and generates a elasticsearch Elasticsearch
object.
.. Note::
If you desire special behavior regarding bu... | [
"Returns",
"the",
"Elasticsearch",
"object",
"to",
"use",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1439-L1462 | [
"def",
"get_es",
"(",
"self",
",",
"default_builder",
"=",
"get_es",
")",
":",
"# .es() calls are incremental, so we go through them all and",
"# update bits that are specified.",
"args",
"=",
"{",
"}",
"for",
"action",
",",
"value",
"in",
"self",
".",
"steps",
":",
... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.get_indexes | Returns the list of indexes to act on. | elasticutils/__init__.py | def get_indexes(self, default_indexes=DEFAULT_INDEXES):
"""Returns the list of indexes to act on."""
for action, value in reversed(self.steps):
if action == 'indexes':
return list(value)
if self.type is not None:
indexes = self.type.get_index()
... | def get_indexes(self, default_indexes=DEFAULT_INDEXES):
"""Returns the list of indexes to act on."""
for action, value in reversed(self.steps):
if action == 'indexes':
return list(value)
if self.type is not None:
indexes = self.type.get_index()
... | [
"Returns",
"the",
"list",
"of",
"indexes",
"to",
"act",
"on",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1464-L1476 | [
"def",
"get_indexes",
"(",
"self",
",",
"default_indexes",
"=",
"DEFAULT_INDEXES",
")",
":",
"for",
"action",
",",
"value",
"in",
"reversed",
"(",
"self",
".",
"steps",
")",
":",
"if",
"action",
"==",
"'indexes'",
":",
"return",
"list",
"(",
"value",
")"... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.get_doctypes | Returns the list of doctypes to use. | elasticutils/__init__.py | def get_doctypes(self, default_doctypes=DEFAULT_DOCTYPES):
"""Returns the list of doctypes to use."""
for action, value in reversed(self.steps):
if action == 'doctypes':
return list(value)
if self.type is not None:
return [self.type.get_mapping_type_name(... | def get_doctypes(self, default_doctypes=DEFAULT_DOCTYPES):
"""Returns the list of doctypes to use."""
for action, value in reversed(self.steps):
if action == 'doctypes':
return list(value)
if self.type is not None:
return [self.type.get_mapping_type_name(... | [
"Returns",
"the",
"list",
"of",
"doctypes",
"to",
"use",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1478-L1487 | [
"def",
"get_doctypes",
"(",
"self",
",",
"default_doctypes",
"=",
"DEFAULT_DOCTYPES",
")",
":",
"for",
"action",
",",
"value",
"in",
"reversed",
"(",
"self",
".",
"steps",
")",
":",
"if",
"action",
"==",
"'doctypes'",
":",
"return",
"list",
"(",
"value",
... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | S.raw | Build query and passes to Elasticsearch, then returns the raw
format returned. | elasticutils/__init__.py | def raw(self):
"""
Build query and passes to Elasticsearch, then returns the raw
format returned.
"""
qs = self.build_search()
es = self.get_es()
index = self.get_indexes()
doc_type = self.get_doctypes()
if doc_type and not index:
rai... | def raw(self):
"""
Build query and passes to Elasticsearch, then returns the raw
format returned.
"""
qs = self.build_search()
es = self.get_es()
index = self.get_indexes()
doc_type = self.get_doctypes()
if doc_type and not index:
rai... | [
"Build",
"query",
"and",
"passes",
"to",
"Elasticsearch",
"then",
"returns",
"the",
"raw",
"format",
"returned",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1489-L1514 | [
"def",
"raw",
"(",
"self",
")",
":",
"qs",
"=",
"self",
".",
"build_search",
"(",
")",
"es",
"=",
"self",
".",
"get_es",
"(",
")",
"index",
"=",
"self",
".",
"get_indexes",
"(",
")",
"doc_type",
"=",
"self",
".",
"get_doctypes",
"(",
")",
"if",
"... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | MLT.get_es | Returns an `Elasticsearch`.
* If there's an s, then it returns that `Elasticsearch`.
* If the es was provided in the constructor, then it returns
that `Elasticsearch`.
* Otherwise, it creates a new `Elasticsearch` and returns
that.
Override this if that behavior isn... | elasticutils/__init__.py | def get_es(self):
"""Returns an `Elasticsearch`.
* If there's an s, then it returns that `Elasticsearch`.
* If the es was provided in the constructor, then it returns
that `Elasticsearch`.
* Otherwise, it creates a new `Elasticsearch` and returns
that.
Overr... | def get_es(self):
"""Returns an `Elasticsearch`.
* If there's an s, then it returns that `Elasticsearch`.
* If the es was provided in the constructor, then it returns
that `Elasticsearch`.
* Otherwise, it creates a new `Elasticsearch` and returns
that.
Overr... | [
"Returns",
"an",
"Elasticsearch",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1721-L1736 | [
"def",
"get_es",
"(",
"self",
")",
":",
"if",
"self",
".",
"s",
":",
"return",
"self",
".",
"s",
".",
"get_es",
"(",
")",
"return",
"self",
".",
"es",
"or",
"get_es",
"(",
")"
] | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | MLT.raw | Build query and passes to `Elasticsearch`, then returns the raw
format returned. | elasticutils/__init__.py | def raw(self):
"""
Build query and passes to `Elasticsearch`, then returns the raw
format returned.
"""
es = self.get_es()
params = dict(self.query_params)
mlt_fields = self.mlt_fields or params.pop('mlt_fields', [])
body = self.s.build_search() if self.... | def raw(self):
"""
Build query and passes to `Elasticsearch`, then returns the raw
format returned.
"""
es = self.get_es()
params = dict(self.query_params)
mlt_fields = self.mlt_fields or params.pop('mlt_fields', [])
body = self.s.build_search() if self.... | [
"Build",
"query",
"and",
"passes",
"to",
"Elasticsearch",
"then",
"returns",
"the",
"raw",
"format",
"returned",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1738-L1756 | [
"def",
"raw",
"(",
"self",
")",
":",
"es",
"=",
"self",
".",
"get_es",
"(",
")",
"params",
"=",
"dict",
"(",
"self",
".",
"query_params",
")",
"mlt_fields",
"=",
"self",
".",
"mlt_fields",
"or",
"params",
".",
"pop",
"(",
"'mlt_fields'",
",",
"[",
... | b880cc5d51fb1079b0581255ec664c1ec934656e |
train | MLT._do_search | Perform the mlt call, then convert that raw format into a
SearchResults instance and return it. | elasticutils/__init__.py | def _do_search(self):
"""
Perform the mlt call, then convert that raw format into a
SearchResults instance and return it.
"""
if self._results_cache is None:
response = self.raw()
results = self.to_python(response.get('hits', {}).get('hits', []))
... | def _do_search(self):
"""
Perform the mlt call, then convert that raw format into a
SearchResults instance and return it.
"""
if self._results_cache is None:
response = self.raw()
results = self.to_python(response.get('hits', {}).get('hits', []))
... | [
"Perform",
"the",
"mlt",
"call",
"then",
"convert",
"that",
"raw",
"format",
"into",
"a",
"SearchResults",
"instance",
"and",
"return",
"it",
"."
] | mozilla/elasticutils | python | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1758-L1768 | [
"def",
"_do_search",
"(",
"self",
")",
":",
"if",
"self",
".",
"_results_cache",
"is",
"None",
":",
"response",
"=",
"self",
".",
"raw",
"(",
")",
"results",
"=",
"self",
".",
"to_python",
"(",
"response",
".",
"get",
"(",
"'hits'",
",",
"{",
"}",
... | b880cc5d51fb1079b0581255ec664c1ec934656e |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.