id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
249,600 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_heliplane.py | HeliPlaneModule.update_channels | def update_channels(self):
'''update which channels provide input'''
self.interlock_channel = -1
self.override_channel = -1
self.zero_I_channel = -1
self.no_vtol_channel = -1
# output channels
self.rsc_out_channel = 9
self.fwd_thr_channel = 10
fo... | python | def update_channels(self):
'''update which channels provide input'''
self.interlock_channel = -1
self.override_channel = -1
self.zero_I_channel = -1
self.no_vtol_channel = -1
# output channels
self.rsc_out_channel = 9
self.fwd_thr_channel = 10
fo... | [
"def",
"update_channels",
"(",
"self",
")",
":",
"self",
".",
"interlock_channel",
"=",
"-",
"1",
"self",
".",
"override_channel",
"=",
"-",
"1",
"self",
".",
"zero_I_channel",
"=",
"-",
"1",
"self",
".",
"no_vtol_channel",
"=",
"-",
"1",
"# output channel... | update which channels provide input | [
"update",
"which",
"channels",
"provide",
"input"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_heliplane.py#L102-L130 |
249,601 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_rally.py | RallyModule.rallyloader | def rallyloader(self):
'''rally loader by system ID'''
if not self.target_system in self.rallyloader_by_sysid:
self.rallyloader_by_sysid[self.target_system] = mavwp.MAVRallyLoader(self.settings.target_system,
se... | python | def rallyloader(self):
'''rally loader by system ID'''
if not self.target_system in self.rallyloader_by_sysid:
self.rallyloader_by_sysid[self.target_system] = mavwp.MAVRallyLoader(self.settings.target_system,
se... | [
"def",
"rallyloader",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"target_system",
"in",
"self",
".",
"rallyloader_by_sysid",
":",
"self",
".",
"rallyloader_by_sysid",
"[",
"self",
".",
"target_system",
"]",
"=",
"mavwp",
".",
"MAVRallyLoader",
"(",
"se... | rally loader by system ID | [
"rally",
"loader",
"by",
"system",
"ID"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_rally.py#L45-L50 |
249,602 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_dataflash_logger.py | dataflash_logger.packet_is_for_me | def packet_is_for_me(self, m):
'''returns true if this packet is appropriately addressed'''
if m.target_system != self.master.mav.srcSystem:
return False
if m.target_component != self.master.mav.srcComponent:
return False
# if have a sender we can also check the s... | python | def packet_is_for_me(self, m):
'''returns true if this packet is appropriately addressed'''
if m.target_system != self.master.mav.srcSystem:
return False
if m.target_component != self.master.mav.srcComponent:
return False
# if have a sender we can also check the s... | [
"def",
"packet_is_for_me",
"(",
"self",
",",
"m",
")",
":",
"if",
"m",
".",
"target_system",
"!=",
"self",
".",
"master",
".",
"mav",
".",
"srcSystem",
":",
"return",
"False",
"if",
"m",
".",
"target_component",
"!=",
"self",
".",
"master",
".",
"mav",... | returns true if this packet is appropriately addressed | [
"returns",
"true",
"if",
"this",
"packet",
"is",
"appropriately",
"addressed"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_dataflash_logger.py#L261-L271 |
249,603 | ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wxagg.py | _convert_agg_to_wx_image | def _convert_agg_to_wx_image(agg, bbox):
"""
Convert the region of the agg buffer bounded by bbox to a wx.Image. If
bbox is None, the entire buffer is converted.
Note: agg must be a backend_agg.RendererAgg instance.
"""
if bbox is None:
# agg => rgb -> image
image = wx.EmptyIma... | python | def _convert_agg_to_wx_image(agg, bbox):
if bbox is None:
# agg => rgb -> image
image = wx.EmptyImage(int(agg.width), int(agg.height))
image.SetData(agg.tostring_rgb())
return image
else:
# agg => rgba buffer -> bitmap => clipped bitmap => image
return wx.ImageFro... | [
"def",
"_convert_agg_to_wx_image",
"(",
"agg",
",",
"bbox",
")",
":",
"if",
"bbox",
"is",
"None",
":",
"# agg => rgb -> image",
"image",
"=",
"wx",
".",
"EmptyImage",
"(",
"int",
"(",
"agg",
".",
"width",
")",
",",
"int",
"(",
"agg",
".",
"height",
")"... | Convert the region of the agg buffer bounded by bbox to a wx.Image. If
bbox is None, the entire buffer is converted.
Note: agg must be a backend_agg.RendererAgg instance. | [
"Convert",
"the",
"region",
"of",
"the",
"agg",
"buffer",
"bounded",
"by",
"bbox",
"to",
"a",
"wx",
".",
"Image",
".",
"If",
"bbox",
"is",
"None",
"the",
"entire",
"buffer",
"is",
"converted",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wxagg.py#L128-L142 |
249,604 | ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wxagg.py | _convert_agg_to_wx_bitmap | def _convert_agg_to_wx_bitmap(agg, bbox):
"""
Convert the region of the agg buffer bounded by bbox to a wx.Bitmap. If
bbox is None, the entire buffer is converted.
Note: agg must be a backend_agg.RendererAgg instance.
"""
if bbox is None:
# agg => rgba buffer -> bitmap
return w... | python | def _convert_agg_to_wx_bitmap(agg, bbox):
if bbox is None:
# agg => rgba buffer -> bitmap
return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
agg.buffer_rgba())
else:
# agg => rgba buffer -> bitmap => clipped bitmap
return _WX28_clipped_agg_as_bitmap(agg, ... | [
"def",
"_convert_agg_to_wx_bitmap",
"(",
"agg",
",",
"bbox",
")",
":",
"if",
"bbox",
"is",
"None",
":",
"# agg => rgba buffer -> bitmap",
"return",
"wx",
".",
"BitmapFromBufferRGBA",
"(",
"int",
"(",
"agg",
".",
"width",
")",
",",
"int",
"(",
"agg",
".",
"... | Convert the region of the agg buffer bounded by bbox to a wx.Bitmap. If
bbox is None, the entire buffer is converted.
Note: agg must be a backend_agg.RendererAgg instance. | [
"Convert",
"the",
"region",
"of",
"the",
"agg",
"buffer",
"bounded",
"by",
"bbox",
"to",
"a",
"wx",
".",
"Bitmap",
".",
"If",
"bbox",
"is",
"None",
"the",
"entire",
"buffer",
"is",
"converted",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wxagg.py#L145-L158 |
249,605 | ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wxagg.py | _WX28_clipped_agg_as_bitmap | def _WX28_clipped_agg_as_bitmap(agg, bbox):
"""
Convert the region of a the agg buffer bounded by bbox to a wx.Bitmap.
Note: agg must be a backend_agg.RendererAgg instance.
"""
l, b, width, height = bbox.bounds
r = l + width
t = b + height
srcBmp = wx.BitmapFromBufferRGBA(int(agg.width... | python | def _WX28_clipped_agg_as_bitmap(agg, bbox):
l, b, width, height = bbox.bounds
r = l + width
t = b + height
srcBmp = wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
agg.buffer_rgba())
srcDC = wx.MemoryDC()
srcDC.SelectObject(srcBmp)
destBmp = wx.EmptyBitmap(int(width), int(... | [
"def",
"_WX28_clipped_agg_as_bitmap",
"(",
"agg",
",",
"bbox",
")",
":",
"l",
",",
"b",
",",
"width",
",",
"height",
"=",
"bbox",
".",
"bounds",
"r",
"=",
"l",
"+",
"width",
"t",
"=",
"b",
"+",
"height",
"srcBmp",
"=",
"wx",
".",
"BitmapFromBufferRGB... | Convert the region of a the agg buffer bounded by bbox to a wx.Bitmap.
Note: agg must be a backend_agg.RendererAgg instance. | [
"Convert",
"the",
"region",
"of",
"a",
"the",
"agg",
"buffer",
"bounded",
"by",
"bbox",
"to",
"a",
"wx",
".",
"Bitmap",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wxagg.py#L161-L189 |
249,606 | ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wxagg.py | FigureCanvasWxAgg.draw | def draw(self, drawDC=None):
"""
Render the figure using agg.
"""
DEBUG_MSG("draw()", 1, self)
FigureCanvasAgg.draw(self)
self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
self._isDrawn = True
self.gui_repaint(drawDC=drawDC) | python | def draw(self, drawDC=None):
DEBUG_MSG("draw()", 1, self)
FigureCanvasAgg.draw(self)
self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
self._isDrawn = True
self.gui_repaint(drawDC=drawDC) | [
"def",
"draw",
"(",
"self",
",",
"drawDC",
"=",
"None",
")",
":",
"DEBUG_MSG",
"(",
"\"draw()\"",
",",
"1",
",",
"self",
")",
"FigureCanvasAgg",
".",
"draw",
"(",
"self",
")",
"self",
".",
"bitmap",
"=",
"_convert_agg_to_wx_bitmap",
"(",
"self",
".",
"... | Render the figure using agg. | [
"Render",
"the",
"figure",
"using",
"agg",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wxagg.py#L39-L48 |
249,607 | ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wxagg.py | FigureCanvasWxAgg.blit | def blit(self, bbox=None):
"""
Transfer the region of the agg buffer defined by bbox to the display.
If bbox is None, the entire buffer is transferred.
"""
if bbox is None:
self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
self.gui_repaint... | python | def blit(self, bbox=None):
if bbox is None:
self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
self.gui_repaint()
return
l, b, w, h = bbox.bounds
r = l + w
t = b + h
x = int(l)
y = int(self.bitmap.GetHeight() - t)
... | [
"def",
"blit",
"(",
"self",
",",
"bbox",
"=",
"None",
")",
":",
"if",
"bbox",
"is",
"None",
":",
"self",
".",
"bitmap",
"=",
"_convert_agg_to_wx_bitmap",
"(",
"self",
".",
"get_renderer",
"(",
")",
",",
"None",
")",
"self",
".",
"gui_repaint",
"(",
"... | Transfer the region of the agg buffer defined by bbox to the display.
If bbox is None, the entire buffer is transferred. | [
"Transfer",
"the",
"region",
"of",
"the",
"agg",
"buffer",
"defined",
"by",
"bbox",
"to",
"the",
"display",
".",
"If",
"bbox",
"is",
"None",
"the",
"entire",
"buffer",
"is",
"transferred",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wxagg.py#L50-L79 |
249,608 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_antenna.py | AntennaModule.cmd_antenna | def cmd_antenna(self, args):
'''set gcs location'''
if len(args) != 2:
if self.gcs_location is None:
print("GCS location not set")
else:
print("GCS location %s" % str(self.gcs_location))
return
self.gcs_location = (float(args[0]... | python | def cmd_antenna(self, args):
'''set gcs location'''
if len(args) != 2:
if self.gcs_location is None:
print("GCS location not set")
else:
print("GCS location %s" % str(self.gcs_location))
return
self.gcs_location = (float(args[0]... | [
"def",
"cmd_antenna",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"2",
":",
"if",
"self",
".",
"gcs_location",
"is",
"None",
":",
"print",
"(",
"\"GCS location not set\"",
")",
"else",
":",
"print",
"(",
"\"GCS location %s\""... | set gcs location | [
"set",
"gcs",
"location"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_antenna.py#L20-L28 |
249,609 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_signing.py | SigningModule.passphrase_to_key | def passphrase_to_key(self, passphrase):
'''convert a passphrase to a 32 byte key'''
import hashlib
h = hashlib.new('sha256')
h.update(passphrase)
return h.digest() | python | def passphrase_to_key(self, passphrase):
'''convert a passphrase to a 32 byte key'''
import hashlib
h = hashlib.new('sha256')
h.update(passphrase)
return h.digest() | [
"def",
"passphrase_to_key",
"(",
"self",
",",
"passphrase",
")",
":",
"import",
"hashlib",
"h",
"=",
"hashlib",
".",
"new",
"(",
"'sha256'",
")",
"h",
".",
"update",
"(",
"passphrase",
")",
"return",
"h",
".",
"digest",
"(",
")"
] | convert a passphrase to a 32 byte key | [
"convert",
"a",
"passphrase",
"to",
"a",
"32",
"byte",
"key"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_signing.py#L39-L44 |
249,610 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_signing.py | SigningModule.cmd_signing_setup | def cmd_signing_setup(self, args):
'''setup signing key on board'''
if len(args) == 0:
print("usage: signing setup passphrase")
return
if not self.master.mavlink20():
print("You must be using MAVLink2 for signing")
return
passphrase = args[... | python | def cmd_signing_setup(self, args):
'''setup signing key on board'''
if len(args) == 0:
print("usage: signing setup passphrase")
return
if not self.master.mavlink20():
print("You must be using MAVLink2 for signing")
return
passphrase = args[... | [
"def",
"cmd_signing_setup",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"print",
"(",
"\"usage: signing setup passphrase\"",
")",
"return",
"if",
"not",
"self",
".",
"master",
".",
"mavlink20",
"(",
")",
":",
"print... | setup signing key on board | [
"setup",
"signing",
"key",
"on",
"board"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_signing.py#L46-L66 |
249,611 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_signing.py | SigningModule.allow_unsigned | def allow_unsigned(self, mav, msgId):
'''see if an unsigned packet should be allowed'''
if self.allow is None:
self.allow = {
mavutil.mavlink.MAVLINK_MSG_ID_RADIO : True,
mavutil.mavlink.MAVLINK_MSG_ID_RADIO_STATUS : True
}
if msgId in ... | python | def allow_unsigned(self, mav, msgId):
'''see if an unsigned packet should be allowed'''
if self.allow is None:
self.allow = {
mavutil.mavlink.MAVLINK_MSG_ID_RADIO : True,
mavutil.mavlink.MAVLINK_MSG_ID_RADIO_STATUS : True
}
if msgId in ... | [
"def",
"allow_unsigned",
"(",
"self",
",",
"mav",
",",
"msgId",
")",
":",
"if",
"self",
".",
"allow",
"is",
"None",
":",
"self",
".",
"allow",
"=",
"{",
"mavutil",
".",
"mavlink",
".",
"MAVLINK_MSG_ID_RADIO",
":",
"True",
",",
"mavutil",
".",
"mavlink"... | see if an unsigned packet should be allowed | [
"see",
"if",
"an",
"unsigned",
"packet",
"should",
"be",
"allowed"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_signing.py#L69-L80 |
249,612 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_signing.py | SigningModule.cmd_signing_key | def cmd_signing_key(self, args):
'''set signing key on connection'''
if len(args) == 0:
print("usage: signing setup passphrase")
return
if not self.master.mavlink20():
print("You must be using MAVLink2 for signing")
return
passphrase = args... | python | def cmd_signing_key(self, args):
'''set signing key on connection'''
if len(args) == 0:
print("usage: signing setup passphrase")
return
if not self.master.mavlink20():
print("You must be using MAVLink2 for signing")
return
passphrase = args... | [
"def",
"cmd_signing_key",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"print",
"(",
"\"usage: signing setup passphrase\"",
")",
"return",
"if",
"not",
"self",
".",
"master",
".",
"mavlink20",
"(",
")",
":",
"print",... | set signing key on connection | [
"set",
"signing",
"key",
"on",
"connection"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_signing.py#L82-L93 |
249,613 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_signing.py | SigningModule.cmd_signing_remove | def cmd_signing_remove(self, args):
'''remove signing from server'''
if not self.master.mavlink20():
print("You must be using MAVLink2 for signing")
return
self.master.mav.setup_signing_send(self.target_system, self.target_component, [0]*32, 0)
self.master.disable... | python | def cmd_signing_remove(self, args):
'''remove signing from server'''
if not self.master.mavlink20():
print("You must be using MAVLink2 for signing")
return
self.master.mav.setup_signing_send(self.target_system, self.target_component, [0]*32, 0)
self.master.disable... | [
"def",
"cmd_signing_remove",
"(",
"self",
",",
"args",
")",
":",
"if",
"not",
"self",
".",
"master",
".",
"mavlink20",
"(",
")",
":",
"print",
"(",
"\"You must be using MAVLink2 for signing\"",
")",
"return",
"self",
".",
"master",
".",
"mav",
".",
"setup_si... | remove signing from server | [
"remove",
"signing",
"from",
"server"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_signing.py#L100-L107 |
249,614 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_output.py | OutputModule.cmd_output | def cmd_output(self, args):
'''handle output commands'''
if len(args) < 1 or args[0] == "list":
self.cmd_output_list()
elif args[0] == "add":
if len(args) != 2:
print("Usage: output add OUTPUT")
return
self.cmd_output_add(args[1... | python | def cmd_output(self, args):
'''handle output commands'''
if len(args) < 1 or args[0] == "list":
self.cmd_output_list()
elif args[0] == "add":
if len(args) != 2:
print("Usage: output add OUTPUT")
return
self.cmd_output_add(args[1... | [
"def",
"cmd_output",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"1",
"or",
"args",
"[",
"0",
"]",
"==",
"\"list\"",
":",
"self",
".",
"cmd_output_list",
"(",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"add\"",
":",
... | handle output commands | [
"handle",
"output",
"commands"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_output.py#L21-L41 |
249,615 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_output.py | OutputModule.cmd_output_add | def cmd_output_add(self, args):
'''add new output'''
device = args[0]
print("Adding output %s" % device)
try:
conn = mavutil.mavlink_connection(device, input=False, source_system=self.settings.source_system)
conn.mav.srcComponent = self.settings.source_component
... | python | def cmd_output_add(self, args):
'''add new output'''
device = args[0]
print("Adding output %s" % device)
try:
conn = mavutil.mavlink_connection(device, input=False, source_system=self.settings.source_system)
conn.mav.srcComponent = self.settings.source_component
... | [
"def",
"cmd_output_add",
"(",
"self",
",",
"args",
")",
":",
"device",
"=",
"args",
"[",
"0",
"]",
"print",
"(",
"\"Adding output %s\"",
"%",
"device",
")",
"try",
":",
"conn",
"=",
"mavutil",
".",
"mavlink_connection",
"(",
"device",
",",
"input",
"=",
... | add new output | [
"add",
"new",
"output"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_output.py#L55-L69 |
249,616 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_output.py | OutputModule.cmd_output_sysid | def cmd_output_sysid(self, args):
'''add new output for a specific MAVLink sysID'''
sysid = int(args[0])
device = args[1]
print("Adding output %s for sysid %u" % (device, sysid))
try:
conn = mavutil.mavlink_connection(device, input=False, source_system=self.settings.s... | python | def cmd_output_sysid(self, args):
'''add new output for a specific MAVLink sysID'''
sysid = int(args[0])
device = args[1]
print("Adding output %s for sysid %u" % (device, sysid))
try:
conn = mavutil.mavlink_connection(device, input=False, source_system=self.settings.s... | [
"def",
"cmd_output_sysid",
"(",
"self",
",",
"args",
")",
":",
"sysid",
"=",
"int",
"(",
"args",
"[",
"0",
"]",
")",
"device",
"=",
"args",
"[",
"1",
"]",
"print",
"(",
"\"Adding output %s for sysid %u\"",
"%",
"(",
"device",
",",
"sysid",
")",
")",
... | add new output for a specific MAVLink sysID | [
"add",
"new",
"output",
"for",
"a",
"specific",
"MAVLink",
"sysID"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_output.py#L71-L88 |
249,617 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_output.py | OutputModule.cmd_output_remove | def cmd_output_remove(self, args):
'''remove an output'''
device = args[0]
for i in range(len(self.mpstate.mav_outputs)):
conn = self.mpstate.mav_outputs[i]
if str(i) == device or conn.address == device:
print("Removing output %s" % conn.address)
... | python | def cmd_output_remove(self, args):
'''remove an output'''
device = args[0]
for i in range(len(self.mpstate.mav_outputs)):
conn = self.mpstate.mav_outputs[i]
if str(i) == device or conn.address == device:
print("Removing output %s" % conn.address)
... | [
"def",
"cmd_output_remove",
"(",
"self",
",",
"args",
")",
":",
"device",
"=",
"args",
"[",
"0",
"]",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"mpstate",
".",
"mav_outputs",
")",
")",
":",
"conn",
"=",
"self",
".",
"mpstate",
".",
... | remove an output | [
"remove",
"an",
"output"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_output.py#L90-L103 |
249,618 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/mp_slipmap.py | MPSlipMap.set_center | def set_center(self, lat, lon):
'''set center of view'''
self.object_queue.put(SlipCenter((lat,lon))) | python | def set_center(self, lat, lon):
'''set center of view'''
self.object_queue.put(SlipCenter((lat,lon))) | [
"def",
"set_center",
"(",
"self",
",",
"lat",
",",
"lon",
")",
":",
"self",
".",
"object_queue",
".",
"put",
"(",
"SlipCenter",
"(",
"(",
"lat",
",",
"lon",
")",
")",
")"
] | set center of view | [
"set",
"center",
"of",
"view"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/mp_slipmap.py#L125-L127 |
249,619 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/mp_slipmap.py | MPSlipMap.get_event | def get_event(self):
'''return next event or None'''
if self.event_queue.qsize() == 0:
return None
evt = self.event_queue.get()
while isinstance(evt, win_layout.WinLayout):
win_layout.set_layout(evt, self.set_layout)
if self.event_queue.qsize() == 0:
... | python | def get_event(self):
'''return next event or None'''
if self.event_queue.qsize() == 0:
return None
evt = self.event_queue.get()
while isinstance(evt, win_layout.WinLayout):
win_layout.set_layout(evt, self.set_layout)
if self.event_queue.qsize() == 0:
... | [
"def",
"get_event",
"(",
"self",
")",
":",
"if",
"self",
".",
"event_queue",
".",
"qsize",
"(",
")",
"==",
"0",
":",
"return",
"None",
"evt",
"=",
"self",
".",
"event_queue",
".",
"get",
"(",
")",
"while",
"isinstance",
"(",
"evt",
",",
"win_layout",... | return next event or None | [
"return",
"next",
"event",
"or",
"None"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/mp_slipmap.py#L153-L163 |
249,620 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_layout.py | LayoutModule.cmd_layout | def cmd_layout(self, args):
'''handle layout command'''
from MAVProxy.modules.lib import win_layout
if len(args) < 1:
print("usage: layout <save|load>")
return
if args[0] == "load":
win_layout.load_layout(self.mpstate.settings.vehicle_name)
eli... | python | def cmd_layout(self, args):
'''handle layout command'''
from MAVProxy.modules.lib import win_layout
if len(args) < 1:
print("usage: layout <save|load>")
return
if args[0] == "load":
win_layout.load_layout(self.mpstate.settings.vehicle_name)
eli... | [
"def",
"cmd_layout",
"(",
"self",
",",
"args",
")",
":",
"from",
"MAVProxy",
".",
"modules",
".",
"lib",
"import",
"win_layout",
"if",
"len",
"(",
"args",
")",
"<",
"1",
":",
"print",
"(",
"\"usage: layout <save|load>\"",
")",
"return",
"if",
"args",
"["... | handle layout command | [
"handle",
"layout",
"command"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_layout.py#L13-L22 |
249,621 | ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_util.py | download_files | def download_files(files):
'''download an array of files'''
for (url, file) in files:
print("Downloading %s as %s" % (url, file))
data = download_url(url)
if data is None:
continue
try:
open(file, mode='wb').write(data)
except Exception as e:
... | python | def download_files(files):
'''download an array of files'''
for (url, file) in files:
print("Downloading %s as %s" % (url, file))
data = download_url(url)
if data is None:
continue
try:
open(file, mode='wb').write(data)
except Exception as e:
... | [
"def",
"download_files",
"(",
"files",
")",
":",
"for",
"(",
"url",
",",
"file",
")",
"in",
"files",
":",
"print",
"(",
"\"Downloading %s as %s\"",
"%",
"(",
"url",
",",
"file",
")",
")",
"data",
"=",
"download_url",
"(",
"url",
")",
"if",
"data",
"i... | download an array of files | [
"download",
"an",
"array",
"of",
"files"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_util.py#L265-L275 |
249,622 | ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_util.py | null_term | def null_term(str):
'''null terminate a string for py3'''
if sys.version_info.major < 3:
return str
if isinstance(str, bytes):
str = str.decode("utf-8")
idx = str.find("\0")
if idx != -1:
str = str[:idx]
return str | python | def null_term(str):
'''null terminate a string for py3'''
if sys.version_info.major < 3:
return str
if isinstance(str, bytes):
str = str.decode("utf-8")
idx = str.find("\0")
if idx != -1:
str = str[:idx]
return str | [
"def",
"null_term",
"(",
"str",
")",
":",
"if",
"sys",
".",
"version_info",
".",
"major",
"<",
"3",
":",
"return",
"str",
"if",
"isinstance",
"(",
"str",
",",
"bytes",
")",
":",
"str",
"=",
"str",
".",
"decode",
"(",
"\"utf-8\"",
")",
"idx",
"=",
... | null terminate a string for py3 | [
"null",
"terminate",
"a",
"string",
"for",
"py3"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_util.py#L316-L325 |
249,623 | ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_util.py | decode_devid | def decode_devid(devid, pname):
'''decode one device ID. Used for 'devid' command in mavproxy and MAVExplorer'''
devid = int(devid)
if devid == 0:
return
bus_type=devid & 0x07
bus=(devid>>3) & 0x1F
address=(devid>>8)&0xFF
devtype=(devid>>16)
bustypes = {
1: "I2C",
... | python | def decode_devid(devid, pname):
'''decode one device ID. Used for 'devid' command in mavproxy and MAVExplorer'''
devid = int(devid)
if devid == 0:
return
bus_type=devid & 0x07
bus=(devid>>3) & 0x1F
address=(devid>>8)&0xFF
devtype=(devid>>16)
bustypes = {
1: "I2C",
... | [
"def",
"decode_devid",
"(",
"devid",
",",
"pname",
")",
":",
"devid",
"=",
"int",
"(",
"devid",
")",
"if",
"devid",
"==",
"0",
":",
"return",
"bus_type",
"=",
"devid",
"&",
"0x07",
"bus",
"=",
"(",
"devid",
">>",
"3",
")",
"&",
"0x1F",
"address",
... | decode one device ID. Used for 'devid' command in mavproxy and MAVExplorer | [
"decode",
"one",
"device",
"ID",
".",
"Used",
"for",
"devid",
"command",
"in",
"mavproxy",
"and",
"MAVExplorer"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_util.py#L328-L400 |
249,624 | django-auth-ldap/django-auth-ldap | django_auth_ldap/backend.py | _LDAPUser._authenticate_user_dn | def _authenticate_user_dn(self, password):
"""
Binds to the LDAP server with the user's DN and password. Raises
AuthenticationFailed on failure.
"""
if self.dn is None:
raise self.AuthenticationFailed("failed to map the username to a DN.")
try:
st... | python | def _authenticate_user_dn(self, password):
if self.dn is None:
raise self.AuthenticationFailed("failed to map the username to a DN.")
try:
sticky = self.settings.BIND_AS_AUTHENTICATING_USER
self._bind_as(self.dn, password, sticky=sticky)
except ldap.INVALID_... | [
"def",
"_authenticate_user_dn",
"(",
"self",
",",
"password",
")",
":",
"if",
"self",
".",
"dn",
"is",
"None",
":",
"raise",
"self",
".",
"AuthenticationFailed",
"(",
"\"failed to map the username to a DN.\"",
")",
"try",
":",
"sticky",
"=",
"self",
".",
"sett... | Binds to the LDAP server with the user's DN and password. Raises
AuthenticationFailed on failure. | [
"Binds",
"to",
"the",
"LDAP",
"server",
"with",
"the",
"user",
"s",
"DN",
"and",
"password",
".",
"Raises",
"AuthenticationFailed",
"on",
"failure",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/backend.py#L471-L484 |
249,625 | django-auth-ldap/django-auth-ldap | django_auth_ldap/backend.py | _LDAPUser._load_user_dn | def _load_user_dn(self):
"""
Populates self._user_dn with the distinguished name of our user.
This will either construct the DN from a template in
AUTH_LDAP_USER_DN_TEMPLATE or connect to the server and search for it.
If we have to search, we'll cache the DN.
"""
... | python | def _load_user_dn(self):
if self._using_simple_bind_mode():
self._user_dn = self._construct_simple_user_dn()
else:
if self.settings.CACHE_TIMEOUT > 0:
cache_key = valid_cache_key(
"django_auth_ldap.user_dn.{}".format(self._username)
... | [
"def",
"_load_user_dn",
"(",
"self",
")",
":",
"if",
"self",
".",
"_using_simple_bind_mode",
"(",
")",
":",
"self",
".",
"_user_dn",
"=",
"self",
".",
"_construct_simple_user_dn",
"(",
")",
"else",
":",
"if",
"self",
".",
"settings",
".",
"CACHE_TIMEOUT",
... | Populates self._user_dn with the distinguished name of our user.
This will either construct the DN from a template in
AUTH_LDAP_USER_DN_TEMPLATE or connect to the server and search for it.
If we have to search, we'll cache the DN. | [
"Populates",
"self",
".",
"_user_dn",
"with",
"the",
"distinguished",
"name",
"of",
"our",
"user",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/backend.py#L496-L516 |
249,626 | django-auth-ldap/django-auth-ldap | django_auth_ldap/backend.py | _LDAPUser._search_for_user_dn | def _search_for_user_dn(self):
"""
Searches the directory for a user matching AUTH_LDAP_USER_SEARCH.
Populates self._user_dn and self._user_attrs.
"""
search = self.settings.USER_SEARCH
if search is None:
raise ImproperlyConfigured(
"AUTH_LDAP_... | python | def _search_for_user_dn(self):
search = self.settings.USER_SEARCH
if search is None:
raise ImproperlyConfigured(
"AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance."
)
results = search.execute(self.connection, {"user": self._username})
if resul... | [
"def",
"_search_for_user_dn",
"(",
"self",
")",
":",
"search",
"=",
"self",
".",
"settings",
".",
"USER_SEARCH",
"if",
"search",
"is",
"None",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance.\"",
")",
"results",
"=",
... | Searches the directory for a user matching AUTH_LDAP_USER_SEARCH.
Populates self._user_dn and self._user_attrs. | [
"Searches",
"the",
"directory",
"for",
"a",
"user",
"matching",
"AUTH_LDAP_USER_SEARCH",
".",
"Populates",
"self",
".",
"_user_dn",
"and",
"self",
".",
"_user_attrs",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/backend.py#L526-L543 |
249,627 | django-auth-ldap/django-auth-ldap | django_auth_ldap/backend.py | _LDAPUser._normalize_group_dns | def _normalize_group_dns(self, group_dns):
"""
Converts one or more group DNs to an LDAPGroupQuery.
group_dns may be a string, a non-empty list or tuple of strings, or an
LDAPGroupQuery. The result will be an LDAPGroupQuery. A list or tuple
will be joined with the | operator.
... | python | def _normalize_group_dns(self, group_dns):
if isinstance(group_dns, LDAPGroupQuery):
query = group_dns
elif isinstance(group_dns, str):
query = LDAPGroupQuery(group_dns)
elif isinstance(group_dns, (list, tuple)) and len(group_dns) > 0:
query = reduce(operator.... | [
"def",
"_normalize_group_dns",
"(",
"self",
",",
"group_dns",
")",
":",
"if",
"isinstance",
"(",
"group_dns",
",",
"LDAPGroupQuery",
")",
":",
"query",
"=",
"group_dns",
"elif",
"isinstance",
"(",
"group_dns",
",",
"str",
")",
":",
"query",
"=",
"LDAPGroupQu... | Converts one or more group DNs to an LDAPGroupQuery.
group_dns may be a string, a non-empty list or tuple of strings, or an
LDAPGroupQuery. The result will be an LDAPGroupQuery. A list or tuple
will be joined with the | operator. | [
"Converts",
"one",
"or",
"more",
"group",
"DNs",
"to",
"an",
"LDAPGroupQuery",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/backend.py#L668-L686 |
249,628 | django-auth-ldap/django-auth-ldap | django_auth_ldap/backend.py | _LDAPUser._normalize_mirror_settings | def _normalize_mirror_settings(self):
"""
Validates the group mirroring settings and converts them as necessary.
"""
def malformed_mirror_groups_except():
return ImproperlyConfigured(
"{} must be a collection of group names".format(
self.s... | python | def _normalize_mirror_settings(self):
def malformed_mirror_groups_except():
return ImproperlyConfigured(
"{} must be a collection of group names".format(
self.settings._name("MIRROR_GROUPS_EXCEPT")
)
)
def malformed_mirror_grou... | [
"def",
"_normalize_mirror_settings",
"(",
"self",
")",
":",
"def",
"malformed_mirror_groups_except",
"(",
")",
":",
"return",
"ImproperlyConfigured",
"(",
"\"{} must be a collection of group names\"",
".",
"format",
"(",
"self",
".",
"settings",
".",
"_name",
"(",
"\"... | Validates the group mirroring settings and converts them as necessary. | [
"Validates",
"the",
"group",
"mirroring",
"settings",
"and",
"converts",
"them",
"as",
"necessary",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/backend.py#L688-L742 |
249,629 | django-auth-ldap/django-auth-ldap | django_auth_ldap/backend.py | _LDAPUser._get_groups | def _get_groups(self):
"""
Returns an _LDAPUserGroups object, which can determine group
membership.
"""
if self._groups is None:
self._groups = _LDAPUserGroups(self)
return self._groups | python | def _get_groups(self):
if self._groups is None:
self._groups = _LDAPUserGroups(self)
return self._groups | [
"def",
"_get_groups",
"(",
"self",
")",
":",
"if",
"self",
".",
"_groups",
"is",
"None",
":",
"self",
".",
"_groups",
"=",
"_LDAPUserGroups",
"(",
"self",
")",
"return",
"self",
".",
"_groups"
] | Returns an _LDAPUserGroups object, which can determine group
membership. | [
"Returns",
"an",
"_LDAPUserGroups",
"object",
"which",
"can",
"determine",
"group",
"membership",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/backend.py#L801-L809 |
249,630 | django-auth-ldap/django-auth-ldap | django_auth_ldap/backend.py | _LDAPUser._bind | def _bind(self):
"""
Binds to the LDAP server with AUTH_LDAP_BIND_DN and
AUTH_LDAP_BIND_PASSWORD.
"""
self._bind_as(self.settings.BIND_DN, self.settings.BIND_PASSWORD, sticky=True) | python | def _bind(self):
self._bind_as(self.settings.BIND_DN, self.settings.BIND_PASSWORD, sticky=True) | [
"def",
"_bind",
"(",
"self",
")",
":",
"self",
".",
"_bind_as",
"(",
"self",
".",
"settings",
".",
"BIND_DN",
",",
"self",
".",
"settings",
".",
"BIND_PASSWORD",
",",
"sticky",
"=",
"True",
")"
] | Binds to the LDAP server with AUTH_LDAP_BIND_DN and
AUTH_LDAP_BIND_PASSWORD. | [
"Binds",
"to",
"the",
"LDAP",
"server",
"with",
"AUTH_LDAP_BIND_DN",
"and",
"AUTH_LDAP_BIND_PASSWORD",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/backend.py#L815-L820 |
249,631 | django-auth-ldap/django-auth-ldap | django_auth_ldap/backend.py | _LDAPUser._bind_as | def _bind_as(self, bind_dn, bind_password, sticky=False):
"""
Binds to the LDAP server with the given credentials. This does not trap
exceptions.
If sticky is True, then we will consider the connection to be bound for
the life of this object. If False, then the caller only wishe... | python | def _bind_as(self, bind_dn, bind_password, sticky=False):
self._get_connection().simple_bind_s(bind_dn, bind_password)
self._connection_bound = sticky | [
"def",
"_bind_as",
"(",
"self",
",",
"bind_dn",
",",
"bind_password",
",",
"sticky",
"=",
"False",
")",
":",
"self",
".",
"_get_connection",
"(",
")",
".",
"simple_bind_s",
"(",
"bind_dn",
",",
"bind_password",
")",
"self",
".",
"_connection_bound",
"=",
"... | Binds to the LDAP server with the given credentials. This does not trap
exceptions.
If sticky is True, then we will consider the connection to be bound for
the life of this object. If False, then the caller only wishes to test
the credentials, after which the connection will be consider... | [
"Binds",
"to",
"the",
"LDAP",
"server",
"with",
"the",
"given",
"credentials",
".",
"This",
"does",
"not",
"trap",
"exceptions",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/backend.py#L822-L833 |
249,632 | django-auth-ldap/django-auth-ldap | django_auth_ldap/backend.py | _LDAPUserGroups._init_group_settings | def _init_group_settings(self):
"""
Loads the settings we need to deal with groups.
Raises ImproperlyConfigured if anything's not right.
"""
self._group_type = self.settings.GROUP_TYPE
if self._group_type is None:
raise ImproperlyConfigured(
... | python | def _init_group_settings(self):
self._group_type = self.settings.GROUP_TYPE
if self._group_type is None:
raise ImproperlyConfigured(
"AUTH_LDAP_GROUP_TYPE must be an LDAPGroupType instance."
)
self._group_search = self.settings.GROUP_SEARCH
if sel... | [
"def",
"_init_group_settings",
"(",
"self",
")",
":",
"self",
".",
"_group_type",
"=",
"self",
".",
"settings",
".",
"GROUP_TYPE",
"if",
"self",
".",
"_group_type",
"is",
"None",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"AUTH_LDAP_GROUP_TYPE must be an LDAPGroup... | Loads the settings we need to deal with groups.
Raises ImproperlyConfigured if anything's not right. | [
"Loads",
"the",
"settings",
"we",
"need",
"to",
"deal",
"with",
"groups",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/backend.py#L882-L899 |
249,633 | django-auth-ldap/django-auth-ldap | django_auth_ldap/backend.py | _LDAPUserGroups.get_group_names | def get_group_names(self):
"""
Returns the set of Django group names that this user belongs to by
virtue of LDAP group memberships.
"""
if self._group_names is None:
self._load_cached_attr("_group_names")
if self._group_names is None:
group_infos ... | python | def get_group_names(self):
if self._group_names is None:
self._load_cached_attr("_group_names")
if self._group_names is None:
group_infos = self._get_group_infos()
self._group_names = {
self._group_type.group_name_from_info(group_info)
... | [
"def",
"get_group_names",
"(",
"self",
")",
":",
"if",
"self",
".",
"_group_names",
"is",
"None",
":",
"self",
".",
"_load_cached_attr",
"(",
"\"_group_names\"",
")",
"if",
"self",
".",
"_group_names",
"is",
"None",
":",
"group_infos",
"=",
"self",
".",
"_... | Returns the set of Django group names that this user belongs to by
virtue of LDAP group memberships. | [
"Returns",
"the",
"set",
"of",
"Django",
"group",
"names",
"that",
"this",
"user",
"belongs",
"to",
"by",
"virtue",
"of",
"LDAP",
"group",
"memberships",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/backend.py#L901-L917 |
249,634 | django-auth-ldap/django-auth-ldap | django_auth_ldap/backend.py | _LDAPUserGroups.is_member_of | def is_member_of(self, group_dn):
"""
Returns true if our user is a member of the given group.
"""
is_member = None
# Normalize the DN
group_dn = group_dn.lower()
# If we have self._group_dns, we'll use it. Otherwise, we'll try to
# avoid the cost of loa... | python | def is_member_of(self, group_dn):
is_member = None
# Normalize the DN
group_dn = group_dn.lower()
# If we have self._group_dns, we'll use it. Otherwise, we'll try to
# avoid the cost of loading it.
if self._group_dns is None:
is_member = self._group_type.is_... | [
"def",
"is_member_of",
"(",
"self",
",",
"group_dn",
")",
":",
"is_member",
"=",
"None",
"# Normalize the DN",
"group_dn",
"=",
"group_dn",
".",
"lower",
"(",
")",
"# If we have self._group_dns, we'll use it. Otherwise, we'll try to",
"# avoid the cost of loading it.",
"if"... | Returns true if our user is a member of the given group. | [
"Returns",
"true",
"if",
"our",
"user",
"is",
"a",
"member",
"of",
"the",
"given",
"group",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/backend.py#L919-L942 |
249,635 | django-auth-ldap/django-auth-ldap | django_auth_ldap/config.py | _LDAPConfig.get_ldap | def get_ldap(cls, global_options=None):
"""
Returns the configured ldap module.
"""
# Apply global LDAP options once
if not cls._ldap_configured and global_options is not None:
for opt, value in global_options.items():
ldap.set_option(opt, value)
... | python | def get_ldap(cls, global_options=None):
# Apply global LDAP options once
if not cls._ldap_configured and global_options is not None:
for opt, value in global_options.items():
ldap.set_option(opt, value)
cls._ldap_configured = True
return ldap | [
"def",
"get_ldap",
"(",
"cls",
",",
"global_options",
"=",
"None",
")",
":",
"# Apply global LDAP options once",
"if",
"not",
"cls",
".",
"_ldap_configured",
"and",
"global_options",
"is",
"not",
"None",
":",
"for",
"opt",
",",
"value",
"in",
"global_options",
... | Returns the configured ldap module. | [
"Returns",
"the",
"configured",
"ldap",
"module",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/config.py#L54-L65 |
249,636 | django-auth-ldap/django-auth-ldap | django_auth_ldap/config.py | LDAPSearch.search_with_additional_terms | def search_with_additional_terms(self, term_dict, escape=True):
"""
Returns a new search object with additional search terms and-ed to the
filter string. term_dict maps attribute names to assertion values. If
you don't want the values escaped, pass escape=False.
"""
term_... | python | def search_with_additional_terms(self, term_dict, escape=True):
term_strings = [self.filterstr]
for name, value in term_dict.items():
if escape:
value = self.ldap.filter.escape_filter_chars(value)
term_strings.append("({}={})".format(name, value))
filter... | [
"def",
"search_with_additional_terms",
"(",
"self",
",",
"term_dict",
",",
"escape",
"=",
"True",
")",
":",
"term_strings",
"=",
"[",
"self",
".",
"filterstr",
"]",
"for",
"name",
",",
"value",
"in",
"term_dict",
".",
"items",
"(",
")",
":",
"if",
"escap... | Returns a new search object with additional search terms and-ed to the
filter string. term_dict maps attribute names to assertion values. If
you don't want the values escaped, pass escape=False. | [
"Returns",
"a",
"new",
"search",
"object",
"with",
"additional",
"search",
"terms",
"and",
"-",
"ed",
"to",
"the",
"filter",
"string",
".",
"term_dict",
"maps",
"attribute",
"names",
"to",
"assertion",
"values",
".",
"If",
"you",
"don",
"t",
"want",
"the",... | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/config.py#L105-L122 |
249,637 | django-auth-ldap/django-auth-ldap | django_auth_ldap/config.py | PosixGroupType.user_groups | def user_groups(self, ldap_user, group_search):
"""
Searches for any group that is either the user's primary or contains the
user as a member.
"""
groups = []
try:
user_uid = ldap_user.attrs["uid"][0]
if "gidNumber" in ldap_user.attrs:
... | python | def user_groups(self, ldap_user, group_search):
groups = []
try:
user_uid = ldap_user.attrs["uid"][0]
if "gidNumber" in ldap_user.attrs:
user_gid = ldap_user.attrs["gidNumber"][0]
filterstr = "(|(gidNumber={})(memberUid={}))".format(
... | [
"def",
"user_groups",
"(",
"self",
",",
"ldap_user",
",",
"group_search",
")",
":",
"groups",
"=",
"[",
"]",
"try",
":",
"user_uid",
"=",
"ldap_user",
".",
"attrs",
"[",
"\"uid\"",
"]",
"[",
"0",
"]",
"if",
"\"gidNumber\"",
"in",
"ldap_user",
".",
"att... | Searches for any group that is either the user's primary or contains the
user as a member. | [
"Searches",
"for",
"any",
"group",
"that",
"is",
"either",
"the",
"user",
"s",
"primary",
"or",
"contains",
"the",
"user",
"as",
"a",
"member",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/config.py#L402-L428 |
249,638 | django-auth-ldap/django-auth-ldap | django_auth_ldap/config.py | PosixGroupType.is_member | def is_member(self, ldap_user, group_dn):
"""
Returns True if the group is the user's primary group or if the user is
listed in the group's memberUid attribute.
"""
try:
user_uid = ldap_user.attrs["uid"][0]
try:
is_member = ldap_user.conne... | python | def is_member(self, ldap_user, group_dn):
try:
user_uid = ldap_user.attrs["uid"][0]
try:
is_member = ldap_user.connection.compare_s(
group_dn, "memberUid", user_uid.encode()
)
except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRI... | [
"def",
"is_member",
"(",
"self",
",",
"ldap_user",
",",
"group_dn",
")",
":",
"try",
":",
"user_uid",
"=",
"ldap_user",
".",
"attrs",
"[",
"\"uid\"",
"]",
"[",
"0",
"]",
"try",
":",
"is_member",
"=",
"ldap_user",
".",
"connection",
".",
"compare_s",
"(... | Returns True if the group is the user's primary group or if the user is
listed in the group's memberUid attribute. | [
"Returns",
"True",
"if",
"the",
"group",
"is",
"the",
"user",
"s",
"primary",
"group",
"or",
"if",
"the",
"user",
"is",
"listed",
"in",
"the",
"group",
"s",
"memberUid",
"attribute",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/config.py#L430-L456 |
249,639 | django-auth-ldap/django-auth-ldap | django_auth_ldap/config.py | NestedMemberDNGroupType.user_groups | def user_groups(self, ldap_user, group_search):
"""
This searches for all of a user's groups from the bottom up. In other
words, it returns the groups that the user belongs to, the groups that
those groups belong to, etc. Circular references will be detected and
pruned.
"... | python | def user_groups(self, ldap_user, group_search):
group_info_map = {} # Maps group_dn to group_info of groups we've found
member_dn_set = {ldap_user.dn} # Member DNs to search with next
handled_dn_set = set() # Member DNs that we've already searched with
while len(member_dn_set) > 0:
... | [
"def",
"user_groups",
"(",
"self",
",",
"ldap_user",
",",
"group_search",
")",
":",
"group_info_map",
"=",
"{",
"}",
"# Maps group_dn to group_info of groups we've found",
"member_dn_set",
"=",
"{",
"ldap_user",
".",
"dn",
"}",
"# Member DNs to search with next",
"handl... | This searches for all of a user's groups from the bottom up. In other
words, it returns the groups that the user belongs to, the groups that
those groups belong to, etc. Circular references will be detected and
pruned. | [
"This",
"searches",
"for",
"all",
"of",
"a",
"user",
"s",
"groups",
"from",
"the",
"bottom",
"up",
".",
"In",
"other",
"words",
"it",
"returns",
"the",
"groups",
"that",
"the",
"user",
"belongs",
"to",
"the",
"groups",
"that",
"those",
"groups",
"belong"... | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/config.py#L509-L532 |
249,640 | django-auth-ldap/django-auth-ldap | django_auth_ldap/config.py | LDAPGroupQuery.aggregator | def aggregator(self):
"""
Returns a function for aggregating a sequence of sub-results.
"""
if self.connector == self.AND:
aggregator = all
elif self.connector == self.OR:
aggregator = any
else:
raise ValueError(self.connector)
... | python | def aggregator(self):
if self.connector == self.AND:
aggregator = all
elif self.connector == self.OR:
aggregator = any
else:
raise ValueError(self.connector)
return aggregator | [
"def",
"aggregator",
"(",
"self",
")",
":",
"if",
"self",
".",
"connector",
"==",
"self",
".",
"AND",
":",
"aggregator",
"=",
"all",
"elif",
"self",
".",
"connector",
"==",
"self",
".",
"OR",
":",
"aggregator",
"=",
"any",
"else",
":",
"raise",
"Valu... | Returns a function for aggregating a sequence of sub-results. | [
"Returns",
"a",
"function",
"for",
"aggregating",
"a",
"sequence",
"of",
"sub",
"-",
"results",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/config.py#L682-L693 |
249,641 | django-auth-ldap/django-auth-ldap | django_auth_ldap/config.py | LDAPGroupQuery._resolve_children | def _resolve_children(self, ldap_user, groups):
"""
Generates the query result for each child.
"""
for child in self.children:
if isinstance(child, LDAPGroupQuery):
yield child.resolve(ldap_user, groups)
else:
yield groups.is_member... | python | def _resolve_children(self, ldap_user, groups):
for child in self.children:
if isinstance(child, LDAPGroupQuery):
yield child.resolve(ldap_user, groups)
else:
yield groups.is_member_of(child) | [
"def",
"_resolve_children",
"(",
"self",
",",
"ldap_user",
",",
"groups",
")",
":",
"for",
"child",
"in",
"self",
".",
"children",
":",
"if",
"isinstance",
"(",
"child",
",",
"LDAPGroupQuery",
")",
":",
"yield",
"child",
".",
"resolve",
"(",
"ldap_user",
... | Generates the query result for each child. | [
"Generates",
"the",
"query",
"result",
"for",
"each",
"child",
"."
] | 9ce3c2825527f8faa1793958b041816e63d839af | https://github.com/django-auth-ldap/django-auth-ldap/blob/9ce3c2825527f8faa1793958b041816e63d839af/django_auth_ldap/config.py#L695-L703 |
249,642 | regebro/hovercraft | hovercraft/position.py | gather_positions | def gather_positions(tree):
"""Makes a list of positions and position commands from the tree"""
pos = {'data-x': 'r0',
'data-y': 'r0',
'data-z': 'r0',
'data-rotate-x': 'r0',
'data-rotate-y': 'r0',
'data-rotate-z': 'r0',
'data-scale': 'r0',
... | python | def gather_positions(tree):
pos = {'data-x': 'r0',
'data-y': 'r0',
'data-z': 'r0',
'data-rotate-x': 'r0',
'data-rotate-y': 'r0',
'data-rotate-z': 'r0',
'data-scale': 'r0',
'is_path': False
}
steps = 0
default_movement =... | [
"def",
"gather_positions",
"(",
"tree",
")",
":",
"pos",
"=",
"{",
"'data-x'",
":",
"'r0'",
",",
"'data-y'",
":",
"'r0'",
",",
"'data-z'",
":",
"'r0'",
",",
"'data-rotate-x'",
":",
"'r0'",
",",
"'data-rotate-y'",
":",
"'r0'",
",",
"'data-rotate-z'",
":",
... | Makes a list of positions and position commands from the tree | [
"Makes",
"a",
"list",
"of",
"positions",
"and",
"position",
"commands",
"from",
"the",
"tree"
] | d9f63bfdfe1519c4d7a81697ee066e49dc26a30b | https://github.com/regebro/hovercraft/blob/d9f63bfdfe1519c4d7a81697ee066e49dc26a30b/hovercraft/position.py#L10-L67 |
249,643 | regebro/hovercraft | hovercraft/position.py | calculate_positions | def calculate_positions(positions):
"""Calculates position information"""
current_position = {'data-x': 0,
'data-y': 0,
'data-z': 0,
'data-rotate-x': 0,
'data-rotate-y': 0,
'data-rotate-z': 0,... | python | def calculate_positions(positions):
current_position = {'data-x': 0,
'data-y': 0,
'data-z': 0,
'data-rotate-x': 0,
'data-rotate-y': 0,
'data-rotate-z': 0,
'data-scale': 1,
... | [
"def",
"calculate_positions",
"(",
"positions",
")",
":",
"current_position",
"=",
"{",
"'data-x'",
":",
"0",
",",
"'data-y'",
":",
"0",
",",
"'data-z'",
":",
"0",
",",
"'data-rotate-x'",
":",
"0",
",",
"'data-rotate-y'",
":",
"0",
",",
"'data-rotate-z'",
... | Calculates position information | [
"Calculates",
"position",
"information"
] | d9f63bfdfe1519c4d7a81697ee066e49dc26a30b | https://github.com/regebro/hovercraft/blob/d9f63bfdfe1519c4d7a81697ee066e49dc26a30b/hovercraft/position.py#L131-L216 |
249,644 | regebro/hovercraft | hovercraft/position.py | update_positions | def update_positions(tree, positions):
"""Updates the tree with new positions"""
for step, pos in zip(tree.findall('step'), positions):
for key in sorted(pos):
value = pos.get(key)
if key.endswith("-rel"):
abs_key = key[:key.index("-rel")]
if valu... | python | def update_positions(tree, positions):
for step, pos in zip(tree.findall('step'), positions):
for key in sorted(pos):
value = pos.get(key)
if key.endswith("-rel"):
abs_key = key[:key.index("-rel")]
if value is not None:
els = tree.f... | [
"def",
"update_positions",
"(",
"tree",
",",
"positions",
")",
":",
"for",
"step",
",",
"pos",
"in",
"zip",
"(",
"tree",
".",
"findall",
"(",
"'step'",
")",
",",
"positions",
")",
":",
"for",
"key",
"in",
"sorted",
"(",
"pos",
")",
":",
"value",
"=... | Updates the tree with new positions | [
"Updates",
"the",
"tree",
"with",
"new",
"positions"
] | d9f63bfdfe1519c4d7a81697ee066e49dc26a30b | https://github.com/regebro/hovercraft/blob/d9f63bfdfe1519c4d7a81697ee066e49dc26a30b/hovercraft/position.py#L219-L236 |
249,645 | regebro/hovercraft | hovercraft/position.py | position_slides | def position_slides(tree):
"""Position the slides in the tree"""
positions = gather_positions(tree)
positions = calculate_positions(positions)
update_positions(tree, positions) | python | def position_slides(tree):
positions = gather_positions(tree)
positions = calculate_positions(positions)
update_positions(tree, positions) | [
"def",
"position_slides",
"(",
"tree",
")",
":",
"positions",
"=",
"gather_positions",
"(",
"tree",
")",
"positions",
"=",
"calculate_positions",
"(",
"positions",
")",
"update_positions",
"(",
"tree",
",",
"positions",
")"
] | Position the slides in the tree | [
"Position",
"the",
"slides",
"in",
"the",
"tree"
] | d9f63bfdfe1519c4d7a81697ee066e49dc26a30b | https://github.com/regebro/hovercraft/blob/d9f63bfdfe1519c4d7a81697ee066e49dc26a30b/hovercraft/position.py#L239-L244 |
249,646 | regebro/hovercraft | hovercraft/parse.py | copy_node | def copy_node(node):
"""Makes a copy of a node with the same attributes and text, but no children."""
element = node.makeelement(node.tag)
element.text = node.text
element.tail = node.tail
for key, value in node.items():
element.set(key, value)
return element | python | def copy_node(node):
element = node.makeelement(node.tag)
element.text = node.text
element.tail = node.tail
for key, value in node.items():
element.set(key, value)
return element | [
"def",
"copy_node",
"(",
"node",
")",
":",
"element",
"=",
"node",
".",
"makeelement",
"(",
"node",
".",
"tag",
")",
"element",
".",
"text",
"=",
"node",
".",
"text",
"element",
".",
"tail",
"=",
"node",
".",
"tail",
"for",
"key",
",",
"value",
"in... | Makes a copy of a node with the same attributes and text, but no children. | [
"Makes",
"a",
"copy",
"of",
"a",
"node",
"with",
"the",
"same",
"attributes",
"and",
"text",
"but",
"no",
"children",
"."
] | d9f63bfdfe1519c4d7a81697ee066e49dc26a30b | https://github.com/regebro/hovercraft/blob/d9f63bfdfe1519c4d7a81697ee066e49dc26a30b/hovercraft/parse.py#L84-L92 |
249,647 | regebro/hovercraft | hovercraft/template.py | Template.copy_resource | def copy_resource(self, resource, targetdir):
"""Copies a resource file and returns the source path for monitoring"""
final_path = resource.final_path()
if final_path[0] == '/' or (':' in final_path) or ('?' in final_path):
# Absolute path or URI: Do nothing
return
... | python | def copy_resource(self, resource, targetdir):
final_path = resource.final_path()
if final_path[0] == '/' or (':' in final_path) or ('?' in final_path):
# Absolute path or URI: Do nothing
return
source_path = self.get_source_path(resource)
if resource.resource_ty... | [
"def",
"copy_resource",
"(",
"self",
",",
"resource",
",",
"targetdir",
")",
":",
"final_path",
"=",
"resource",
".",
"final_path",
"(",
")",
"if",
"final_path",
"[",
"0",
"]",
"==",
"'/'",
"or",
"(",
"':'",
"in",
"final_path",
")",
"or",
"(",
"'?'",
... | Copies a resource file and returns the source path for monitoring | [
"Copies",
"a",
"resource",
"file",
"and",
"returns",
"the",
"source",
"path",
"for",
"monitoring"
] | d9f63bfdfe1519c4d7a81697ee066e49dc26a30b | https://github.com/regebro/hovercraft/blob/d9f63bfdfe1519c4d7a81697ee066e49dc26a30b/hovercraft/template.py#L143-L162 |
249,648 | regebro/hovercraft | hovercraft/generate.py | generate | def generate(args):
"""Generates the presentation and returns a list of files used"""
source_files = {args.presentation}
# Parse the template info
template_info = Template(args.template)
if args.css:
presentation_dir = os.path.split(args.presentation)[0]
target_path = os.path.relpa... | python | def generate(args):
source_files = {args.presentation}
# Parse the template info
template_info = Template(args.template)
if args.css:
presentation_dir = os.path.split(args.presentation)[0]
target_path = os.path.relpath(args.css, presentation_dir)
template_info.add_resource(args.... | [
"def",
"generate",
"(",
"args",
")",
":",
"source_files",
"=",
"{",
"args",
".",
"presentation",
"}",
"# Parse the template info",
"template_info",
"=",
"Template",
"(",
"args",
".",
"template",
")",
"if",
"args",
".",
"css",
":",
"presentation_dir",
"=",
"o... | Generates the presentation and returns a list of files used | [
"Generates",
"the",
"presentation",
"and",
"returns",
"a",
"list",
"of",
"files",
"used"
] | d9f63bfdfe1519c4d7a81697ee066e49dc26a30b | https://github.com/regebro/hovercraft/blob/d9f63bfdfe1519c4d7a81697ee066e49dc26a30b/hovercraft/generate.py#L144-L207 |
249,649 | sourceperl/pyModbusTCP | pyModbusTCP/client.py | ModbusClient.port | def port(self, port=None):
"""Get or set TCP port
:param port: TCP port number or None for get value
:type port: int or None
:returns: TCP port or None if set fail
:rtype: int or None
"""
if (port is None) or (port == self.__port):
return self.__port
... | python | def port(self, port=None):
if (port is None) or (port == self.__port):
return self.__port
# when port change ensure old socket is close
self.close()
# valid port ?
if 0 < int(port) < 65536:
self.__port = int(port)
return self.__port
els... | [
"def",
"port",
"(",
"self",
",",
"port",
"=",
"None",
")",
":",
"if",
"(",
"port",
"is",
"None",
")",
"or",
"(",
"port",
"==",
"self",
".",
"__port",
")",
":",
"return",
"self",
".",
"__port",
"# when port change ensure old socket is close",
"self",
".",... | Get or set TCP port
:param port: TCP port number or None for get value
:type port: int or None
:returns: TCP port or None if set fail
:rtype: int or None | [
"Get",
"or",
"set",
"TCP",
"port"
] | 993f6e2f5ab52eba164be049e42cea560c3751a5 | https://github.com/sourceperl/pyModbusTCP/blob/993f6e2f5ab52eba164be049e42cea560c3751a5/pyModbusTCP/client.py#L145-L162 |
249,650 | sourceperl/pyModbusTCP | pyModbusTCP/client.py | ModbusClient.unit_id | def unit_id(self, unit_id=None):
"""Get or set unit ID field
:param unit_id: unit ID (0 to 255) or None for get value
:type unit_id: int or None
:returns: unit ID or None if set fail
:rtype: int or None
"""
if unit_id is None:
return self.__unit_id
... | python | def unit_id(self, unit_id=None):
if unit_id is None:
return self.__unit_id
if 0 <= int(unit_id) < 256:
self.__unit_id = int(unit_id)
return self.__unit_id
else:
return None | [
"def",
"unit_id",
"(",
"self",
",",
"unit_id",
"=",
"None",
")",
":",
"if",
"unit_id",
"is",
"None",
":",
"return",
"self",
".",
"__unit_id",
"if",
"0",
"<=",
"int",
"(",
"unit_id",
")",
"<",
"256",
":",
"self",
".",
"__unit_id",
"=",
"int",
"(",
... | Get or set unit ID field
:param unit_id: unit ID (0 to 255) or None for get value
:type unit_id: int or None
:returns: unit ID or None if set fail
:rtype: int or None | [
"Get",
"or",
"set",
"unit",
"ID",
"field"
] | 993f6e2f5ab52eba164be049e42cea560c3751a5 | https://github.com/sourceperl/pyModbusTCP/blob/993f6e2f5ab52eba164be049e42cea560c3751a5/pyModbusTCP/client.py#L164-L178 |
249,651 | sourceperl/pyModbusTCP | pyModbusTCP/client.py | ModbusClient.timeout | def timeout(self, timeout=None):
"""Get or set timeout field
:param timeout: socket timeout in seconds or None for get value
:type timeout: float or None
:returns: timeout or None if set fail
:rtype: float or None
"""
if timeout is None:
return self._... | python | def timeout(self, timeout=None):
if timeout is None:
return self.__timeout
if 0 < float(timeout) < 3600:
self.__timeout = float(timeout)
return self.__timeout
else:
return None | [
"def",
"timeout",
"(",
"self",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"return",
"self",
".",
"__timeout",
"if",
"0",
"<",
"float",
"(",
"timeout",
")",
"<",
"3600",
":",
"self",
".",
"__timeout",
"=",
"float",
"(... | Get or set timeout field
:param timeout: socket timeout in seconds or None for get value
:type timeout: float or None
:returns: timeout or None if set fail
:rtype: float or None | [
"Get",
"or",
"set",
"timeout",
"field"
] | 993f6e2f5ab52eba164be049e42cea560c3751a5 | https://github.com/sourceperl/pyModbusTCP/blob/993f6e2f5ab52eba164be049e42cea560c3751a5/pyModbusTCP/client.py#L180-L194 |
249,652 | sourceperl/pyModbusTCP | pyModbusTCP/client.py | ModbusClient.debug | def debug(self, state=None):
"""Get or set debug mode
:param state: debug state or None for get value
:type state: bool or None
:returns: debug state or None if set fail
:rtype: bool or None
"""
if state is None:
return self.__debug
self.__deb... | python | def debug(self, state=None):
if state is None:
return self.__debug
self.__debug = bool(state)
return self.__debug | [
"def",
"debug",
"(",
"self",
",",
"state",
"=",
"None",
")",
":",
"if",
"state",
"is",
"None",
":",
"return",
"self",
".",
"__debug",
"self",
".",
"__debug",
"=",
"bool",
"(",
"state",
")",
"return",
"self",
".",
"__debug"
] | Get or set debug mode
:param state: debug state or None for get value
:type state: bool or None
:returns: debug state or None if set fail
:rtype: bool or None | [
"Get",
"or",
"set",
"debug",
"mode"
] | 993f6e2f5ab52eba164be049e42cea560c3751a5 | https://github.com/sourceperl/pyModbusTCP/blob/993f6e2f5ab52eba164be049e42cea560c3751a5/pyModbusTCP/client.py#L196-L207 |
249,653 | sourceperl/pyModbusTCP | pyModbusTCP/client.py | ModbusClient.auto_open | def auto_open(self, state=None):
"""Get or set automatic TCP connect mode
:param state: auto_open state or None for get value
:type state: bool or None
:returns: auto_open state or None if set fail
:rtype: bool or None
"""
if state is None:
return sel... | python | def auto_open(self, state=None):
if state is None:
return self.__auto_open
self.__auto_open = bool(state)
return self.__auto_open | [
"def",
"auto_open",
"(",
"self",
",",
"state",
"=",
"None",
")",
":",
"if",
"state",
"is",
"None",
":",
"return",
"self",
".",
"__auto_open",
"self",
".",
"__auto_open",
"=",
"bool",
"(",
"state",
")",
"return",
"self",
".",
"__auto_open"
] | Get or set automatic TCP connect mode
:param state: auto_open state or None for get value
:type state: bool or None
:returns: auto_open state or None if set fail
:rtype: bool or None | [
"Get",
"or",
"set",
"automatic",
"TCP",
"connect",
"mode"
] | 993f6e2f5ab52eba164be049e42cea560c3751a5 | https://github.com/sourceperl/pyModbusTCP/blob/993f6e2f5ab52eba164be049e42cea560c3751a5/pyModbusTCP/client.py#L209-L220 |
249,654 | sourceperl/pyModbusTCP | pyModbusTCP/client.py | ModbusClient._can_read | def _can_read(self):
"""Wait data available for socket read
:returns: True if data available or None if timeout or socket error
:rtype: bool or None
"""
if self.__sock is None:
return None
if select.select([self.__sock], [], [], self.__timeout)[0]:
... | python | def _can_read(self):
if self.__sock is None:
return None
if select.select([self.__sock], [], [], self.__timeout)[0]:
return True
else:
self.__last_error = const.MB_TIMEOUT_ERR
self.__debug_msg('timeout error')
self.close()
r... | [
"def",
"_can_read",
"(",
"self",
")",
":",
"if",
"self",
".",
"__sock",
"is",
"None",
":",
"return",
"None",
"if",
"select",
".",
"select",
"(",
"[",
"self",
".",
"__sock",
"]",
",",
"[",
"]",
",",
"[",
"]",
",",
"self",
".",
"__timeout",
")",
... | Wait data available for socket read
:returns: True if data available or None if timeout or socket error
:rtype: bool or None | [
"Wait",
"data",
"available",
"for",
"socket",
"read"
] | 993f6e2f5ab52eba164be049e42cea560c3751a5 | https://github.com/sourceperl/pyModbusTCP/blob/993f6e2f5ab52eba164be049e42cea560c3751a5/pyModbusTCP/client.py#L740-L754 |
249,655 | sourceperl/pyModbusTCP | pyModbusTCP/client.py | ModbusClient._send | def _send(self, data):
"""Send data over current socket
:param data: registers value to write
:type data: str (Python2) or class bytes (Python3)
:returns: True if send ok or None if error
:rtype: bool or None
"""
# check link
if self.__sock is None:
... | python | def _send(self, data):
# check link
if self.__sock is None:
self.__debug_msg('call _send on close socket')
return None
# send
data_l = len(data)
try:
send_l = self.__sock.send(data)
except socket.error:
send_l = None
... | [
"def",
"_send",
"(",
"self",
",",
"data",
")",
":",
"# check link",
"if",
"self",
".",
"__sock",
"is",
"None",
":",
"self",
".",
"__debug_msg",
"(",
"'call _send on close socket'",
")",
"return",
"None",
"# send",
"data_l",
"=",
"len",
"(",
"data",
")",
... | Send data over current socket
:param data: registers value to write
:type data: str (Python2) or class bytes (Python3)
:returns: True if send ok or None if error
:rtype: bool or None | [
"Send",
"data",
"over",
"current",
"socket"
] | 993f6e2f5ab52eba164be049e42cea560c3751a5 | https://github.com/sourceperl/pyModbusTCP/blob/993f6e2f5ab52eba164be049e42cea560c3751a5/pyModbusTCP/client.py#L756-L781 |
249,656 | sourceperl/pyModbusTCP | pyModbusTCP/client.py | ModbusClient._recv | def _recv(self, max_size):
"""Receive data over current socket
:param max_size: number of bytes to receive
:type max_size: int
:returns: receive data or None if error
:rtype: str (Python2) or class bytes (Python3) or None
"""
# wait for read
if not self._... | python | def _recv(self, max_size):
# wait for read
if not self._can_read():
self.close()
return None
# recv
try:
r_buffer = self.__sock.recv(max_size)
except socket.error:
r_buffer = None
# handle recv error
if not r_buffer:... | [
"def",
"_recv",
"(",
"self",
",",
"max_size",
")",
":",
"# wait for read",
"if",
"not",
"self",
".",
"_can_read",
"(",
")",
":",
"self",
".",
"close",
"(",
")",
"return",
"None",
"# recv",
"try",
":",
"r_buffer",
"=",
"self",
".",
"__sock",
".",
"rec... | Receive data over current socket
:param max_size: number of bytes to receive
:type max_size: int
:returns: receive data or None if error
:rtype: str (Python2) or class bytes (Python3) or None | [
"Receive",
"data",
"over",
"current",
"socket"
] | 993f6e2f5ab52eba164be049e42cea560c3751a5 | https://github.com/sourceperl/pyModbusTCP/blob/993f6e2f5ab52eba164be049e42cea560c3751a5/pyModbusTCP/client.py#L783-L806 |
249,657 | sourceperl/pyModbusTCP | pyModbusTCP/client.py | ModbusClient._send_mbus | def _send_mbus(self, frame):
"""Send modbus frame
:param frame: modbus frame to send (with MBAP for TCP/CRC for RTU)
:type frame: str (Python2) or class bytes (Python3)
:returns: number of bytes send or None if error
:rtype: int or None
"""
# for auto_open mode, ... | python | def _send_mbus(self, frame):
# for auto_open mode, check TCP and open if need
if self.__auto_open and not self.is_open():
self.open()
# send request
bytes_send = self._send(frame)
if bytes_send:
if self.__debug:
self._pretty_dump('Tx', fram... | [
"def",
"_send_mbus",
"(",
"self",
",",
"frame",
")",
":",
"# for auto_open mode, check TCP and open if need",
"if",
"self",
".",
"__auto_open",
"and",
"not",
"self",
".",
"is_open",
"(",
")",
":",
"self",
".",
"open",
"(",
")",
"# send request",
"bytes_send",
... | Send modbus frame
:param frame: modbus frame to send (with MBAP for TCP/CRC for RTU)
:type frame: str (Python2) or class bytes (Python3)
:returns: number of bytes send or None if error
:rtype: int or None | [
"Send",
"modbus",
"frame"
] | 993f6e2f5ab52eba164be049e42cea560c3751a5 | https://github.com/sourceperl/pyModbusTCP/blob/993f6e2f5ab52eba164be049e42cea560c3751a5/pyModbusTCP/client.py#L824-L842 |
249,658 | sourceperl/pyModbusTCP | pyModbusTCP/client.py | ModbusClient._recv_mbus | def _recv_mbus(self):
"""Receive a modbus frame
:returns: modbus frame body or None if error
:rtype: str (Python2) or class bytes (Python3) or None
"""
# receive
# modbus TCP receive
if self.__mode == const.MODBUS_TCP:
# 7 bytes header (mbap)
... | python | def _recv_mbus(self):
# receive
# modbus TCP receive
if self.__mode == const.MODBUS_TCP:
# 7 bytes header (mbap)
rx_buffer = self._recv_all(7)
# check recv
if not (rx_buffer and len(rx_buffer) == 7):
self.__last_error = const.MB_REC... | [
"def",
"_recv_mbus",
"(",
"self",
")",
":",
"# receive",
"# modbus TCP receive",
"if",
"self",
".",
"__mode",
"==",
"const",
".",
"MODBUS_TCP",
":",
"# 7 bytes header (mbap)",
"rx_buffer",
"=",
"self",
".",
"_recv_all",
"(",
"7",
")",
"# check recv",
"if",
"no... | Receive a modbus frame
:returns: modbus frame body or None if error
:rtype: str (Python2) or class bytes (Python3) or None | [
"Receive",
"a",
"modbus",
"frame"
] | 993f6e2f5ab52eba164be049e42cea560c3751a5 | https://github.com/sourceperl/pyModbusTCP/blob/993f6e2f5ab52eba164be049e42cea560c3751a5/pyModbusTCP/client.py#L844-L939 |
249,659 | ihabunek/toot | toot/wcstring.py | _wc_hard_wrap | def _wc_hard_wrap(line, length):
"""
Wrap text to length characters, breaking when target length is reached,
taking into account character width.
Used to wrap lines which cannot be wrapped on whitespace.
"""
chars = []
chars_len = 0
for char in line:
char_len = wcwidth(char)
... | python | def _wc_hard_wrap(line, length):
chars = []
chars_len = 0
for char in line:
char_len = wcwidth(char)
if chars_len + char_len > length:
yield "".join(chars)
chars = []
chars_len = 0
chars.append(char)
chars_len += char_len
if chars:
... | [
"def",
"_wc_hard_wrap",
"(",
"line",
",",
"length",
")",
":",
"chars",
"=",
"[",
"]",
"chars_len",
"=",
"0",
"for",
"char",
"in",
"line",
":",
"char_len",
"=",
"wcwidth",
"(",
"char",
")",
"if",
"chars_len",
"+",
"char_len",
">",
"length",
":",
"yiel... | Wrap text to length characters, breaking when target length is reached,
taking into account character width.
Used to wrap lines which cannot be wrapped on whitespace. | [
"Wrap",
"text",
"to",
"length",
"characters",
"breaking",
"when",
"target",
"length",
"is",
"reached",
"taking",
"into",
"account",
"character",
"width",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/wcstring.py#L10-L30 |
249,660 | ihabunek/toot | toot/wcstring.py | wc_wrap | def wc_wrap(text, length):
"""
Wrap text to given length, breaking on whitespace and taking into account
character width.
Meant for use on a single line or paragraph. Will destroy spacing between
words and paragraphs and any indentation.
"""
line_words = []
line_len = 0
words = re.... | python | def wc_wrap(text, length):
line_words = []
line_len = 0
words = re.split(r"\s+", text.strip())
for word in words:
word_len = wcswidth(word)
if line_words and line_len + word_len > length:
line = " ".join(line_words)
if line_len <= length:
yield l... | [
"def",
"wc_wrap",
"(",
"text",
",",
"length",
")",
":",
"line_words",
"=",
"[",
"]",
"line_len",
"=",
"0",
"words",
"=",
"re",
".",
"split",
"(",
"r\"\\s+\"",
",",
"text",
".",
"strip",
"(",
")",
")",
"for",
"word",
"in",
"words",
":",
"word_len",
... | Wrap text to given length, breaking on whitespace and taking into account
character width.
Meant for use on a single line or paragraph. Will destroy spacing between
words and paragraphs and any indentation. | [
"Wrap",
"text",
"to",
"given",
"length",
"breaking",
"on",
"whitespace",
"and",
"taking",
"into",
"account",
"character",
"width",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/wcstring.py#L33-L66 |
249,661 | ihabunek/toot | toot/wcstring.py | trunc | def trunc(text, length):
"""
Truncates text to given length, taking into account wide characters.
If truncated, the last char is replaced by an elipsis.
"""
if length < 1:
raise ValueError("length should be 1 or larger")
# Remove whitespace first so no unneccesary truncation is done.
... | python | def trunc(text, length):
if length < 1:
raise ValueError("length should be 1 or larger")
# Remove whitespace first so no unneccesary truncation is done.
text = text.strip()
text_length = wcswidth(text)
if text_length <= length:
return text
# We cannot just remove n characters ... | [
"def",
"trunc",
"(",
"text",
",",
"length",
")",
":",
"if",
"length",
"<",
"1",
":",
"raise",
"ValueError",
"(",
"\"length should be 1 or larger\"",
")",
"# Remove whitespace first so no unneccesary truncation is done.",
"text",
"=",
"text",
".",
"strip",
"(",
")",
... | Truncates text to given length, taking into account wide characters.
If truncated, the last char is replaced by an elipsis. | [
"Truncates",
"text",
"to",
"given",
"length",
"taking",
"into",
"account",
"wide",
"characters",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/wcstring.py#L69-L98 |
249,662 | ihabunek/toot | toot/wcstring.py | pad | def pad(text, length):
"""Pads text to given length, taking into account wide characters."""
text_length = wcswidth(text)
if text_length < length:
return text + ' ' * (length - text_length)
return text | python | def pad(text, length):
text_length = wcswidth(text)
if text_length < length:
return text + ' ' * (length - text_length)
return text | [
"def",
"pad",
"(",
"text",
",",
"length",
")",
":",
"text_length",
"=",
"wcswidth",
"(",
"text",
")",
"if",
"text_length",
"<",
"length",
":",
"return",
"text",
"+",
"' '",
"*",
"(",
"length",
"-",
"text_length",
")",
"return",
"text"
] | Pads text to given length, taking into account wide characters. | [
"Pads",
"text",
"to",
"given",
"length",
"taking",
"into",
"account",
"wide",
"characters",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/wcstring.py#L101-L108 |
249,663 | ihabunek/toot | toot/wcstring.py | fit_text | def fit_text(text, length):
"""Makes text fit the given length by padding or truncating it."""
text_length = wcswidth(text)
if text_length > length:
return trunc(text, length)
if text_length < length:
return pad(text, length)
return text | python | def fit_text(text, length):
text_length = wcswidth(text)
if text_length > length:
return trunc(text, length)
if text_length < length:
return pad(text, length)
return text | [
"def",
"fit_text",
"(",
"text",
",",
"length",
")",
":",
"text_length",
"=",
"wcswidth",
"(",
"text",
")",
"if",
"text_length",
">",
"length",
":",
"return",
"trunc",
"(",
"text",
",",
"length",
")",
"if",
"text_length",
"<",
"length",
":",
"return",
"... | Makes text fit the given length by padding or truncating it. | [
"Makes",
"text",
"fit",
"the",
"given",
"length",
"by",
"padding",
"or",
"truncating",
"it",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/wcstring.py#L111-L121 |
249,664 | ihabunek/toot | toot/http.py | _get_error_message | def _get_error_message(response):
"""Attempt to extract an error message from response body"""
try:
data = response.json()
if "error_description" in data:
return data['error_description']
if "error" in data:
return data['error']
except Exception:
pass
... | python | def _get_error_message(response):
try:
data = response.json()
if "error_description" in data:
return data['error_description']
if "error" in data:
return data['error']
except Exception:
pass
return "Unknown error" | [
"def",
"_get_error_message",
"(",
"response",
")",
":",
"try",
":",
"data",
"=",
"response",
".",
"json",
"(",
")",
"if",
"\"error_description\"",
"in",
"data",
":",
"return",
"data",
"[",
"'error_description'",
"]",
"if",
"\"error\"",
"in",
"data",
":",
"... | Attempt to extract an error message from response body | [
"Attempt",
"to",
"extract",
"an",
"error",
"message",
"from",
"response",
"body"
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/http.py#L19-L30 |
249,665 | ihabunek/toot | toot/api.py | _get_next_path | def _get_next_path(headers):
"""Given timeline response headers, returns the path to the next batch"""
links = headers.get('Link', '')
matches = re.match('<([^>]+)>; rel="next"', links)
if matches:
parsed = urlparse(matches.group(1))
return "?".join([parsed.path, parsed.query]) | python | def _get_next_path(headers):
links = headers.get('Link', '')
matches = re.match('<([^>]+)>; rel="next"', links)
if matches:
parsed = urlparse(matches.group(1))
return "?".join([parsed.path, parsed.query]) | [
"def",
"_get_next_path",
"(",
"headers",
")",
":",
"links",
"=",
"headers",
".",
"get",
"(",
"'Link'",
",",
"''",
")",
"matches",
"=",
"re",
".",
"match",
"(",
"'<([^>]+)>; rel=\"next\"'",
",",
"links",
")",
"if",
"matches",
":",
"parsed",
"=",
"urlparse... | Given timeline response headers, returns the path to the next batch | [
"Given",
"timeline",
"response",
"headers",
"returns",
"the",
"path",
"to",
"the",
"next",
"batch"
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/api.py#L160-L166 |
249,666 | ihabunek/toot | toot/ui/app.py | TimelineApp.select_previous | def select_previous(self):
"""Move to the previous status in the timeline."""
self.footer.clear_message()
if self.selected == 0:
self.footer.draw_message("Cannot move beyond first toot.", Color.GREEN)
return
old_index = self.selected
new_index = self.sel... | python | def select_previous(self):
self.footer.clear_message()
if self.selected == 0:
self.footer.draw_message("Cannot move beyond first toot.", Color.GREEN)
return
old_index = self.selected
new_index = self.selected - 1
self.selected = new_index
self.r... | [
"def",
"select_previous",
"(",
"self",
")",
":",
"self",
".",
"footer",
".",
"clear_message",
"(",
")",
"if",
"self",
".",
"selected",
"==",
"0",
":",
"self",
".",
"footer",
".",
"draw_message",
"(",
"\"Cannot move beyond first toot.\"",
",",
"Color",
".",
... | Move to the previous status in the timeline. | [
"Move",
"to",
"the",
"previous",
"status",
"in",
"the",
"timeline",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/ui/app.py#L692-L704 |
249,667 | ihabunek/toot | toot/ui/app.py | TimelineApp.select_next | def select_next(self):
"""Move to the next status in the timeline."""
self.footer.clear_message()
old_index = self.selected
new_index = self.selected + 1
# Load more statuses if no more are available
if self.selected + 1 >= len(self.statuses):
self.fetch_nex... | python | def select_next(self):
self.footer.clear_message()
old_index = self.selected
new_index = self.selected + 1
# Load more statuses if no more are available
if self.selected + 1 >= len(self.statuses):
self.fetch_next()
self.left.draw_statuses(self.statuses, ... | [
"def",
"select_next",
"(",
"self",
")",
":",
"self",
".",
"footer",
".",
"clear_message",
"(",
")",
"old_index",
"=",
"self",
".",
"selected",
"new_index",
"=",
"self",
".",
"selected",
"+",
"1",
"# Load more statuses if no more are available",
"if",
"self",
"... | Move to the next status in the timeline. | [
"Move",
"to",
"the",
"next",
"status",
"in",
"the",
"timeline",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/ui/app.py#L706-L720 |
249,668 | ihabunek/toot | toot/ui/app.py | TimelineApp.full_redraw | def full_redraw(self):
"""Perform a full redraw of the UI."""
self.left.draw_statuses(self.statuses, self.selected)
self.right.draw(self.get_selected_status())
self.header.draw(self.user)
self.draw_footer_status() | python | def full_redraw(self):
self.left.draw_statuses(self.statuses, self.selected)
self.right.draw(self.get_selected_status())
self.header.draw(self.user)
self.draw_footer_status() | [
"def",
"full_redraw",
"(",
"self",
")",
":",
"self",
".",
"left",
".",
"draw_statuses",
"(",
"self",
".",
"statuses",
",",
"self",
".",
"selected",
")",
"self",
".",
"right",
".",
"draw",
"(",
"self",
".",
"get_selected_status",
"(",
")",
")",
"self",
... | Perform a full redraw of the UI. | [
"Perform",
"a",
"full",
"redraw",
"of",
"the",
"UI",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/ui/app.py#L740-L746 |
249,669 | ihabunek/toot | toot/ui/utils.py | size_as_drawn | def size_as_drawn(lines, screen_width):
"""Get the bottom-right corner of some text as would be drawn by draw_lines"""
y = 0
x = 0
for line in lines:
wrapped = list(wc_wrap(line, screen_width))
if len(wrapped) > 0:
for wrapped_line in wrapped:
x = len(wrapped_... | python | def size_as_drawn(lines, screen_width):
y = 0
x = 0
for line in lines:
wrapped = list(wc_wrap(line, screen_width))
if len(wrapped) > 0:
for wrapped_line in wrapped:
x = len(wrapped_line)
y += 1
else:
x = 0
y += 1
... | [
"def",
"size_as_drawn",
"(",
"lines",
",",
"screen_width",
")",
":",
"y",
"=",
"0",
"x",
"=",
"0",
"for",
"line",
"in",
"lines",
":",
"wrapped",
"=",
"list",
"(",
"wc_wrap",
"(",
"line",
",",
"screen_width",
")",
")",
"if",
"len",
"(",
"wrapped",
"... | Get the bottom-right corner of some text as would be drawn by draw_lines | [
"Get",
"the",
"bottom",
"-",
"right",
"corner",
"of",
"some",
"text",
"as",
"would",
"be",
"drawn",
"by",
"draw_lines"
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/ui/utils.py#L49-L62 |
249,670 | ihabunek/toot | toot/commands.py | _find_account | def _find_account(app, user, account_name):
"""For a given account name, returns the Account object.
Raises an exception if not found.
"""
if not account_name:
raise ConsoleError("Empty account name given")
accounts = api.search_accounts(app, user, account_name)
if account_name[0] == ... | python | def _find_account(app, user, account_name):
if not account_name:
raise ConsoleError("Empty account name given")
accounts = api.search_accounts(app, user, account_name)
if account_name[0] == "@":
account_name = account_name[1:]
for account in accounts:
if account['acct'] == acc... | [
"def",
"_find_account",
"(",
"app",
",",
"user",
",",
"account_name",
")",
":",
"if",
"not",
"account_name",
":",
"raise",
"ConsoleError",
"(",
"\"Empty account name given\"",
")",
"accounts",
"=",
"api",
".",
"search_accounts",
"(",
"app",
",",
"user",
",",
... | For a given account name, returns the Account object.
Raises an exception if not found. | [
"For",
"a",
"given",
"account",
"name",
"returns",
"the",
"Account",
"object",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/commands.py#L216-L233 |
249,671 | ihabunek/toot | toot/config_legacy.py | add_username | def add_username(user, apps):
"""When using broser login, username was not stored so look it up"""
if not user:
return None
apps = [a for a in apps if a.instance == user.instance]
if not apps:
return None
from toot.api import verify_credentials
creds = verify_credentials(apps.... | python | def add_username(user, apps):
if not user:
return None
apps = [a for a in apps if a.instance == user.instance]
if not apps:
return None
from toot.api import verify_credentials
creds = verify_credentials(apps.pop(), user)
return User(user.instance, creds['username'], user.acce... | [
"def",
"add_username",
"(",
"user",
",",
"apps",
")",
":",
"if",
"not",
"user",
":",
"return",
"None",
"apps",
"=",
"[",
"a",
"for",
"a",
"in",
"apps",
"if",
"a",
".",
"instance",
"==",
"user",
".",
"instance",
"]",
"if",
"not",
"apps",
":",
"ret... | When using broser login, username was not stored so look it up | [
"When",
"using",
"broser",
"login",
"username",
"was",
"not",
"stored",
"so",
"look",
"it",
"up"
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/config_legacy.py#L42-L55 |
249,672 | ihabunek/toot | toot/utils.py | get_text | def get_text(html):
"""Converts html to text, strips all tags."""
# Ignore warnings made by BeautifulSoup, if passed something that looks like
# a file (e.g. a dot which matches current dict), it will warn that the file
# should be opened instead of passing a filename.
with warnings.catch_warnings(... | python | def get_text(html):
# Ignore warnings made by BeautifulSoup, if passed something that looks like
# a file (e.g. a dot which matches current dict), it will warn that the file
# should be opened instead of passing a filename.
with warnings.catch_warnings():
warnings.simplefilter("ignore")
... | [
"def",
"get_text",
"(",
"html",
")",
":",
"# Ignore warnings made by BeautifulSoup, if passed something that looks like",
"# a file (e.g. a dot which matches current dict), it will warn that the file",
"# should be opened instead of passing a filename.",
"with",
"warnings",
".",
"catch_warni... | Converts html to text, strips all tags. | [
"Converts",
"html",
"to",
"text",
"strips",
"all",
"tags",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/utils.py#L19-L29 |
249,673 | ihabunek/toot | toot/utils.py | parse_html | def parse_html(html):
"""Attempt to convert html to plain text while keeping line breaks.
Returns a list of paragraphs, each being a list of lines.
"""
paragraphs = re.split("</?p[^>]*>", html)
# Convert <br>s to line breaks and remove empty paragraphs
paragraphs = [re.split("<br */?>", p) for ... | python | def parse_html(html):
paragraphs = re.split("</?p[^>]*>", html)
# Convert <br>s to line breaks and remove empty paragraphs
paragraphs = [re.split("<br */?>", p) for p in paragraphs if p]
# Convert each line in each paragraph to plain text:
return [[get_text(l) for l in p] for p in paragraphs] | [
"def",
"parse_html",
"(",
"html",
")",
":",
"paragraphs",
"=",
"re",
".",
"split",
"(",
"\"</?p[^>]*>\"",
",",
"html",
")",
"# Convert <br>s to line breaks and remove empty paragraphs",
"paragraphs",
"=",
"[",
"re",
".",
"split",
"(",
"\"<br */?>\"",
",",
"p",
"... | Attempt to convert html to plain text while keeping line breaks.
Returns a list of paragraphs, each being a list of lines. | [
"Attempt",
"to",
"convert",
"html",
"to",
"plain",
"text",
"while",
"keeping",
"line",
"breaks",
".",
"Returns",
"a",
"list",
"of",
"paragraphs",
"each",
"being",
"a",
"list",
"of",
"lines",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/utils.py#L32-L42 |
249,674 | ihabunek/toot | toot/utils.py | format_content | def format_content(content):
"""Given a Status contents in HTML, converts it into lines of plain text.
Returns a generator yielding lines of content.
"""
paragraphs = parse_html(content)
first = True
for paragraph in paragraphs:
if not first:
yield ""
for line in... | python | def format_content(content):
paragraphs = parse_html(content)
first = True
for paragraph in paragraphs:
if not first:
yield ""
for line in paragraph:
yield line
first = False | [
"def",
"format_content",
"(",
"content",
")",
":",
"paragraphs",
"=",
"parse_html",
"(",
"content",
")",
"first",
"=",
"True",
"for",
"paragraph",
"in",
"paragraphs",
":",
"if",
"not",
"first",
":",
"yield",
"\"\"",
"for",
"line",
"in",
"paragraph",
":",
... | Given a Status contents in HTML, converts it into lines of plain text.
Returns a generator yielding lines of content. | [
"Given",
"a",
"Status",
"contents",
"in",
"HTML",
"converts",
"it",
"into",
"lines",
"of",
"plain",
"text",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/utils.py#L45-L62 |
249,675 | ihabunek/toot | toot/utils.py | multiline_input | def multiline_input():
"""Lets user input multiple lines of text, terminated by EOF."""
lines = []
while True:
try:
lines.append(input())
except EOFError:
break
return "\n".join(lines).strip() | python | def multiline_input():
lines = []
while True:
try:
lines.append(input())
except EOFError:
break
return "\n".join(lines).strip() | [
"def",
"multiline_input",
"(",
")",
":",
"lines",
"=",
"[",
"]",
"while",
"True",
":",
"try",
":",
"lines",
".",
"append",
"(",
"input",
"(",
")",
")",
"except",
"EOFError",
":",
"break",
"return",
"\"\\n\"",
".",
"join",
"(",
"lines",
")",
".",
"s... | Lets user input multiple lines of text, terminated by EOF. | [
"Lets",
"user",
"input",
"multiple",
"lines",
"of",
"text",
"terminated",
"by",
"EOF",
"."
] | d13fa8685b300f96621fa325774913ec0f413a7f | https://github.com/ihabunek/toot/blob/d13fa8685b300f96621fa325774913ec0f413a7f/toot/utils.py#L81-L90 |
249,676 | Azure/azure-kusto-python | azure-kusto-data/azure/kusto/data/_models.py | KustoResultTable.to_dict | def to_dict(self):
"""Converts the table to a dict."""
return {"name": self.table_name, "kind": self.table_kind, "data": [r.to_dict() for r in self]} | python | def to_dict(self):
return {"name": self.table_name, "kind": self.table_kind, "data": [r.to_dict() for r in self]} | [
"def",
"to_dict",
"(",
"self",
")",
":",
"return",
"{",
"\"name\"",
":",
"self",
".",
"table_name",
",",
"\"kind\"",
":",
"self",
".",
"table_kind",
",",
"\"data\"",
":",
"[",
"r",
".",
"to_dict",
"(",
")",
"for",
"r",
"in",
"self",
"]",
"}"
] | Converts the table to a dict. | [
"Converts",
"the",
"table",
"to",
"a",
"dict",
"."
] | 92466a2ae175d6353d1dee3496a02517b2a71a86 | https://github.com/Azure/azure-kusto-python/blob/92466a2ae175d6353d1dee3496a02517b2a71a86/azure-kusto-data/azure/kusto/data/_models.py#L152-L154 |
249,677 | Azure/azure-kusto-python | azure-kusto-data/azure/kusto/data/_converters.py | to_datetime | def to_datetime(value):
"""Converts a string to a datetime."""
if value is None:
return None
if isinstance(value, six.integer_types):
return parser.parse(value)
return parser.isoparse(value) | python | def to_datetime(value):
if value is None:
return None
if isinstance(value, six.integer_types):
return parser.parse(value)
return parser.isoparse(value) | [
"def",
"to_datetime",
"(",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"value",
",",
"six",
".",
"integer_types",
")",
":",
"return",
"parser",
".",
"parse",
"(",
"value",
")",
"return",
"parser",
"."... | Converts a string to a datetime. | [
"Converts",
"a",
"string",
"to",
"a",
"datetime",
"."
] | 92466a2ae175d6353d1dee3496a02517b2a71a86 | https://github.com/Azure/azure-kusto-python/blob/92466a2ae175d6353d1dee3496a02517b2a71a86/azure-kusto-data/azure/kusto/data/_converters.py#L12-L19 |
249,678 | Azure/azure-kusto-python | azure-kusto-data/azure/kusto/data/_converters.py | to_timedelta | def to_timedelta(value):
"""Converts a string to a timedelta."""
if value is None:
return None
if isinstance(value, (six.integer_types, float)):
return timedelta(microseconds=(float(value) / 10))
match = _TIMESPAN_PATTERN.match(value)
if match:
if match.group(1) == "-":
... | python | def to_timedelta(value):
if value is None:
return None
if isinstance(value, (six.integer_types, float)):
return timedelta(microseconds=(float(value) / 10))
match = _TIMESPAN_PATTERN.match(value)
if match:
if match.group(1) == "-":
factor = -1
else:
... | [
"def",
"to_timedelta",
"(",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"value",
",",
"(",
"six",
".",
"integer_types",
",",
"float",
")",
")",
":",
"return",
"timedelta",
"(",
"microseconds",
"=",
"(... | Converts a string to a timedelta. | [
"Converts",
"a",
"string",
"to",
"a",
"timedelta",
"."
] | 92466a2ae175d6353d1dee3496a02517b2a71a86 | https://github.com/Azure/azure-kusto-python/blob/92466a2ae175d6353d1dee3496a02517b2a71a86/azure-kusto-data/azure/kusto/data/_converters.py#L22-L41 |
249,679 | Azure/azure-kusto-python | azure-kusto-data/azure/kusto/data/security.py | _AadHelper.acquire_authorization_header | def acquire_authorization_header(self):
"""Acquire tokens from AAD."""
try:
return self._acquire_authorization_header()
except AdalError as error:
if self._authentication_method is AuthenticationMethod.aad_username_password:
kwargs = {"username": self._use... | python | def acquire_authorization_header(self):
try:
return self._acquire_authorization_header()
except AdalError as error:
if self._authentication_method is AuthenticationMethod.aad_username_password:
kwargs = {"username": self._username, "client_id": self._client_id}
... | [
"def",
"acquire_authorization_header",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"_acquire_authorization_header",
"(",
")",
"except",
"AdalError",
"as",
"error",
":",
"if",
"self",
".",
"_authentication_method",
"is",
"AuthenticationMethod",
".",
"... | Acquire tokens from AAD. | [
"Acquire",
"tokens",
"from",
"AAD",
"."
] | 92466a2ae175d6353d1dee3496a02517b2a71a86 | https://github.com/Azure/azure-kusto-python/blob/92466a2ae175d6353d1dee3496a02517b2a71a86/azure-kusto-data/azure/kusto/data/security.py#L49-L68 |
249,680 | Azure/azure-kusto-python | azure-kusto-data/azure/kusto/data/request.py | KustoClient._execute | def _execute(self, endpoint, database, query, default_timeout, properties=None):
"""Executes given query against this client"""
request_payload = {"db": database, "csl": query}
if properties:
request_payload["properties"] = properties.to_json()
request_headers = {
... | python | def _execute(self, endpoint, database, query, default_timeout, properties=None):
request_payload = {"db": database, "csl": query}
if properties:
request_payload["properties"] = properties.to_json()
request_headers = {
"Accept": "application/json",
"Acc... | [
"def",
"_execute",
"(",
"self",
",",
"endpoint",
",",
"database",
",",
"query",
",",
"default_timeout",
",",
"properties",
"=",
"None",
")",
":",
"request_payload",
"=",
"{",
"\"db\"",
":",
"database",
",",
"\"csl\"",
":",
"query",
"}",
"if",
"properties",... | Executes given query against this client | [
"Executes",
"given",
"query",
"against",
"this",
"client"
] | 92466a2ae175d6353d1dee3496a02517b2a71a86 | https://github.com/Azure/azure-kusto-python/blob/92466a2ae175d6353d1dee3496a02517b2a71a86/azure-kusto-data/azure/kusto/data/request.py#L360-L386 |
249,681 | Azure/azure-kusto-python | azure-kusto-data/azure/kusto/data/request.py | ClientRequestProperties.set_option | def set_option(self, name, value):
"""Sets an option's value"""
_assert_value_is_valid(name)
self._options[name] = value | python | def set_option(self, name, value):
_assert_value_is_valid(name)
self._options[name] = value | [
"def",
"set_option",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"_assert_value_is_valid",
"(",
"name",
")",
"self",
".",
"_options",
"[",
"name",
"]",
"=",
"value"
] | Sets an option's value | [
"Sets",
"an",
"option",
"s",
"value"
] | 92466a2ae175d6353d1dee3496a02517b2a71a86 | https://github.com/Azure/azure-kusto-python/blob/92466a2ae175d6353d1dee3496a02517b2a71a86/azure-kusto-data/azure/kusto/data/request.py#L467-L470 |
249,682 | Azure/azure-kusto-python | azure-kusto-ingest/azure/kusto/ingest/_resource_manager.py | _ResourceUri.parse | def parse(cls, uri):
"""Parses uri into a ResourceUri object"""
match = _URI_FORMAT.search(uri)
return cls(match.group(1), match.group(2), match.group(3), match.group(4)) | python | def parse(cls, uri):
match = _URI_FORMAT.search(uri)
return cls(match.group(1), match.group(2), match.group(3), match.group(4)) | [
"def",
"parse",
"(",
"cls",
",",
"uri",
")",
":",
"match",
"=",
"_URI_FORMAT",
".",
"search",
"(",
"uri",
")",
"return",
"cls",
"(",
"match",
".",
"group",
"(",
"1",
")",
",",
"match",
".",
"group",
"(",
"2",
")",
",",
"match",
".",
"group",
"(... | Parses uri into a ResourceUri object | [
"Parses",
"uri",
"into",
"a",
"ResourceUri",
"object"
] | 92466a2ae175d6353d1dee3496a02517b2a71a86 | https://github.com/Azure/azure-kusto-python/blob/92466a2ae175d6353d1dee3496a02517b2a71a86/azure-kusto-ingest/azure/kusto/ingest/_resource_manager.py#L17-L20 |
249,683 | Azure/azure-kusto-python | azure-kusto-ingest/azure/kusto/ingest/_ingestion_properties.py | IngestionProperties.get_mapping_format | def get_mapping_format(self):
"""Dictating the corresponding mapping to the format."""
if self.format == DataFormat.json or self.format == DataFormat.avro:
return self.format.name
else:
return DataFormat.csv.name | python | def get_mapping_format(self):
if self.format == DataFormat.json or self.format == DataFormat.avro:
return self.format.name
else:
return DataFormat.csv.name | [
"def",
"get_mapping_format",
"(",
"self",
")",
":",
"if",
"self",
".",
"format",
"==",
"DataFormat",
".",
"json",
"or",
"self",
".",
"format",
"==",
"DataFormat",
".",
"avro",
":",
"return",
"self",
".",
"format",
".",
"name",
"else",
":",
"return",
"D... | Dictating the corresponding mapping to the format. | [
"Dictating",
"the",
"corresponding",
"mapping",
"to",
"the",
"format",
"."
] | 92466a2ae175d6353d1dee3496a02517b2a71a86 | https://github.com/Azure/azure-kusto-python/blob/92466a2ae175d6353d1dee3496a02517b2a71a86/azure-kusto-ingest/azure/kusto/ingest/_ingestion_properties.py#L125-L130 |
249,684 | yuce/pyswip | pyswip/easy.py | getAtomChars | def getAtomChars(t):
"""If t is an atom, return it as a string, otherwise raise InvalidTypeError.
"""
s = c_char_p()
if PL_get_atom_chars(t, byref(s)):
return s.value
else:
raise InvalidTypeError("atom") | python | def getAtomChars(t):
s = c_char_p()
if PL_get_atom_chars(t, byref(s)):
return s.value
else:
raise InvalidTypeError("atom") | [
"def",
"getAtomChars",
"(",
"t",
")",
":",
"s",
"=",
"c_char_p",
"(",
")",
"if",
"PL_get_atom_chars",
"(",
"t",
",",
"byref",
"(",
"s",
")",
")",
":",
"return",
"s",
".",
"value",
"else",
":",
"raise",
"InvalidTypeError",
"(",
"\"atom\"",
")"
] | If t is an atom, return it as a string, otherwise raise InvalidTypeError. | [
"If",
"t",
"is",
"an",
"atom",
"return",
"it",
"as",
"a",
"string",
"otherwise",
"raise",
"InvalidTypeError",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/easy.py#L333-L340 |
249,685 | yuce/pyswip | pyswip/easy.py | getBool | def getBool(t):
"""If t is of type bool, return it, otherwise raise InvalidTypeError.
"""
b = c_int()
if PL_get_long(t, byref(b)):
return bool(b.value)
else:
raise InvalidTypeError("bool") | python | def getBool(t):
b = c_int()
if PL_get_long(t, byref(b)):
return bool(b.value)
else:
raise InvalidTypeError("bool") | [
"def",
"getBool",
"(",
"t",
")",
":",
"b",
"=",
"c_int",
"(",
")",
"if",
"PL_get_long",
"(",
"t",
",",
"byref",
"(",
"b",
")",
")",
":",
"return",
"bool",
"(",
"b",
".",
"value",
")",
"else",
":",
"raise",
"InvalidTypeError",
"(",
"\"bool\"",
")"... | If t is of type bool, return it, otherwise raise InvalidTypeError. | [
"If",
"t",
"is",
"of",
"type",
"bool",
"return",
"it",
"otherwise",
"raise",
"InvalidTypeError",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/easy.py#L349-L356 |
249,686 | yuce/pyswip | pyswip/easy.py | getLong | def getLong(t):
"""If t is of type long, return it, otherwise raise InvalidTypeError.
"""
i = c_long()
if PL_get_long(t, byref(i)):
return i.value
else:
raise InvalidTypeError("long") | python | def getLong(t):
i = c_long()
if PL_get_long(t, byref(i)):
return i.value
else:
raise InvalidTypeError("long") | [
"def",
"getLong",
"(",
"t",
")",
":",
"i",
"=",
"c_long",
"(",
")",
"if",
"PL_get_long",
"(",
"t",
",",
"byref",
"(",
"i",
")",
")",
":",
"return",
"i",
".",
"value",
"else",
":",
"raise",
"InvalidTypeError",
"(",
"\"long\"",
")"
] | If t is of type long, return it, otherwise raise InvalidTypeError. | [
"If",
"t",
"is",
"of",
"type",
"long",
"return",
"it",
"otherwise",
"raise",
"InvalidTypeError",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/easy.py#L359-L366 |
249,687 | yuce/pyswip | pyswip/easy.py | getFloat | def getFloat(t):
"""If t is of type float, return it, otherwise raise InvalidTypeError.
"""
d = c_double()
if PL_get_float(t, byref(d)):
return d.value
else:
raise InvalidTypeError("float") | python | def getFloat(t):
d = c_double()
if PL_get_float(t, byref(d)):
return d.value
else:
raise InvalidTypeError("float") | [
"def",
"getFloat",
"(",
"t",
")",
":",
"d",
"=",
"c_double",
"(",
")",
"if",
"PL_get_float",
"(",
"t",
",",
"byref",
"(",
"d",
")",
")",
":",
"return",
"d",
".",
"value",
"else",
":",
"raise",
"InvalidTypeError",
"(",
"\"float\"",
")"
] | If t is of type float, return it, otherwise raise InvalidTypeError. | [
"If",
"t",
"is",
"of",
"type",
"float",
"return",
"it",
"otherwise",
"raise",
"InvalidTypeError",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/easy.py#L372-L379 |
249,688 | yuce/pyswip | pyswip/easy.py | getString | def getString(t):
"""If t is of type string, return it, otherwise raise InvalidTypeError.
"""
slen = c_int()
s = c_char_p()
if PL_get_string_chars(t, byref(s), byref(slen)):
return s.value
else:
raise InvalidTypeError("string") | python | def getString(t):
slen = c_int()
s = c_char_p()
if PL_get_string_chars(t, byref(s), byref(slen)):
return s.value
else:
raise InvalidTypeError("string") | [
"def",
"getString",
"(",
"t",
")",
":",
"slen",
"=",
"c_int",
"(",
")",
"s",
"=",
"c_char_p",
"(",
")",
"if",
"PL_get_string_chars",
"(",
"t",
",",
"byref",
"(",
"s",
")",
",",
"byref",
"(",
"slen",
")",
")",
":",
"return",
"s",
".",
"value",
"... | If t is of type string, return it, otherwise raise InvalidTypeError. | [
"If",
"t",
"is",
"of",
"type",
"string",
"return",
"it",
"otherwise",
"raise",
"InvalidTypeError",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/easy.py#L382-L390 |
249,689 | yuce/pyswip | pyswip/easy.py | getList | def getList(x):
"""
Return t as a list.
"""
t = PL_copy_term_ref(x)
head = PL_new_term_ref()
result = []
while PL_get_list(t, head, t):
result.append(getTerm(head))
head = PL_new_term_ref()
return result | python | def getList(x):
t = PL_copy_term_ref(x)
head = PL_new_term_ref()
result = []
while PL_get_list(t, head, t):
result.append(getTerm(head))
head = PL_new_term_ref()
return result | [
"def",
"getList",
"(",
"x",
")",
":",
"t",
"=",
"PL_copy_term_ref",
"(",
"x",
")",
"head",
"=",
"PL_new_term_ref",
"(",
")",
"result",
"=",
"[",
"]",
"while",
"PL_get_list",
"(",
"t",
",",
"head",
",",
"t",
")",
":",
"result",
".",
"append",
"(",
... | Return t as a list. | [
"Return",
"t",
"as",
"a",
"list",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/easy.py#L411-L423 |
249,690 | yuce/pyswip | pyswip/easy.py | Atom.fromTerm | def fromTerm(cls, term):
"""Create an atom from a Term or term handle."""
if isinstance(term, Term):
term = term.handle
elif not isinstance(term, (c_void_p, int)):
raise ArgumentTypeError((str(Term), str(c_void_p)), str(type(term)))
a = atom_t()
if PL_ge... | python | def fromTerm(cls, term):
if isinstance(term, Term):
term = term.handle
elif not isinstance(term, (c_void_p, int)):
raise ArgumentTypeError((str(Term), str(c_void_p)), str(type(term)))
a = atom_t()
if PL_get_atom(term, byref(a)):
return cls(a.value) | [
"def",
"fromTerm",
"(",
"cls",
",",
"term",
")",
":",
"if",
"isinstance",
"(",
"term",
",",
"Term",
")",
":",
"term",
"=",
"term",
".",
"handle",
"elif",
"not",
"isinstance",
"(",
"term",
",",
"(",
"c_void_p",
",",
"int",
")",
")",
":",
"raise",
... | Create an atom from a Term or term handle. | [
"Create",
"an",
"atom",
"from",
"a",
"Term",
"or",
"term",
"handle",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/easy.py#L62-L72 |
249,691 | yuce/pyswip | pyswip/easy.py | Functor.fromTerm | def fromTerm(cls, term):
"""Create a functor from a Term or term handle."""
if isinstance(term, Term):
term = term.handle
elif not isinstance(term, (c_void_p, int)):
raise ArgumentTypeError((str(Term), str(int)), str(type(term)))
f = functor_t()
if PL_ge... | python | def fromTerm(cls, term):
if isinstance(term, Term):
term = term.handle
elif not isinstance(term, (c_void_p, int)):
raise ArgumentTypeError((str(Term), str(int)), str(type(term)))
f = functor_t()
if PL_get_functor(term, byref(f)):
# get args
... | [
"def",
"fromTerm",
"(",
"cls",
",",
"term",
")",
":",
"if",
"isinstance",
"(",
"term",
",",
"Term",
")",
":",
"term",
"=",
"term",
".",
"handle",
"elif",
"not",
"isinstance",
"(",
"term",
",",
"(",
"c_void_p",
",",
"int",
")",
")",
":",
"raise",
... | Create a functor from a Term or term handle. | [
"Create",
"a",
"functor",
"from",
"a",
"Term",
"or",
"term",
"handle",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/easy.py#L235-L254 |
249,692 | yuce/pyswip | pyswip/core.py | _findSwiplWin | def _findSwiplWin():
import re
"""
This function uses several heuristics to gues where SWI-Prolog is installed
in Windows. It always returns None as the path of the resource file because,
in Windows, the way to find it is more robust so the SWI-Prolog DLL is
always able to find it.
:return... | python | def _findSwiplWin():
import re
dllNames = ('swipl.dll', 'libswipl.dll')
# First try: check the usual installation path (this is faster but
# hardcoded)
programFiles = os.getenv('ProgramFiles')
paths = [os.path.join(programFiles, r'pl\bin', dllName)
for dllName in dllNames]
for... | [
"def",
"_findSwiplWin",
"(",
")",
":",
"import",
"re",
"dllNames",
"=",
"(",
"'swipl.dll'",
",",
"'libswipl.dll'",
")",
"# First try: check the usual installation path (this is faster but",
"# hardcoded)",
"programFiles",
"=",
"os",
".",
"getenv",
"(",
"'ProgramFiles'",
... | This function uses several heuristics to gues where SWI-Prolog is installed
in Windows. It always returns None as the path of the resource file because,
in Windows, the way to find it is more robust so the SWI-Prolog DLL is
always able to find it.
:returns:
A tuple of (path to the swipl DLL, pa... | [
"This",
"function",
"uses",
"several",
"heuristics",
"to",
"gues",
"where",
"SWI",
"-",
"Prolog",
"is",
"installed",
"in",
"Windows",
".",
"It",
"always",
"returns",
"None",
"as",
"the",
"path",
"of",
"the",
"resource",
"file",
"because",
"in",
"Windows",
... | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/core.py#L159-L232 |
249,693 | yuce/pyswip | pyswip/core.py | _findSwiplLin | def _findSwiplLin():
"""
This function uses several heuristics to guess where SWI-Prolog is
installed in Linuxes.
:returns:
A tuple of (path to the swipl so, path to the resource file)
:returns type:
({str, None}, {str, None})
"""
# Maybe the exec is on path?
(path, sw... | python | def _findSwiplLin():
# Maybe the exec is on path?
(path, swiHome) = _findSwiplFromExec()
if path is not None:
return (path, swiHome)
# If it is not, use find_library
path = _findSwiplPathFromFindLib()
if path is not None:
return (path, swiHome)
# Our last try: some hardcod... | [
"def",
"_findSwiplLin",
"(",
")",
":",
"# Maybe the exec is on path?",
"(",
"path",
",",
"swiHome",
")",
"=",
"_findSwiplFromExec",
"(",
")",
"if",
"path",
"is",
"not",
"None",
":",
"return",
"(",
"path",
",",
"swiHome",
")",
"# If it is not, use find_library",... | This function uses several heuristics to guess where SWI-Prolog is
installed in Linuxes.
:returns:
A tuple of (path to the swipl so, path to the resource file)
:returns type:
({str, None}, {str, None}) | [
"This",
"function",
"uses",
"several",
"heuristics",
"to",
"guess",
"where",
"SWI",
"-",
"Prolog",
"is",
"installed",
"in",
"Linuxes",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/core.py#L234-L271 |
249,694 | yuce/pyswip | pyswip/core.py | _findSwiplDar | def _findSwiplDar():
"""
This function uses several heuristics to guess where SWI-Prolog is
installed in MacOS.
:returns:
A tuple of (path to the swipl so, path to the resource file)
:returns type:
({str, None}, {str, None})
"""
# If the exec is in path
(path, swiHome)... | python | def _findSwiplDar():
# If the exec is in path
(path, swiHome) = _findSwiplFromExec()
if path is not None:
return (path, swiHome)
# If it is not, use find_library
path = _findSwiplPathFromFindLib()
if path is not None:
return (path, swiHome)
# Last guess, searching for the ... | [
"def",
"_findSwiplDar",
"(",
")",
":",
"# If the exec is in path",
"(",
"path",
",",
"swiHome",
")",
"=",
"_findSwiplFromExec",
"(",
")",
"if",
"path",
"is",
"not",
"None",
":",
"return",
"(",
"path",
",",
"swiHome",
")",
"# If it is not, use find_library",
"... | This function uses several heuristics to guess where SWI-Prolog is
installed in MacOS.
:returns:
A tuple of (path to the swipl so, path to the resource file)
:returns type:
({str, None}, {str, None}) | [
"This",
"function",
"uses",
"several",
"heuristics",
"to",
"guess",
"where",
"SWI",
"-",
"Prolog",
"is",
"installed",
"in",
"MacOS",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/core.py#L358-L390 |
249,695 | yuce/pyswip | pyswip/core.py | _fixWindowsPath | def _fixWindowsPath(dll):
"""
When the path to the DLL is not in Windows search path, Windows will not be
able to find other DLLs on the same directory, so we have to add it to the
path. This function takes care of it.
:parameters:
- `dll` (str) - File name of the DLL
"""
if sys.pla... | python | def _fixWindowsPath(dll):
if sys.platform[:3] != 'win':
return # Nothing to do here
pathToDll = os.path.dirname(dll)
currentWindowsPath = os.getenv('PATH')
if pathToDll not in currentWindowsPath:
# We will prepend the path, to avoid conflicts between DLLs
newPath = pathToDll + ... | [
"def",
"_fixWindowsPath",
"(",
"dll",
")",
":",
"if",
"sys",
".",
"platform",
"[",
":",
"3",
"]",
"!=",
"'win'",
":",
"return",
"# Nothing to do here",
"pathToDll",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"dll",
")",
"currentWindowsPath",
"=",
"os",... | When the path to the DLL is not in Windows search path, Windows will not be
able to find other DLLs on the same directory, so we have to add it to the
path. This function takes care of it.
:parameters:
- `dll` (str) - File name of the DLL | [
"When",
"the",
"path",
"to",
"the",
"DLL",
"is",
"not",
"in",
"Windows",
"search",
"path",
"Windows",
"will",
"not",
"be",
"able",
"to",
"find",
"other",
"DLLs",
"on",
"the",
"same",
"directory",
"so",
"we",
"have",
"to",
"add",
"it",
"to",
"the",
"p... | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/core.py#L435-L454 |
249,696 | yuce/pyswip | pyswip/core.py | list_to_bytes_list | def list_to_bytes_list(strList):
"""
This function turns an array of strings into a pointer array
with pointers pointing to the encodings of those strings
Possibly contained bytes are kept as they are.
:param strList: List of strings that shall be converted
:type strList: List of strings
:r... | python | def list_to_bytes_list(strList):
pList = c_char_p * len(strList)
# if strList is already a pointerarray or None, there is nothing to do
if isinstance(strList, (pList, type(None))):
return strList
if not isinstance(strList, (list, set, tuple)):
raise TypeError("strList must be list, set... | [
"def",
"list_to_bytes_list",
"(",
"strList",
")",
":",
"pList",
"=",
"c_char_p",
"*",
"len",
"(",
"strList",
")",
"# if strList is already a pointerarray or None, there is nothing to do",
"if",
"isinstance",
"(",
"strList",
",",
"(",
"pList",
",",
"type",
"(",
"None... | This function turns an array of strings into a pointer array
with pointers pointing to the encodings of those strings
Possibly contained bytes are kept as they are.
:param strList: List of strings that shall be converted
:type strList: List of strings
:returns: Pointer array with pointers pointing ... | [
"This",
"function",
"turns",
"an",
"array",
"of",
"strings",
"into",
"a",
"pointer",
"array",
"with",
"pointers",
"pointing",
"to",
"the",
"encodings",
"of",
"those",
"strings",
"Possibly",
"contained",
"bytes",
"are",
"kept",
"as",
"they",
"are",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/core.py#L478-L502 |
249,697 | yuce/pyswip | pyswip/core.py | check_strings | def check_strings(strings, arrays):
"""
Decorator function which can be used to automatically turn an incoming
string into a bytes object and an incoming list to a pointer array if
necessary.
:param strings: Indices of the arguments must be pointers to bytes
:type strings: List of integers
... | python | def check_strings(strings, arrays):
# if given a single element, turn it into a list
if isinstance(strings, int):
strings = [strings]
elif strings is None:
strings = []
# check if all entries are integers
for i,k in enumerate(strings):
if not isinstance(k, int):
... | [
"def",
"check_strings",
"(",
"strings",
",",
"arrays",
")",
":",
"# if given a single element, turn it into a list",
"if",
"isinstance",
"(",
"strings",
",",
"int",
")",
":",
"strings",
"=",
"[",
"strings",
"]",
"elif",
"strings",
"is",
"None",
":",
"strings",
... | Decorator function which can be used to automatically turn an incoming
string into a bytes object and an incoming list to a pointer array if
necessary.
:param strings: Indices of the arguments must be pointers to bytes
:type strings: List of integers
:param arrays: Indices of the arguments must be ... | [
"Decorator",
"function",
"which",
"can",
"be",
"used",
"to",
"automatically",
"turn",
"an",
"incoming",
"string",
"into",
"a",
"bytes",
"object",
"and",
"an",
"incoming",
"list",
"to",
"a",
"pointer",
"array",
"if",
"necessary",
"."
] | f7c1f1e8c3a13b90bd775861d374788a8b5677d8 | https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/core.py#L506-L563 |
249,698 | hazelcast/hazelcast-python-client | hazelcast/proxy/queue.py | Queue.add | def add(self, item):
"""
Adds the specified item to this queue if there is available space.
:param item: (object), the specified item.
:return: (bool), ``true`` if element is successfully added, ``false`` otherwise.
"""
def result_fnc(f):
if f.result():
... | python | def add(self, item):
def result_fnc(f):
if f.result():
return True
raise Full("Queue is full!")
return self.offer(item).continue_with(result_fnc) | [
"def",
"add",
"(",
"self",
",",
"item",
")",
":",
"def",
"result_fnc",
"(",
"f",
")",
":",
"if",
"f",
".",
"result",
"(",
")",
":",
"return",
"True",
"raise",
"Full",
"(",
"\"Queue is full!\"",
")",
"return",
"self",
".",
"offer",
"(",
"item",
")",... | Adds the specified item to this queue if there is available space.
:param item: (object), the specified item.
:return: (bool), ``true`` if element is successfully added, ``false`` otherwise. | [
"Adds",
"the",
"specified",
"item",
"to",
"this",
"queue",
"if",
"there",
"is",
"available",
"space",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/queue.py#L39-L51 |
249,699 | hazelcast/hazelcast-python-client | hazelcast/proxy/queue.py | Queue.add_all | def add_all(self, items):
"""
Adds the elements in the specified collection to this queue.
:param items: (Collection), collection which includes the items to be added.
:return: (bool), ``true`` if this queue is changed after call, ``false`` otherwise.
"""
check_not_none(... | python | def add_all(self, items):
check_not_none(items, "Value can't be None")
data_items = []
for item in items:
check_not_none(item, "Value can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(queue_add_all_codec, data_list=data_items) | [
"def",
"add_all",
"(",
"self",
",",
"items",
")",
":",
"check_not_none",
"(",
"items",
",",
"\"Value can't be None\"",
")",
"data_items",
"=",
"[",
"]",
"for",
"item",
"in",
"items",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",
"d... | Adds the elements in the specified collection to this queue.
:param items: (Collection), collection which includes the items to be added.
:return: (bool), ``true`` if this queue is changed after call, ``false`` otherwise. | [
"Adds",
"the",
"elements",
"in",
"the",
"specified",
"collection",
"to",
"this",
"queue",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/queue.py#L53-L65 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.