repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
pilliq/scratchpy | scratch/scratch.py | Scratch._pack | def _pack(self, msg):
"""
Packages msg according to Scratch message specification (encodes and
appends length prefix to msg). Credit to chalkmarrow from the
scratch.mit.edu forums for the prefix encoding code.
"""
n = len(msg)
a = array.array('c')
a.app... | python | def _pack(self, msg):
"""
Packages msg according to Scratch message specification (encodes and
appends length prefix to msg). Credit to chalkmarrow from the
scratch.mit.edu forums for the prefix encoding code.
"""
n = len(msg)
a = array.array('c')
a.app... | [
"def",
"_pack",
"(",
"self",
",",
"msg",
")",
":",
"n",
"=",
"len",
"(",
"msg",
")",
"a",
"=",
"array",
".",
"array",
"(",
"'c'",
")",
"a",
".",
"append",
"(",
"chr",
"(",
"(",
"n",
">>",
"24",
")",
"&",
"0xFF",
")",
")",
"a",
".",
"appen... | Packages msg according to Scratch message specification (encodes and
appends length prefix to msg). Credit to chalkmarrow from the
scratch.mit.edu forums for the prefix encoding code. | [
"Packages",
"msg",
"according",
"to",
"Scratch",
"message",
"specification",
"(",
"encodes",
"and",
"appends",
"length",
"prefix",
"to",
"msg",
")",
".",
"Credit",
"to",
"chalkmarrow",
"from",
"the",
"scratch",
".",
"mit",
".",
"edu",
"forums",
"for",
"the",... | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L27-L39 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch._get_type | def _get_type(self, s):
"""
Converts a string from Scratch to its proper type in Python. Expects a
string with its delimiting quotes in place. Returns either a string,
int or float.
"""
# TODO: what if the number is bigger than an int or float?
if s.startswith('... | python | def _get_type(self, s):
"""
Converts a string from Scratch to its proper type in Python. Expects a
string with its delimiting quotes in place. Returns either a string,
int or float.
"""
# TODO: what if the number is bigger than an int or float?
if s.startswith('... | [
"def",
"_get_type",
"(",
"self",
",",
"s",
")",
":",
"# TODO: what if the number is bigger than an int or float?",
"if",
"s",
".",
"startswith",
"(",
"'\"'",
")",
"and",
"s",
".",
"endswith",
"(",
"'\"'",
")",
":",
"return",
"s",
"[",
"1",
":",
"-",
"1",
... | Converts a string from Scratch to its proper type in Python. Expects a
string with its delimiting quotes in place. Returns either a string,
int or float. | [
"Converts",
"a",
"string",
"from",
"Scratch",
"to",
"its",
"proper",
"type",
"in",
"Python",
".",
"Expects",
"a",
"string",
"with",
"its",
"delimiting",
"quotes",
"in",
"place",
".",
"Returns",
"either",
"a",
"string",
"int",
"or",
"float",
"."
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L47-L59 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch._escape | def _escape(self, msg):
"""
Escapes double quotes by adding another double quote as per the Scratch
protocol. Expects a string without its delimiting quotes. Returns a new
escaped string.
"""
escaped = ''
for c in msg:
escaped += c
if c ... | python | def _escape(self, msg):
"""
Escapes double quotes by adding another double quote as per the Scratch
protocol. Expects a string without its delimiting quotes. Returns a new
escaped string.
"""
escaped = ''
for c in msg:
escaped += c
if c ... | [
"def",
"_escape",
"(",
"self",
",",
"msg",
")",
":",
"escaped",
"=",
"''",
"for",
"c",
"in",
"msg",
":",
"escaped",
"+=",
"c",
"if",
"c",
"==",
"'\"'",
":",
"escaped",
"+=",
"'\"'",
"return",
"escaped"
] | Escapes double quotes by adding another double quote as per the Scratch
protocol. Expects a string without its delimiting quotes. Returns a new
escaped string. | [
"Escapes",
"double",
"quotes",
"by",
"adding",
"another",
"double",
"quote",
"as",
"per",
"the",
"Scratch",
"protocol",
".",
"Expects",
"a",
"string",
"without",
"its",
"delimiting",
"quotes",
".",
"Returns",
"a",
"new",
"escaped",
"string",
"."
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L61-L72 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch._unescape | def _unescape(self, msg):
"""
Removes double quotes that were used to escape double quotes. Expects
a string without its delimiting quotes, or a number. Returns a new
unescaped string.
"""
if isinstance(msg, (int, float, long)):
return msg
unescaped =... | python | def _unescape(self, msg):
"""
Removes double quotes that were used to escape double quotes. Expects
a string without its delimiting quotes, or a number. Returns a new
unescaped string.
"""
if isinstance(msg, (int, float, long)):
return msg
unescaped =... | [
"def",
"_unescape",
"(",
"self",
",",
"msg",
")",
":",
"if",
"isinstance",
"(",
"msg",
",",
"(",
"int",
",",
"float",
",",
"long",
")",
")",
":",
"return",
"msg",
"unescaped",
"=",
"''",
"i",
"=",
"0",
"while",
"i",
"<",
"len",
"(",
"msg",
")",... | Removes double quotes that were used to escape double quotes. Expects
a string without its delimiting quotes, or a number. Returns a new
unescaped string. | [
"Removes",
"double",
"quotes",
"that",
"were",
"used",
"to",
"escape",
"double",
"quotes",
".",
"Expects",
"a",
"string",
"without",
"its",
"delimiting",
"quotes",
"or",
"a",
"number",
".",
"Returns",
"a",
"new",
"unescaped",
"string",
"."
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L74-L90 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch._is_msg | def _is_msg(self, msg):
"""
Returns True if message is a proper Scratch message, else return False.
"""
if not msg or len(msg) < self.prefix_len:
return False
length = self._extract_len(msg[:self.prefix_len])
msg_type = msg[self.prefix_len:].split(' ', 1)[0]
... | python | def _is_msg(self, msg):
"""
Returns True if message is a proper Scratch message, else return False.
"""
if not msg or len(msg) < self.prefix_len:
return False
length = self._extract_len(msg[:self.prefix_len])
msg_type = msg[self.prefix_len:].split(' ', 1)[0]
... | [
"def",
"_is_msg",
"(",
"self",
",",
"msg",
")",
":",
"if",
"not",
"msg",
"or",
"len",
"(",
"msg",
")",
"<",
"self",
".",
"prefix_len",
":",
"return",
"False",
"length",
"=",
"self",
".",
"_extract_len",
"(",
"msg",
"[",
":",
"self",
".",
"prefix_le... | Returns True if message is a proper Scratch message, else return False. | [
"Returns",
"True",
"if",
"message",
"is",
"a",
"proper",
"Scratch",
"message",
"else",
"return",
"False",
"."
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L92-L102 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch._parse_broadcast | def _parse_broadcast(self, msg):
"""
Given a broacast message, returns the message that was broadcast.
"""
# get message, remove surrounding quotes, and unescape
return self._unescape(self._get_type(msg[self.broadcast_prefix_len:])) | python | def _parse_broadcast(self, msg):
"""
Given a broacast message, returns the message that was broadcast.
"""
# get message, remove surrounding quotes, and unescape
return self._unescape(self._get_type(msg[self.broadcast_prefix_len:])) | [
"def",
"_parse_broadcast",
"(",
"self",
",",
"msg",
")",
":",
"# get message, remove surrounding quotes, and unescape",
"return",
"self",
".",
"_unescape",
"(",
"self",
".",
"_get_type",
"(",
"msg",
"[",
"self",
".",
"broadcast_prefix_len",
":",
"]",
")",
")"
] | Given a broacast message, returns the message that was broadcast. | [
"Given",
"a",
"broacast",
"message",
"returns",
"the",
"message",
"that",
"was",
"broadcast",
"."
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L104-L109 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch._parse_sensorupdate | def _parse_sensorupdate(self, msg):
"""
Given a sensor-update message, returns the sensors/variables that were
updated as a dict that maps sensors/variables to their updated values.
"""
update = msg[self.sensorupdate_prefix_len:]
parsed = [] # each element is either a sen... | python | def _parse_sensorupdate(self, msg):
"""
Given a sensor-update message, returns the sensors/variables that were
updated as a dict that maps sensors/variables to their updated values.
"""
update = msg[self.sensorupdate_prefix_len:]
parsed = [] # each element is either a sen... | [
"def",
"_parse_sensorupdate",
"(",
"self",
",",
"msg",
")",
":",
"update",
"=",
"msg",
"[",
"self",
".",
"sensorupdate_prefix_len",
":",
"]",
"parsed",
"=",
"[",
"]",
"# each element is either a sensor (key) or a sensor value",
"curr_seg",
"=",
"''",
"# current segm... | Given a sensor-update message, returns the sensors/variables that were
updated as a dict that maps sensors/variables to their updated values. | [
"Given",
"a",
"sensor",
"-",
"update",
"message",
"returns",
"the",
"sensors",
"/",
"variables",
"that",
"were",
"updated",
"as",
"a",
"dict",
"that",
"maps",
"sensors",
"/",
"variables",
"to",
"their",
"updated",
"values",
"."
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L111-L134 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch._parse | def _parse(self, msg):
"""
Parses a Scratch message and returns a tuple with the first element
as the message type, and the second element as the message payload. The
payload for a 'broadcast' message is a string, and the payload for a
'sensor-update' message is a dict whose ke... | python | def _parse(self, msg):
"""
Parses a Scratch message and returns a tuple with the first element
as the message type, and the second element as the message payload. The
payload for a 'broadcast' message is a string, and the payload for a
'sensor-update' message is a dict whose ke... | [
"def",
"_parse",
"(",
"self",
",",
"msg",
")",
":",
"if",
"not",
"self",
".",
"_is_msg",
"(",
"msg",
")",
":",
"return",
"None",
"msg_type",
"=",
"msg",
"[",
"self",
".",
"prefix_len",
":",
"]",
".",
"split",
"(",
"' '",
")",
"[",
"0",
"]",
"if... | Parses a Scratch message and returns a tuple with the first element
as the message type, and the second element as the message payload. The
payload for a 'broadcast' message is a string, and the payload for a
'sensor-update' message is a dict whose keys are variables, and values
are up... | [
"Parses",
"a",
"Scratch",
"message",
"and",
"returns",
"a",
"tuple",
"with",
"the",
"first",
"element",
"as",
"the",
"message",
"type",
"and",
"the",
"second",
"element",
"as",
"the",
"message",
"payload",
".",
"The",
"payload",
"for",
"a",
"broadcast",
"m... | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L136-L150 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch._write | def _write(self, data):
"""
Writes string data out to Scratch
"""
total_sent = 0
length = len(data)
while total_sent < length:
try:
sent = self.socket.send(data[total_sent:])
except socket.error as (err, msg):
self.c... | python | def _write(self, data):
"""
Writes string data out to Scratch
"""
total_sent = 0
length = len(data)
while total_sent < length:
try:
sent = self.socket.send(data[total_sent:])
except socket.error as (err, msg):
self.c... | [
"def",
"_write",
"(",
"self",
",",
"data",
")",
":",
"total_sent",
"=",
"0",
"length",
"=",
"len",
"(",
"data",
")",
"while",
"total_sent",
"<",
"length",
":",
"try",
":",
"sent",
"=",
"self",
".",
"socket",
".",
"send",
"(",
"data",
"[",
"total_se... | Writes string data out to Scratch | [
"Writes",
"string",
"data",
"out",
"to",
"Scratch"
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L152-L167 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch._read | def _read(self, size):
"""
Reads size number of bytes from Scratch and returns data as a string
"""
data = ''
while len(data) < size:
try:
chunk = self.socket.recv(size-len(data))
except socket.error as (err, msg):
self.conn... | python | def _read(self, size):
"""
Reads size number of bytes from Scratch and returns data as a string
"""
data = ''
while len(data) < size:
try:
chunk = self.socket.recv(size-len(data))
except socket.error as (err, msg):
self.conn... | [
"def",
"_read",
"(",
"self",
",",
"size",
")",
":",
"data",
"=",
"''",
"while",
"len",
"(",
"data",
")",
"<",
"size",
":",
"try",
":",
"chunk",
"=",
"self",
".",
"socket",
".",
"recv",
"(",
"size",
"-",
"len",
"(",
"data",
")",
")",
"except",
... | Reads size number of bytes from Scratch and returns data as a string | [
"Reads",
"size",
"number",
"of",
"bytes",
"from",
"Scratch",
"and",
"returns",
"data",
"as",
"a",
"string"
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L175-L190 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch._recv | def _recv(self):
"""
Receives and returns a message from Scratch
"""
prefix = self._read(self.prefix_len)
msg = self._read(self._extract_len(prefix))
return prefix + msg | python | def _recv(self):
"""
Receives and returns a message from Scratch
"""
prefix = self._read(self.prefix_len)
msg = self._read(self._extract_len(prefix))
return prefix + msg | [
"def",
"_recv",
"(",
"self",
")",
":",
"prefix",
"=",
"self",
".",
"_read",
"(",
"self",
".",
"prefix_len",
")",
"msg",
"=",
"self",
".",
"_read",
"(",
"self",
".",
"_extract_len",
"(",
"prefix",
")",
")",
"return",
"prefix",
"+",
"msg"
] | Receives and returns a message from Scratch | [
"Receives",
"and",
"returns",
"a",
"message",
"from",
"Scratch"
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L192-L198 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch.connect | def connect(self):
"""
Connects to Scratch.
"""
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
self.socket.connect((self.host, self.port))
except socket.error as (err, msg):
self.connected = False
raise ScratchErro... | python | def connect(self):
"""
Connects to Scratch.
"""
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
self.socket.connect((self.host, self.port))
except socket.error as (err, msg):
self.connected = False
raise ScratchErro... | [
"def",
"connect",
"(",
"self",
")",
":",
"self",
".",
"socket",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
"SOCK_STREAM",
")",
"try",
":",
"self",
".",
"socket",
".",
"connect",
"(",
"(",
"self",
".",
"host",
"... | Connects to Scratch. | [
"Connects",
"to",
"Scratch",
"."
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L200-L210 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch.disconnect | def disconnect(self):
"""
Closes connection to Scratch
"""
try: # connection may already be disconnected, so catch exceptions
self.socket.shutdown(socket.SHUT_RDWR) # a proper disconnect
except socket.error:
pass
self.socket.close()
self.co... | python | def disconnect(self):
"""
Closes connection to Scratch
"""
try: # connection may already be disconnected, so catch exceptions
self.socket.shutdown(socket.SHUT_RDWR) # a proper disconnect
except socket.error:
pass
self.socket.close()
self.co... | [
"def",
"disconnect",
"(",
"self",
")",
":",
"try",
":",
"# connection may already be disconnected, so catch exceptions",
"self",
".",
"socket",
".",
"shutdown",
"(",
"socket",
".",
"SHUT_RDWR",
")",
"# a proper disconnect",
"except",
"socket",
".",
"error",
":",
"pa... | Closes connection to Scratch | [
"Closes",
"connection",
"to",
"Scratch"
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L212-L221 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch.sensorupdate | def sensorupdate(self, data):
"""
Given a dict of sensors and values, updates those sensors with the
values in Scratch.
"""
if not isinstance(data, dict):
raise TypeError('Expected a dict')
msg = 'sensor-update '
for key in data.keys():
ms... | python | def sensorupdate(self, data):
"""
Given a dict of sensors and values, updates those sensors with the
values in Scratch.
"""
if not isinstance(data, dict):
raise TypeError('Expected a dict')
msg = 'sensor-update '
for key in data.keys():
ms... | [
"def",
"sensorupdate",
"(",
"self",
",",
"data",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"'Expected a dict'",
")",
"msg",
"=",
"'sensor-update '",
"for",
"key",
"in",
"data",
".",
"keys",
"(",
... | Given a dict of sensors and values, updates those sensors with the
values in Scratch. | [
"Given",
"a",
"dict",
"of",
"sensors",
"and",
"values",
"updates",
"those",
"sensors",
"with",
"the",
"values",
"in",
"Scratch",
"."
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L223-L234 | train |
pilliq/scratchpy | scratch/scratch.py | Scratch.broadcast | def broadcast(self, msg):
"""
Broadcasts msg to Scratch. msg can be a single message or an iterable
(list, tuple, set, generator, etc.) of messages.
"""
if getattr(msg, '__iter__', False): # iterable
for m in msg:
self._send('broadcast "%s"' % self._e... | python | def broadcast(self, msg):
"""
Broadcasts msg to Scratch. msg can be a single message or an iterable
(list, tuple, set, generator, etc.) of messages.
"""
if getattr(msg, '__iter__', False): # iterable
for m in msg:
self._send('broadcast "%s"' % self._e... | [
"def",
"broadcast",
"(",
"self",
",",
"msg",
")",
":",
"if",
"getattr",
"(",
"msg",
",",
"'__iter__'",
",",
"False",
")",
":",
"# iterable",
"for",
"m",
"in",
"msg",
":",
"self",
".",
"_send",
"(",
"'broadcast \"%s\"'",
"%",
"self",
".",
"_escape",
"... | Broadcasts msg to Scratch. msg can be a single message or an iterable
(list, tuple, set, generator, etc.) of messages. | [
"Broadcasts",
"msg",
"to",
"Scratch",
".",
"msg",
"can",
"be",
"a",
"single",
"message",
"or",
"an",
"iterable",
"(",
"list",
"tuple",
"set",
"generator",
"etc",
".",
")",
"of",
"messages",
"."
] | a594561c147b1cf6696231c26a0475c7d52b8039 | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L236-L245 | train |
AirSage/Petrel | petrel/petrel/mock.py | Mock.run_simple_topology | def run_simple_topology(cls, config, emitters, result_type=NAMEDTUPLE, max_spout_emits=None):
"""Tests a simple topology. "Simple" means there it has no branches
or cycles. "emitters" is a list of emitters, starting with a spout
followed by 0 or more bolts that run in a chain."""
... | python | def run_simple_topology(cls, config, emitters, result_type=NAMEDTUPLE, max_spout_emits=None):
"""Tests a simple topology. "Simple" means there it has no branches
or cycles. "emitters" is a list of emitters, starting with a spout
followed by 0 or more bolts that run in a chain."""
... | [
"def",
"run_simple_topology",
"(",
"cls",
",",
"config",
",",
"emitters",
",",
"result_type",
"=",
"NAMEDTUPLE",
",",
"max_spout_emits",
"=",
"None",
")",
":",
"# The config is almost always required. The only known reason to pass",
"# None is when calling run_simple_topology()... | Tests a simple topology. "Simple" means there it has no branches
or cycles. "emitters" is a list of emitters, starting with a spout
followed by 0 or more bolts that run in a chain. | [
"Tests",
"a",
"simple",
"topology",
".",
"Simple",
"means",
"there",
"it",
"has",
"no",
"branches",
"or",
"cycles",
".",
"emitters",
"is",
"a",
"list",
"of",
"emitters",
"starting",
"with",
"a",
"spout",
"followed",
"by",
"0",
"or",
"more",
"bolts",
"tha... | c4be9b7da5916dcc028ddb88850e7703203eeb79 | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/mock.py#L108-L164 | train |
AirSage/Petrel | petrel/petrel/topologybuilder.py | TopologyBuilder.write | def write(self, stream):
"""Writes the topology to a stream or file."""
topology = self.createTopology()
def write_it(stream):
transportOut = TMemoryBuffer()
protocolOut = TBinaryProtocol.TBinaryProtocol(transportOut)
topology.write(protocolOut)
by... | python | def write(self, stream):
"""Writes the topology to a stream or file."""
topology = self.createTopology()
def write_it(stream):
transportOut = TMemoryBuffer()
protocolOut = TBinaryProtocol.TBinaryProtocol(transportOut)
topology.write(protocolOut)
by... | [
"def",
"write",
"(",
"self",
",",
"stream",
")",
":",
"topology",
"=",
"self",
".",
"createTopology",
"(",
")",
"def",
"write_it",
"(",
"stream",
")",
":",
"transportOut",
"=",
"TMemoryBuffer",
"(",
")",
"protocolOut",
"=",
"TBinaryProtocol",
".",
"TBinary... | Writes the topology to a stream or file. | [
"Writes",
"the",
"topology",
"to",
"a",
"stream",
"or",
"file",
"."
] | c4be9b7da5916dcc028ddb88850e7703203eeb79 | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/topologybuilder.py#L110-L126 | train |
AirSage/Petrel | petrel/petrel/topologybuilder.py | TopologyBuilder.read | def read(self, stream):
"""Reads the topology from a stream or file."""
def read_it(stream):
bytes = stream.read()
transportIn = TMemoryBuffer(bytes)
protocolIn = TBinaryProtocol.TBinaryProtocol(transportIn)
topology = StormTopology()
topology.... | python | def read(self, stream):
"""Reads the topology from a stream or file."""
def read_it(stream):
bytes = stream.read()
transportIn = TMemoryBuffer(bytes)
protocolIn = TBinaryProtocol.TBinaryProtocol(transportIn)
topology = StormTopology()
topology.... | [
"def",
"read",
"(",
"self",
",",
"stream",
")",
":",
"def",
"read_it",
"(",
"stream",
")",
":",
"bytes",
"=",
"stream",
".",
"read",
"(",
")",
"transportIn",
"=",
"TMemoryBuffer",
"(",
"bytes",
")",
"protocolIn",
"=",
"TBinaryProtocol",
".",
"TBinaryProt... | Reads the topology from a stream or file. | [
"Reads",
"the",
"topology",
"from",
"a",
"stream",
"or",
"file",
"."
] | c4be9b7da5916dcc028ddb88850e7703203eeb79 | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/topologybuilder.py#L128-L142 | train |
AirSage/Petrel | petrel/petrel/package.py | build_jar | def build_jar(source_jar_path, dest_jar_path, config, venv=None, definition=None, logdir=None):
"""Build a StormTopology .jar which encapsulates the topology defined in
topology_dir. Optionally override the module and function names. This
feature supports the definition of multiple topologies in a single
... | python | def build_jar(source_jar_path, dest_jar_path, config, venv=None, definition=None, logdir=None):
"""Build a StormTopology .jar which encapsulates the topology defined in
topology_dir. Optionally override the module and function names. This
feature supports the definition of multiple topologies in a single
... | [
"def",
"build_jar",
"(",
"source_jar_path",
",",
"dest_jar_path",
",",
"config",
",",
"venv",
"=",
"None",
",",
"definition",
"=",
"None",
",",
"logdir",
"=",
"None",
")",
":",
"if",
"definition",
"is",
"None",
":",
"definition",
"=",
"'create.create'",
"#... | Build a StormTopology .jar which encapsulates the topology defined in
topology_dir. Optionally override the module and function names. This
feature supports the definition of multiple topologies in a single
directory. | [
"Build",
"a",
"StormTopology",
".",
"jar",
"which",
"encapsulates",
"the",
"topology",
"defined",
"in",
"topology_dir",
".",
"Optionally",
"override",
"the",
"module",
"and",
"function",
"names",
".",
"This",
"feature",
"supports",
"the",
"definition",
"of",
"mu... | c4be9b7da5916dcc028ddb88850e7703203eeb79 | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/package.py#L74-L172 | train |
AirSage/Petrel | petrel/petrel/storm.py | sendFailureMsgToParent | def sendFailureMsgToParent(msg):
"""This function is kind of a hack, but useful when a Python task
encounters a fatal exception. "msg" should be a simple string like
"E_SPOUTFAILED". This function sends "msg" as-is to the Storm worker,
which tries to parse it as JSON. The hacky aspect is that we
*de... | python | def sendFailureMsgToParent(msg):
"""This function is kind of a hack, but useful when a Python task
encounters a fatal exception. "msg" should be a simple string like
"E_SPOUTFAILED". This function sends "msg" as-is to the Storm worker,
which tries to parse it as JSON. The hacky aspect is that we
*de... | [
"def",
"sendFailureMsgToParent",
"(",
"msg",
")",
":",
"assert",
"isinstance",
"(",
"msg",
",",
"six",
".",
"string_types",
")",
"print",
"(",
"msg",
",",
"file",
"=",
"old_stdout",
")",
"print",
"(",
"'end'",
",",
"file",
"=",
"old_stdout",
")",
"storm_... | This function is kind of a hack, but useful when a Python task
encounters a fatal exception. "msg" should be a simple string like
"E_SPOUTFAILED". This function sends "msg" as-is to the Storm worker,
which tries to parse it as JSON. The hacky aspect is that we
*deliberately* make it fail by sending it n... | [
"This",
"function",
"is",
"kind",
"of",
"a",
"hack",
"but",
"useful",
"when",
"a",
"Python",
"task",
"encounters",
"a",
"fatal",
"exception",
".",
"msg",
"should",
"be",
"a",
"simple",
"string",
"like",
"E_SPOUTFAILED",
".",
"This",
"function",
"sends",
"m... | c4be9b7da5916dcc028ddb88850e7703203eeb79 | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/storm.py#L101-L113 | train |
AirSage/Petrel | petrel/petrel/storm.py | emitMany | def emitMany(*args, **kwargs):
"""A more efficient way to emit a number of tuples at once."""
global MODE
if MODE == Bolt:
emitManyBolt(*args, **kwargs)
elif MODE == Spout:
emitManySpout(*args, **kwargs) | python | def emitMany(*args, **kwargs):
"""A more efficient way to emit a number of tuples at once."""
global MODE
if MODE == Bolt:
emitManyBolt(*args, **kwargs)
elif MODE == Spout:
emitManySpout(*args, **kwargs) | [
"def",
"emitMany",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"global",
"MODE",
"if",
"MODE",
"==",
"Bolt",
":",
"emitManyBolt",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"elif",
"MODE",
"==",
"Spout",
":",
"emitManySpout",
"(",
"*"... | A more efficient way to emit a number of tuples at once. | [
"A",
"more",
"efficient",
"way",
"to",
"emit",
"a",
"number",
"of",
"tuples",
"at",
"once",
"."
] | c4be9b7da5916dcc028ddb88850e7703203eeb79 | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/storm.py#L132-L138 | train |
AirSage/Petrel | petrel/petrel/rdebug.py | remote_debug | def remote_debug(sig,frame):
"""Handler to allow process to be remotely debugged."""
def _raiseEx(ex):
"""Raise specified exception in the remote process"""
_raiseEx.ex = ex
_raiseEx.ex = None
try:
# Provide some useful functions.
locs = {'_raiseEx' : _raiseEx}
... | python | def remote_debug(sig,frame):
"""Handler to allow process to be remotely debugged."""
def _raiseEx(ex):
"""Raise specified exception in the remote process"""
_raiseEx.ex = ex
_raiseEx.ex = None
try:
# Provide some useful functions.
locs = {'_raiseEx' : _raiseEx}
... | [
"def",
"remote_debug",
"(",
"sig",
",",
"frame",
")",
":",
"def",
"_raiseEx",
"(",
"ex",
")",
":",
"\"\"\"Raise specified exception in the remote process\"\"\"",
"_raiseEx",
".",
"ex",
"=",
"ex",
"_raiseEx",
".",
"ex",
"=",
"None",
"try",
":",
"# Provide some us... | Handler to allow process to be remotely debugged. | [
"Handler",
"to",
"allow",
"process",
"to",
"be",
"remotely",
"debugged",
"."
] | c4be9b7da5916dcc028ddb88850e7703203eeb79 | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/rdebug.py#L72-L122 | train |
AirSage/Petrel | petrel/petrel/rdebug.py | debug_process | def debug_process(pid):
"""Interrupt a running process and debug it."""
os.kill(pid, signal.SIGUSR1) # Signal process.
pipe = NamedPipe(pipename(pid), 1)
try:
while pipe.is_open():
txt=raw_input(pipe.get()) + '\n'
pipe.put(txt)
except EOFError:
pass # Exit.
... | python | def debug_process(pid):
"""Interrupt a running process and debug it."""
os.kill(pid, signal.SIGUSR1) # Signal process.
pipe = NamedPipe(pipename(pid), 1)
try:
while pipe.is_open():
txt=raw_input(pipe.get()) + '\n'
pipe.put(txt)
except EOFError:
pass # Exit.
... | [
"def",
"debug_process",
"(",
"pid",
")",
":",
"os",
".",
"kill",
"(",
"pid",
",",
"signal",
".",
"SIGUSR1",
")",
"# Signal process.",
"pipe",
"=",
"NamedPipe",
"(",
"pipename",
"(",
"pid",
")",
",",
"1",
")",
"try",
":",
"while",
"pipe",
".",
"is_ope... | Interrupt a running process and debug it. | [
"Interrupt",
"a",
"running",
"process",
"and",
"debug",
"it",
"."
] | c4be9b7da5916dcc028ddb88850e7703203eeb79 | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/rdebug.py#L125-L135 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface._encode_utf8 | def _encode_utf8(self, **kwargs):
"""
UTF8 encodes all of the NVP values.
"""
if is_py3:
# This is only valid for Python 2. In Python 3, unicode is
# everywhere (yay).
return kwargs
unencoded_pairs = kwargs
for i in unencoded_pairs.key... | python | def _encode_utf8(self, **kwargs):
"""
UTF8 encodes all of the NVP values.
"""
if is_py3:
# This is only valid for Python 2. In Python 3, unicode is
# everywhere (yay).
return kwargs
unencoded_pairs = kwargs
for i in unencoded_pairs.key... | [
"def",
"_encode_utf8",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"is_py3",
":",
"# This is only valid for Python 2. In Python 3, unicode is",
"# everywhere (yay).",
"return",
"kwargs",
"unencoded_pairs",
"=",
"kwargs",
"for",
"i",
"in",
"unencoded_pairs",
... | UTF8 encodes all of the NVP values. | [
"UTF8",
"encodes",
"all",
"of",
"the",
"NVP",
"values",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L58-L72 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface._check_required | def _check_required(self, requires, **kwargs):
"""
Checks kwargs for the values specified in 'requires', which is a tuple
of strings. These strings are the NVP names of the required values.
"""
for req in requires:
# PayPal api is never mixed-case.
if req.... | python | def _check_required(self, requires, **kwargs):
"""
Checks kwargs for the values specified in 'requires', which is a tuple
of strings. These strings are the NVP names of the required values.
"""
for req in requires:
# PayPal api is never mixed-case.
if req.... | [
"def",
"_check_required",
"(",
"self",
",",
"requires",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"req",
"in",
"requires",
":",
"# PayPal api is never mixed-case.",
"if",
"req",
".",
"lower",
"(",
")",
"not",
"in",
"kwargs",
"and",
"req",
".",
"upper",
"... | Checks kwargs for the values specified in 'requires', which is a tuple
of strings. These strings are the NVP names of the required values. | [
"Checks",
"kwargs",
"for",
"the",
"values",
"specified",
"in",
"requires",
"which",
"is",
"a",
"tuple",
"of",
"strings",
".",
"These",
"strings",
"are",
"the",
"NVP",
"names",
"of",
"the",
"required",
"values",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L74-L82 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface._call | def _call(self, method, **kwargs):
"""
Wrapper method for executing all API commands over HTTP. This method is
further used to implement wrapper methods listed here:
https://www.x.com/docs/DOC-1374
``method`` must be a supported NVP method listed at the above address.
`... | python | def _call(self, method, **kwargs):
"""
Wrapper method for executing all API commands over HTTP. This method is
further used to implement wrapper methods listed here:
https://www.x.com/docs/DOC-1374
``method`` must be a supported NVP method listed at the above address.
`... | [
"def",
"_call",
"(",
"self",
",",
"method",
",",
"*",
"*",
"kwargs",
")",
":",
"post_params",
"=",
"self",
".",
"_get_call_params",
"(",
"method",
",",
"*",
"*",
"kwargs",
")",
"payload",
"=",
"post_params",
"[",
"'data'",
"]",
"api_endpoint",
"=",
"po... | Wrapper method for executing all API commands over HTTP. This method is
further used to implement wrapper methods listed here:
https://www.x.com/docs/DOC-1374
``method`` must be a supported NVP method listed at the above address.
``kwargs`` the actual call parameters | [
"Wrapper",
"method",
"for",
"executing",
"all",
"API",
"commands",
"over",
"HTTP",
".",
"This",
"method",
"is",
"further",
"used",
"to",
"implement",
"wrapper",
"methods",
"listed",
"here",
":"
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L95-L120 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface._get_call_params | def _get_call_params(self, method, **kwargs):
"""
Returns the prepared call parameters. Mind, these will be keyword
arguments to ``requests.post``.
``method`` the NVP method
``kwargs`` the actual call parameters
"""
payload = {'METHOD': method,
... | python | def _get_call_params(self, method, **kwargs):
"""
Returns the prepared call parameters. Mind, these will be keyword
arguments to ``requests.post``.
``method`` the NVP method
``kwargs`` the actual call parameters
"""
payload = {'METHOD': method,
... | [
"def",
"_get_call_params",
"(",
"self",
",",
"method",
",",
"*",
"*",
"kwargs",
")",
":",
"payload",
"=",
"{",
"'METHOD'",
":",
"method",
",",
"'VERSION'",
":",
"self",
".",
"config",
".",
"API_VERSION",
"}",
"certificate",
"=",
"None",
"if",
"self",
"... | Returns the prepared call parameters. Mind, these will be keyword
arguments to ``requests.post``.
``method`` the NVP method
``kwargs`` the actual call parameters | [
"Returns",
"the",
"prepared",
"call",
"parameters",
".",
"Mind",
"these",
"will",
"be",
"keyword",
"arguments",
"to",
"requests",
".",
"post",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L122-L161 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.address_verify | def address_verify(self, email, street, zip):
"""Shortcut for the AddressVerify method.
``email``::
Email address of a PayPal member to verify.
Maximum string length: 255 single-byte characters
Input mask: ?@?.??
``street``::
First line of the bil... | python | def address_verify(self, email, street, zip):
"""Shortcut for the AddressVerify method.
``email``::
Email address of a PayPal member to verify.
Maximum string length: 255 single-byte characters
Input mask: ?@?.??
``street``::
First line of the bil... | [
"def",
"address_verify",
"(",
"self",
",",
"email",
",",
"street",
",",
"zip",
")",
":",
"args",
"=",
"self",
".",
"_sanitize_locals",
"(",
"locals",
"(",
")",
")",
"return",
"self",
".",
"_call",
"(",
"'AddressVerify'",
",",
"*",
"*",
"args",
")"
] | Shortcut for the AddressVerify method.
``email``::
Email address of a PayPal member to verify.
Maximum string length: 255 single-byte characters
Input mask: ?@?.??
``street``::
First line of the billing or shipping postal address to verify.
T... | [
"Shortcut",
"for",
"the",
"AddressVerify",
"method",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L163-L190 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.do_authorization | def do_authorization(self, transactionid, amt):
"""Shortcut for the DoAuthorization method.
Use the TRANSACTIONID from DoExpressCheckoutPayment for the
``transactionid``. The latest version of the API does not support the
creation of an Order from `DoDirectPayment`.
The `amt` s... | python | def do_authorization(self, transactionid, amt):
"""Shortcut for the DoAuthorization method.
Use the TRANSACTIONID from DoExpressCheckoutPayment for the
``transactionid``. The latest version of the API does not support the
creation of an Order from `DoDirectPayment`.
The `amt` s... | [
"def",
"do_authorization",
"(",
"self",
",",
"transactionid",
",",
"amt",
")",
":",
"args",
"=",
"self",
".",
"_sanitize_locals",
"(",
"locals",
"(",
")",
")",
"return",
"self",
".",
"_call",
"(",
"'DoAuthorization'",
",",
"*",
"*",
"args",
")"
] | Shortcut for the DoAuthorization method.
Use the TRANSACTIONID from DoExpressCheckoutPayment for the
``transactionid``. The latest version of the API does not support the
creation of an Order from `DoDirectPayment`.
The `amt` should be the same as passed to `DoExpressCheckoutPayment`.
... | [
"Shortcut",
"for",
"the",
"DoAuthorization",
"method",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L228-L251 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.do_capture | def do_capture(self, authorizationid, amt, completetype='Complete',
**kwargs):
"""Shortcut for the DoCapture method.
Use the TRANSACTIONID from DoAuthorization, DoDirectPayment or
DoExpressCheckoutPayment for the ``authorizationid``.
The `amt` should be the same as t... | python | def do_capture(self, authorizationid, amt, completetype='Complete',
**kwargs):
"""Shortcut for the DoCapture method.
Use the TRANSACTIONID from DoAuthorization, DoDirectPayment or
DoExpressCheckoutPayment for the ``authorizationid``.
The `amt` should be the same as t... | [
"def",
"do_capture",
"(",
"self",
",",
"authorizationid",
",",
"amt",
",",
"completetype",
"=",
"'Complete'",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"update",
"(",
"self",
".",
"_sanitize_locals",
"(",
"locals",
"(",
")",
")",
")",
"return",
... | Shortcut for the DoCapture method.
Use the TRANSACTIONID from DoAuthorization, DoDirectPayment or
DoExpressCheckoutPayment for the ``authorizationid``.
The `amt` should be the same as the authorized transaction. | [
"Shortcut",
"for",
"the",
"DoCapture",
"method",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L253-L263 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.do_direct_payment | def do_direct_payment(self, paymentaction="Sale", **kwargs):
"""Shortcut for the DoDirectPayment method.
``paymentaction`` could be 'Authorization' or 'Sale'
To issue a Sale immediately::
charge = {
'amt': '10.00',
'creditcardtype': 'Visa',
... | python | def do_direct_payment(self, paymentaction="Sale", **kwargs):
"""Shortcut for the DoDirectPayment method.
``paymentaction`` could be 'Authorization' or 'Sale'
To issue a Sale immediately::
charge = {
'amt': '10.00',
'creditcardtype': 'Visa',
... | [
"def",
"do_direct_payment",
"(",
"self",
",",
"paymentaction",
"=",
"\"Sale\"",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"update",
"(",
"self",
".",
"_sanitize_locals",
"(",
"locals",
"(",
")",
")",
")",
"return",
"self",
".",
"_call",
"(",
"'... | Shortcut for the DoDirectPayment method.
``paymentaction`` could be 'Authorization' or 'Sale'
To issue a Sale immediately::
charge = {
'amt': '10.00',
'creditcardtype': 'Visa',
'acct': '4812177017895760',
'expdate': '012010',... | [
"Shortcut",
"for",
"the",
"DoDirectPayment",
"method",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L265-L302 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.transaction_search | def transaction_search(self, **kwargs):
"""Shortcut for the TransactionSearch method.
Returns a PayPalResponseList object, which merges the L_ syntax list
to a list of dictionaries with properly named keys.
Note that the API will limit returned transactions to 100.
Required Kwa... | python | def transaction_search(self, **kwargs):
"""Shortcut for the TransactionSearch method.
Returns a PayPalResponseList object, which merges the L_ syntax list
to a list of dictionaries with properly named keys.
Note that the API will limit returned transactions to 100.
Required Kwa... | [
"def",
"transaction_search",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"plain",
"=",
"self",
".",
"_call",
"(",
"'TransactionSearch'",
",",
"*",
"*",
"kwargs",
")",
"return",
"PayPalResponseList",
"(",
"plain",
".",
"raw",
",",
"self",
".",
"config... | Shortcut for the TransactionSearch method.
Returns a PayPalResponseList object, which merges the L_ syntax list
to a list of dictionaries with properly named keys.
Note that the API will limit returned transactions to 100.
Required Kwargs
---------------
* STARTDATE
... | [
"Shortcut",
"for",
"the",
"TransactionSearch",
"method",
".",
"Returns",
"a",
"PayPalResponseList",
"object",
"which",
"merges",
"the",
"L_",
"syntax",
"list",
"to",
"a",
"list",
"of",
"dictionaries",
"with",
"properly",
"named",
"keys",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L338-L355 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.refund_transaction | def refund_transaction(self, transactionid=None, payerid=None, **kwargs):
"""Shortcut for RefundTransaction method.
Note new API supports passing a PayerID instead of a transaction id,
exactly one must be provided.
Optional:
INVOICEID
REFUNDTYPE
... | python | def refund_transaction(self, transactionid=None, payerid=None, **kwargs):
"""Shortcut for RefundTransaction method.
Note new API supports passing a PayerID instead of a transaction id,
exactly one must be provided.
Optional:
INVOICEID
REFUNDTYPE
... | [
"def",
"refund_transaction",
"(",
"self",
",",
"transactionid",
"=",
"None",
",",
"payerid",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# This line seems like a complete waste of time... kwargs should not",
"# be populated",
"if",
"(",
"transactionid",
"is",
"No... | Shortcut for RefundTransaction method.
Note new API supports passing a PayerID instead of a transaction id,
exactly one must be provided.
Optional:
INVOICEID
REFUNDTYPE
AMT
CURRENCYCODE
NOTE
RETRY... | [
"Shortcut",
"for",
"RefundTransaction",
"method",
".",
"Note",
"new",
"API",
"supports",
"passing",
"a",
"PayerID",
"instead",
"of",
"a",
"transaction",
"id",
"exactly",
"one",
"must",
"be",
"provided",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L375-L412 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.generate_express_checkout_redirect_url | def generate_express_checkout_redirect_url(self, token, useraction=None):
"""Returns the URL to redirect the user to for the Express checkout.
Express Checkouts must be verified by the customer by redirecting them
to the PayPal website. Use the token returned in the response from
:meth:... | python | def generate_express_checkout_redirect_url(self, token, useraction=None):
"""Returns the URL to redirect the user to for the Express checkout.
Express Checkouts must be verified by the customer by redirecting them
to the PayPal website. Use the token returned in the response from
:meth:... | [
"def",
"generate_express_checkout_redirect_url",
"(",
"self",
",",
"token",
",",
"useraction",
"=",
"None",
")",
":",
"url_vars",
"=",
"(",
"self",
".",
"config",
".",
"PAYPAL_URL_BASE",
",",
"token",
")",
"url",
"=",
"\"%s?cmd=_express-checkout&token=%s\"",
"%",
... | Returns the URL to redirect the user to for the Express checkout.
Express Checkouts must be verified by the customer by redirecting them
to the PayPal website. Use the token returned in the response from
:meth:`set_express_checkout` with this function to figure out where
to redirect the... | [
"Returns",
"the",
"URL",
"to",
"redirect",
"the",
"user",
"to",
"for",
"the",
"Express",
"checkout",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L430-L454 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.generate_cart_upload_redirect_url | def generate_cart_upload_redirect_url(self, **kwargs):
"""https://www.sandbox.paypal.com/webscr
?cmd=_cart
&upload=1
"""
required_vals = ('business', 'item_name_1', 'amount_1', 'quantity_1')
self._check_required(required_vals, **kwargs)
url = "%s?cmd=_cart... | python | def generate_cart_upload_redirect_url(self, **kwargs):
"""https://www.sandbox.paypal.com/webscr
?cmd=_cart
&upload=1
"""
required_vals = ('business', 'item_name_1', 'amount_1', 'quantity_1')
self._check_required(required_vals, **kwargs)
url = "%s?cmd=_cart... | [
"def",
"generate_cart_upload_redirect_url",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"required_vals",
"=",
"(",
"'business'",
",",
"'item_name_1'",
",",
"'amount_1'",
",",
"'quantity_1'",
")",
"self",
".",
"_check_required",
"(",
"required_vals",
",",
"*"... | https://www.sandbox.paypal.com/webscr
?cmd=_cart
&upload=1 | [
"https",
":",
"//",
"www",
".",
"sandbox",
".",
"paypal",
".",
"com",
"/",
"webscr",
"?cmd",
"=",
"_cart",
"&upload",
"=",
"1"
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L456-L466 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.get_recurring_payments_profile_details | def get_recurring_payments_profile_details(self, profileid):
"""Shortcut for the GetRecurringPaymentsProfile method.
This returns details for a recurring payment plan. The ``profileid`` is
a value included in the response retrieved by the function
``create_recurring_payments_profile``. ... | python | def get_recurring_payments_profile_details(self, profileid):
"""Shortcut for the GetRecurringPaymentsProfile method.
This returns details for a recurring payment plan. The ``profileid`` is
a value included in the response retrieved by the function
``create_recurring_payments_profile``. ... | [
"def",
"get_recurring_payments_profile_details",
"(",
"self",
",",
"profileid",
")",
":",
"args",
"=",
"self",
".",
"_sanitize_locals",
"(",
"locals",
"(",
")",
")",
"return",
"self",
".",
"_call",
"(",
"'GetRecurringPaymentsProfileDetails'",
",",
"*",
"*",
"arg... | Shortcut for the GetRecurringPaymentsProfile method.
This returns details for a recurring payment plan. The ``profileid`` is
a value included in the response retrieved by the function
``create_recurring_payments_profile``. The profile details include the
data provided when the profile w... | [
"Shortcut",
"for",
"the",
"GetRecurringPaymentsProfile",
"method",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L468-L487 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.manage_recurring_payments_profile_status | def manage_recurring_payments_profile_status(self, profileid, action,
note=None):
"""Shortcut to the ManageRecurringPaymentsProfileStatus method.
``profileid`` is the same profile id used for getting profile details.
``action`` should be either '... | python | def manage_recurring_payments_profile_status(self, profileid, action,
note=None):
"""Shortcut to the ManageRecurringPaymentsProfileStatus method.
``profileid`` is the same profile id used for getting profile details.
``action`` should be either '... | [
"def",
"manage_recurring_payments_profile_status",
"(",
"self",
",",
"profileid",
",",
"action",
",",
"note",
"=",
"None",
")",
":",
"args",
"=",
"self",
".",
"_sanitize_locals",
"(",
"locals",
"(",
")",
")",
"if",
"not",
"note",
":",
"del",
"args",
"[",
... | Shortcut to the ManageRecurringPaymentsProfileStatus method.
``profileid`` is the same profile id used for getting profile details.
``action`` should be either 'Cancel', 'Suspend', or 'Reactivate'.
``note`` is optional and is visible to the user. It contains the
reason for the chang... | [
"Shortcut",
"to",
"the",
"ManageRecurringPaymentsProfileStatus",
"method",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L489-L501 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.update_recurring_payments_profile | def update_recurring_payments_profile(self, profileid, **kwargs):
"""Shortcut to the UpdateRecurringPaymentsProfile method.
``profileid`` is the same profile id used for getting profile details.
The keyed arguments are data in the payment profile which you wish to
change. The profileid... | python | def update_recurring_payments_profile(self, profileid, **kwargs):
"""Shortcut to the UpdateRecurringPaymentsProfile method.
``profileid`` is the same profile id used for getting profile details.
The keyed arguments are data in the payment profile which you wish to
change. The profileid... | [
"def",
"update_recurring_payments_profile",
"(",
"self",
",",
"profileid",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"update",
"(",
"self",
".",
"_sanitize_locals",
"(",
"locals",
"(",
")",
")",
")",
"return",
"self",
".",
"_call",
"(",
"'UpdateRec... | Shortcut to the UpdateRecurringPaymentsProfile method.
``profileid`` is the same profile id used for getting profile details.
The keyed arguments are data in the payment profile which you wish to
change. The profileid does not change. Anything else will take the new
value. Most of, tho... | [
"Shortcut",
"to",
"the",
"UpdateRecurringPaymentsProfile",
"method",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L503-L516 | train |
gtaylor/paypal-python | paypal/interface.py | PayPalInterface.bm_create_button | def bm_create_button(self, **kwargs):
"""Shortcut to the BMCreateButton method.
See the docs for details on arguments:
https://cms.paypal.com/mx/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_BMCreateButton
The L_BUTTONVARn fields are especially important, so make su... | python | def bm_create_button(self, **kwargs):
"""Shortcut to the BMCreateButton method.
See the docs for details on arguments:
https://cms.paypal.com/mx/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_BMCreateButton
The L_BUTTONVARn fields are especially important, so make su... | [
"def",
"bm_create_button",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"update",
"(",
"self",
".",
"_sanitize_locals",
"(",
"locals",
"(",
")",
")",
")",
"return",
"self",
".",
"_call",
"(",
"'BMCreateButton'",
",",
"*",
"*",
"kwargs... | Shortcut to the BMCreateButton method.
See the docs for details on arguments:
https://cms.paypal.com/mx/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_BMCreateButton
The L_BUTTONVARn fields are especially important, so make sure to
read those and act accordingly. See... | [
"Shortcut",
"to",
"the",
"BMCreateButton",
"method",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L518-L528 | train |
gtaylor/paypal-python | paypal/response.py | PayPalResponse.success | def success(self):
"""
Checks for the presence of errors in the response. Returns ``True`` if
all is well, ``False`` otherwise.
:rtype: bool
:returns ``True`` if PayPal says our query was successful.
"""
return self.ack.upper() in (self.config.ACK_SUCCESS,
... | python | def success(self):
"""
Checks for the presence of errors in the response. Returns ``True`` if
all is well, ``False`` otherwise.
:rtype: bool
:returns ``True`` if PayPal says our query was successful.
"""
return self.ack.upper() in (self.config.ACK_SUCCESS,
... | [
"def",
"success",
"(",
"self",
")",
":",
"return",
"self",
".",
"ack",
".",
"upper",
"(",
")",
"in",
"(",
"self",
".",
"config",
".",
"ACK_SUCCESS",
",",
"self",
".",
"config",
".",
"ACK_SUCCESS_WITH_WARNING",
")"
] | Checks for the presence of errors in the response. Returns ``True`` if
all is well, ``False`` otherwise.
:rtype: bool
:returns ``True`` if PayPal says our query was successful. | [
"Checks",
"for",
"the",
"presence",
"of",
"errors",
"in",
"the",
"response",
".",
"Returns",
"True",
"if",
"all",
"is",
"well",
"False",
"otherwise",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/response.py#L109-L118 | train |
gtaylor/paypal-python | paypal/countries.py | is_valid_country_abbrev | def is_valid_country_abbrev(abbrev, case_sensitive=False):
"""
Given a country code abbreviation, check to see if it matches the
country table.
abbrev: (str) Country code to evaluate.
case_sensitive: (bool) When True, enforce case sensitivity.
Returns True if valid, False if not.
"""
i... | python | def is_valid_country_abbrev(abbrev, case_sensitive=False):
"""
Given a country code abbreviation, check to see if it matches the
country table.
abbrev: (str) Country code to evaluate.
case_sensitive: (bool) When True, enforce case sensitivity.
Returns True if valid, False if not.
"""
i... | [
"def",
"is_valid_country_abbrev",
"(",
"abbrev",
",",
"case_sensitive",
"=",
"False",
")",
":",
"if",
"case_sensitive",
":",
"country_code",
"=",
"abbrev",
"else",
":",
"country_code",
"=",
"abbrev",
".",
"upper",
"(",
")",
"for",
"code",
",",
"full_name",
"... | Given a country code abbreviation, check to see if it matches the
country table.
abbrev: (str) Country code to evaluate.
case_sensitive: (bool) When True, enforce case sensitivity.
Returns True if valid, False if not. | [
"Given",
"a",
"country",
"code",
"abbreviation",
"check",
"to",
"see",
"if",
"it",
"matches",
"the",
"country",
"table",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/countries.py#L254-L273 | train |
gtaylor/paypal-python | paypal/countries.py | get_name_from_abbrev | def get_name_from_abbrev(abbrev, case_sensitive=False):
"""
Given a country code abbreviation, get the full name from the table.
abbrev: (str) Country code to retrieve the full name of.
case_sensitive: (bool) When True, enforce case sensitivity.
"""
if case_sensitive:
country_code = abb... | python | def get_name_from_abbrev(abbrev, case_sensitive=False):
"""
Given a country code abbreviation, get the full name from the table.
abbrev: (str) Country code to retrieve the full name of.
case_sensitive: (bool) When True, enforce case sensitivity.
"""
if case_sensitive:
country_code = abb... | [
"def",
"get_name_from_abbrev",
"(",
"abbrev",
",",
"case_sensitive",
"=",
"False",
")",
":",
"if",
"case_sensitive",
":",
"country_code",
"=",
"abbrev",
"else",
":",
"country_code",
"=",
"abbrev",
".",
"upper",
"(",
")",
"for",
"code",
",",
"full_name",
"in"... | Given a country code abbreviation, get the full name from the table.
abbrev: (str) Country code to retrieve the full name of.
case_sensitive: (bool) When True, enforce case sensitivity. | [
"Given",
"a",
"country",
"code",
"abbreviation",
"get",
"the",
"full",
"name",
"from",
"the",
"table",
"."
] | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/countries.py#L276-L292 | train |
touilleMan/marshmallow-mongoengine | marshmallow_mongoengine/schema.py | SchemaMeta.get_declared_fields | def get_declared_fields(mcs, klass, *args, **kwargs):
"""Updates declared fields with fields converted from the
Mongoengine model passed as the `model` class Meta option.
"""
declared_fields = kwargs.get('dict_class', dict)()
# Generate the fields provided through inheritance
... | python | def get_declared_fields(mcs, klass, *args, **kwargs):
"""Updates declared fields with fields converted from the
Mongoengine model passed as the `model` class Meta option.
"""
declared_fields = kwargs.get('dict_class', dict)()
# Generate the fields provided through inheritance
... | [
"def",
"get_declared_fields",
"(",
"mcs",
",",
"klass",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"declared_fields",
"=",
"kwargs",
".",
"get",
"(",
"'dict_class'",
",",
"dict",
")",
"(",
")",
"# Generate the fields provided through inheritance",
"o... | Updates declared fields with fields converted from the
Mongoengine model passed as the `model` class Meta option. | [
"Updates",
"declared",
"fields",
"with",
"fields",
"converted",
"from",
"the",
"Mongoengine",
"model",
"passed",
"as",
"the",
"model",
"class",
"Meta",
"option",
"."
] | 21223700ea1f1d0209c967761e5c22635ee721e7 | https://github.com/touilleMan/marshmallow-mongoengine/blob/21223700ea1f1d0209c967761e5c22635ee721e7/marshmallow_mongoengine/schema.py#L49-L88 | train |
touilleMan/marshmallow-mongoengine | marshmallow_mongoengine/schema.py | ModelSchema.update | def update(self, obj, data):
"""Helper function to update an already existing document
instead of creating a new one.
:param obj: Mongoengine Document to update
:param data: incomming payload to deserialize
:return: an :class UnmarshallResult:
Example: ::
from marshmallow_mongoengi... | python | def update(self, obj, data):
"""Helper function to update an already existing document
instead of creating a new one.
:param obj: Mongoengine Document to update
:param data: incomming payload to deserialize
:return: an :class UnmarshallResult:
Example: ::
from marshmallow_mongoengi... | [
"def",
"update",
"(",
"self",
",",
"obj",
",",
"data",
")",
":",
"# TODO: find a cleaner way to skip required validation on update",
"required_fields",
"=",
"[",
"k",
"for",
"k",
",",
"f",
"in",
"self",
".",
"fields",
".",
"items",
"(",
")",
"if",
"f",
".",
... | Helper function to update an already existing document
instead of creating a new one.
:param obj: Mongoengine Document to update
:param data: incomming payload to deserialize
:return: an :class UnmarshallResult:
Example: ::
from marshmallow_mongoengine import ModelSchema
from mymod... | [
"Helper",
"function",
"to",
"update",
"an",
"already",
"existing",
"document",
"instead",
"of",
"creating",
"a",
"new",
"one",
".",
":",
"param",
"obj",
":",
"Mongoengine",
"Document",
"to",
"update",
":",
"param",
"data",
":",
"incomming",
"payload",
"to",
... | 21223700ea1f1d0209c967761e5c22635ee721e7 | https://github.com/touilleMan/marshmallow-mongoengine/blob/21223700ea1f1d0209c967761e5c22635ee721e7/marshmallow_mongoengine/schema.py#L120-L160 | train |
touilleMan/marshmallow-mongoengine | marshmallow_mongoengine/conversion/fields.py | register_field | def register_field(mongo_field_cls, marshmallow_field_cls,
available_params=()):
"""
Bind a marshmallow field to it corresponding mongoengine field
:param mongo_field_cls: Mongoengine Field
:param marshmallow_field_cls: Marshmallow Field
:param available_params: List of :class mar... | python | def register_field(mongo_field_cls, marshmallow_field_cls,
available_params=()):
"""
Bind a marshmallow field to it corresponding mongoengine field
:param mongo_field_cls: Mongoengine Field
:param marshmallow_field_cls: Marshmallow Field
:param available_params: List of :class mar... | [
"def",
"register_field",
"(",
"mongo_field_cls",
",",
"marshmallow_field_cls",
",",
"available_params",
"=",
"(",
")",
")",
":",
"class",
"Builder",
"(",
"MetaFieldBuilder",
")",
":",
"AVAILABLE_PARAMS",
"=",
"available_params",
"MARSHMALLOW_FIELD_CLS",
"=",
"marshmal... | Bind a marshmallow field to it corresponding mongoengine field
:param mongo_field_cls: Mongoengine Field
:param marshmallow_field_cls: Marshmallow Field
:param available_params: List of :class marshmallow_mongoengine.cnoversion.params.MetaParam:
instances to import the mongoengine field config to ma... | [
"Bind",
"a",
"marshmallow",
"field",
"to",
"it",
"corresponding",
"mongoengine",
"field",
":",
"param",
"mongo_field_cls",
":",
"Mongoengine",
"Field",
":",
"param",
"marshmallow_field_cls",
":",
"Marshmallow",
"Field",
":",
"param",
"available_params",
":",
"List",... | 21223700ea1f1d0209c967761e5c22635ee721e7 | https://github.com/touilleMan/marshmallow-mongoengine/blob/21223700ea1f1d0209c967761e5c22635ee721e7/marshmallow_mongoengine/conversion/fields.py#L143-L155 | train |
touilleMan/marshmallow-mongoengine | marshmallow_mongoengine/conversion/fields.py | MetaFieldBuilder.build_marshmallow_field | def build_marshmallow_field(self, **kwargs):
"""
:return: The Marshmallow Field instanciated and configured
"""
field_kwargs = None
for param in self.params:
field_kwargs = param.apply(field_kwargs)
field_kwargs.update(kwargs)
return self.marshmallow_f... | python | def build_marshmallow_field(self, **kwargs):
"""
:return: The Marshmallow Field instanciated and configured
"""
field_kwargs = None
for param in self.params:
field_kwargs = param.apply(field_kwargs)
field_kwargs.update(kwargs)
return self.marshmallow_f... | [
"def",
"build_marshmallow_field",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"field_kwargs",
"=",
"None",
"for",
"param",
"in",
"self",
".",
"params",
":",
"field_kwargs",
"=",
"param",
".",
"apply",
"(",
"field_kwargs",
")",
"field_kwargs",
".",
"upd... | :return: The Marshmallow Field instanciated and configured | [
":",
"return",
":",
"The",
"Marshmallow",
"Field",
"instanciated",
"and",
"configured"
] | 21223700ea1f1d0209c967761e5c22635ee721e7 | https://github.com/touilleMan/marshmallow-mongoengine/blob/21223700ea1f1d0209c967761e5c22635ee721e7/marshmallow_mongoengine/conversion/fields.py#L25-L33 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.loop | def loop(self, timeout = 1):
"""Main loop."""
rlist = [self.sock]
wlist = []
if len(self.out_packet) > 0:
wlist.append(self.sock)
to_read, to_write, _ = select.select(rlist, wlist, [], timeout)
if len(to_read) > 0:
ret, _ = self.loop_read... | python | def loop(self, timeout = 1):
"""Main loop."""
rlist = [self.sock]
wlist = []
if len(self.out_packet) > 0:
wlist.append(self.sock)
to_read, to_write, _ = select.select(rlist, wlist, [], timeout)
if len(to_read) > 0:
ret, _ = self.loop_read... | [
"def",
"loop",
"(",
"self",
",",
"timeout",
"=",
"1",
")",
":",
"rlist",
"=",
"[",
"self",
".",
"sock",
"]",
"wlist",
"=",
"[",
"]",
"if",
"len",
"(",
"self",
".",
"out_packet",
")",
">",
"0",
":",
"wlist",
".",
"append",
"(",
"self",
".",
"s... | Main loop. | [
"Main",
"loop",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L49-L70 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.loop_misc | def loop_misc(self):
"""Misc loop."""
self.check_keepalive()
if self.last_retry_check + 1 < time.time():
pass
return NC.ERR_SUCCESS | python | def loop_misc(self):
"""Misc loop."""
self.check_keepalive()
if self.last_retry_check + 1 < time.time():
pass
return NC.ERR_SUCCESS | [
"def",
"loop_misc",
"(",
"self",
")",
":",
"self",
".",
"check_keepalive",
"(",
")",
"if",
"self",
".",
"last_retry_check",
"+",
"1",
"<",
"time",
".",
"time",
"(",
")",
":",
"pass",
"return",
"NC",
".",
"ERR_SUCCESS"
] | Misc loop. | [
"Misc",
"loop",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L82-L87 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.check_keepalive | def check_keepalive(self):
"""Send keepalive/PING if necessary."""
if self.sock != NC.INVALID_SOCKET and time.time() - self.last_msg_out >= self.keep_alive:
if self.state == NC.CS_CONNECTED:
self.send_pingreq()
else:
self.socket_close() | python | def check_keepalive(self):
"""Send keepalive/PING if necessary."""
if self.sock != NC.INVALID_SOCKET and time.time() - self.last_msg_out >= self.keep_alive:
if self.state == NC.CS_CONNECTED:
self.send_pingreq()
else:
self.socket_close() | [
"def",
"check_keepalive",
"(",
"self",
")",
":",
"if",
"self",
".",
"sock",
"!=",
"NC",
".",
"INVALID_SOCKET",
"and",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"last_msg_out",
">=",
"self",
".",
"keep_alive",
":",
"if",
"self",
".",
"state",
"... | Send keepalive/PING if necessary. | [
"Send",
"keepalive",
"/",
"PING",
"if",
"necessary",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L89-L95 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.packet_handle | def packet_handle(self):
"""Incoming packet handler dispatcher."""
cmd = self.in_packet.command & 0xF0
if cmd == NC.CMD_CONNACK:
return self.handle_connack()
elif cmd == NC.CMD_PINGRESP:
return self.handle_pingresp()
elif cmd == NC.CMD_PUBLISH:
... | python | def packet_handle(self):
"""Incoming packet handler dispatcher."""
cmd = self.in_packet.command & 0xF0
if cmd == NC.CMD_CONNACK:
return self.handle_connack()
elif cmd == NC.CMD_PINGRESP:
return self.handle_pingresp()
elif cmd == NC.CMD_PUBLISH:
... | [
"def",
"packet_handle",
"(",
"self",
")",
":",
"cmd",
"=",
"self",
".",
"in_packet",
".",
"command",
"&",
"0xF0",
"if",
"cmd",
"==",
"NC",
".",
"CMD_CONNACK",
":",
"return",
"self",
".",
"handle_connack",
"(",
")",
"elif",
"cmd",
"==",
"NC",
".",
"CM... | Incoming packet handler dispatcher. | [
"Incoming",
"packet",
"handler",
"dispatcher",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L97-L126 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.connect | def connect(self, version = 3, clean_session = 1, will = None):
"""Connect to server."""
self.clean_session = clean_session
self.will = None
if will is not None:
self.will = NyamukMsg(
topic = will['topic'],
# unicode text nee... | python | def connect(self, version = 3, clean_session = 1, will = None):
"""Connect to server."""
self.clean_session = clean_session
self.will = None
if will is not None:
self.will = NyamukMsg(
topic = will['topic'],
# unicode text nee... | [
"def",
"connect",
"(",
"self",
",",
"version",
"=",
"3",
",",
"clean_session",
"=",
"1",
",",
"will",
"=",
"None",
")",
":",
"self",
".",
"clean_session",
"=",
"clean_session",
"self",
".",
"will",
"=",
"None",
"if",
"will",
"is",
"not",
"None",
":",... | Connect to server. | [
"Connect",
"to",
"server",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L132-L180 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.disconnect | def disconnect(self):
"""Disconnect from server."""
self.logger.info("DISCONNECT")
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.state = NC.CS_DISCONNECTING
ret = self.send_disconnect()
ret2, bytes_written = self.packet_write()
... | python | def disconnect(self):
"""Disconnect from server."""
self.logger.info("DISCONNECT")
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.state = NC.CS_DISCONNECTING
ret = self.send_disconnect()
ret2, bytes_written = self.packet_write()
... | [
"def",
"disconnect",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"DISCONNECT\"",
")",
"if",
"self",
".",
"sock",
"==",
"NC",
".",
"INVALID_SOCKET",
":",
"return",
"NC",
".",
"ERR_NO_CONN",
"self",
".",
"state",
"=",
"NC",
".",
"... | Disconnect from server. | [
"Disconnect",
"from",
"server",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L182-L193 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.subscribe | def subscribe(self, topic, qos):
"""Subscribe to some topic."""
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.logger.info("SUBSCRIBE: %s", topic)
return self.send_subscribe(False, [(utf8encode(topic), qos)]) | python | def subscribe(self, topic, qos):
"""Subscribe to some topic."""
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.logger.info("SUBSCRIBE: %s", topic)
return self.send_subscribe(False, [(utf8encode(topic), qos)]) | [
"def",
"subscribe",
"(",
"self",
",",
"topic",
",",
"qos",
")",
":",
"if",
"self",
".",
"sock",
"==",
"NC",
".",
"INVALID_SOCKET",
":",
"return",
"NC",
".",
"ERR_NO_CONN",
"self",
".",
"logger",
".",
"info",
"(",
"\"SUBSCRIBE: %s\"",
",",
"topic",
")",... | Subscribe to some topic. | [
"Subscribe",
"to",
"some",
"topic",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L195-L201 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.subscribe_multi | def subscribe_multi(self, topics):
"""Subscribe to some topics."""
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.logger.info("SUBSCRIBE: %s", ', '.join([t for (t,q) in topics]))
return self.send_subscribe(False, [(utf8encode(topic), qos) for (topic, q... | python | def subscribe_multi(self, topics):
"""Subscribe to some topics."""
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.logger.info("SUBSCRIBE: %s", ', '.join([t for (t,q) in topics]))
return self.send_subscribe(False, [(utf8encode(topic), qos) for (topic, q... | [
"def",
"subscribe_multi",
"(",
"self",
",",
"topics",
")",
":",
"if",
"self",
".",
"sock",
"==",
"NC",
".",
"INVALID_SOCKET",
":",
"return",
"NC",
".",
"ERR_NO_CONN",
"self",
".",
"logger",
".",
"info",
"(",
"\"SUBSCRIBE: %s\"",
",",
"', '",
".",
"join",... | Subscribe to some topics. | [
"Subscribe",
"to",
"some",
"topics",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L204-L210 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.unsubscribe | def unsubscribe(self, topic):
"""Unsubscribe to some topic."""
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.logger.info("UNSUBSCRIBE: %s", topic)
return self.send_unsubscribe(False, [utf8encode(topic)]) | python | def unsubscribe(self, topic):
"""Unsubscribe to some topic."""
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.logger.info("UNSUBSCRIBE: %s", topic)
return self.send_unsubscribe(False, [utf8encode(topic)]) | [
"def",
"unsubscribe",
"(",
"self",
",",
"topic",
")",
":",
"if",
"self",
".",
"sock",
"==",
"NC",
".",
"INVALID_SOCKET",
":",
"return",
"NC",
".",
"ERR_NO_CONN",
"self",
".",
"logger",
".",
"info",
"(",
"\"UNSUBSCRIBE: %s\"",
",",
"topic",
")",
"return",... | Unsubscribe to some topic. | [
"Unsubscribe",
"to",
"some",
"topic",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L212-L218 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.unsubscribe_multi | def unsubscribe_multi(self, topics):
"""Unsubscribe to some topics."""
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.logger.info("UNSUBSCRIBE: %s", ', '.join(topics))
return self.send_unsubscribe(False, [utf8encode(topic) for topic in topics]) | python | def unsubscribe_multi(self, topics):
"""Unsubscribe to some topics."""
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.logger.info("UNSUBSCRIBE: %s", ', '.join(topics))
return self.send_unsubscribe(False, [utf8encode(topic) for topic in topics]) | [
"def",
"unsubscribe_multi",
"(",
"self",
",",
"topics",
")",
":",
"if",
"self",
".",
"sock",
"==",
"NC",
".",
"INVALID_SOCKET",
":",
"return",
"NC",
".",
"ERR_NO_CONN",
"self",
".",
"logger",
".",
"info",
"(",
"\"UNSUBSCRIBE: %s\"",
",",
"', '",
".",
"jo... | Unsubscribe to some topics. | [
"Unsubscribe",
"to",
"some",
"topics",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L220-L226 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.send_subscribe | def send_subscribe(self, dup, topics):
"""Send subscribe COMMAND to server."""
pkt = MqttPkt()
pktlen = 2 + sum([2+len(topic)+1 for (topic, qos) in topics])
pkt.command = NC.CMD_SUBSCRIBE | (dup << 3) | (1 << 1)
pkt.remaining_length = pktlen
ret = pkt.al... | python | def send_subscribe(self, dup, topics):
"""Send subscribe COMMAND to server."""
pkt = MqttPkt()
pktlen = 2 + sum([2+len(topic)+1 for (topic, qos) in topics])
pkt.command = NC.CMD_SUBSCRIBE | (dup << 3) | (1 << 1)
pkt.remaining_length = pktlen
ret = pkt.al... | [
"def",
"send_subscribe",
"(",
"self",
",",
"dup",
",",
"topics",
")",
":",
"pkt",
"=",
"MqttPkt",
"(",
")",
"pktlen",
"=",
"2",
"+",
"sum",
"(",
"[",
"2",
"+",
"len",
"(",
"topic",
")",
"+",
"1",
"for",
"(",
"topic",
",",
"qos",
")",
"in",
"t... | Send subscribe COMMAND to server. | [
"Send",
"subscribe",
"COMMAND",
"to",
"server",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L233-L254 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.send_unsubscribe | def send_unsubscribe(self, dup, topics):
"""Send unsubscribe COMMAND to server."""
pkt = MqttPkt()
pktlen = 2 + sum([2+len(topic) for topic in topics])
pkt.command = NC.CMD_UNSUBSCRIBE | (dup << 3) | (1 << 1)
pkt.remaining_length = pktlen
ret = pkt.alloc... | python | def send_unsubscribe(self, dup, topics):
"""Send unsubscribe COMMAND to server."""
pkt = MqttPkt()
pktlen = 2 + sum([2+len(topic) for topic in topics])
pkt.command = NC.CMD_UNSUBSCRIBE | (dup << 3) | (1 << 1)
pkt.remaining_length = pktlen
ret = pkt.alloc... | [
"def",
"send_unsubscribe",
"(",
"self",
",",
"dup",
",",
"topics",
")",
":",
"pkt",
"=",
"MqttPkt",
"(",
")",
"pktlen",
"=",
"2",
"+",
"sum",
"(",
"[",
"2",
"+",
"len",
"(",
"topic",
")",
"for",
"topic",
"in",
"topics",
"]",
")",
"pkt",
".",
"c... | Send unsubscribe COMMAND to server. | [
"Send",
"unsubscribe",
"COMMAND",
"to",
"server",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L256-L276 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.publish | def publish(self, topic, payload = None, qos = 0, retain = False):
"""Publish some payload to server."""
#print "PUBLISHING (",topic,"): ", payload
payloadlen = len(payload)
if topic is None or qos < 0 or qos > 2:
print "PUBLISH:err inval"
return NC.ERR_INVAL
... | python | def publish(self, topic, payload = None, qos = 0, retain = False):
"""Publish some payload to server."""
#print "PUBLISHING (",topic,"): ", payload
payloadlen = len(payload)
if topic is None or qos < 0 or qos > 2:
print "PUBLISH:err inval"
return NC.ERR_INVAL
... | [
"def",
"publish",
"(",
"self",
",",
"topic",
",",
"payload",
"=",
"None",
",",
"qos",
"=",
"0",
",",
"retain",
"=",
"False",
")",
":",
"#print \"PUBLISHING (\",topic,\"): \", payload",
"payloadlen",
"=",
"len",
"(",
"payload",
")",
"if",
"topic",
"is",
"No... | Publish some payload to server. | [
"Publish",
"some",
"payload",
"to",
"server",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L278-L300 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.handle_connack | def handle_connack(self):
"""Handle incoming CONNACK command."""
self.logger.info("CONNACK reveived")
ret, flags = self.in_packet.read_byte()
if ret != NC.ERR_SUCCESS:
self.logger.error("error read byte")
return ret
# useful for v3.1.1 only
... | python | def handle_connack(self):
"""Handle incoming CONNACK command."""
self.logger.info("CONNACK reveived")
ret, flags = self.in_packet.read_byte()
if ret != NC.ERR_SUCCESS:
self.logger.error("error read byte")
return ret
# useful for v3.1.1 only
... | [
"def",
"handle_connack",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"CONNACK reveived\"",
")",
"ret",
",",
"flags",
"=",
"self",
".",
"in_packet",
".",
"read_byte",
"(",
")",
"if",
"ret",
"!=",
"NC",
".",
"ERR_SUCCESS",
":",
"sel... | Handle incoming CONNACK command. | [
"Handle",
"incoming",
"CONNACK",
"command",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L302-L327 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.handle_pingresp | def handle_pingresp(self):
"""Handle incoming PINGRESP packet."""
self.logger.debug("PINGRESP received")
self.push_event(event.EventPingResp())
return NC.ERR_SUCCESS | python | def handle_pingresp(self):
"""Handle incoming PINGRESP packet."""
self.logger.debug("PINGRESP received")
self.push_event(event.EventPingResp())
return NC.ERR_SUCCESS | [
"def",
"handle_pingresp",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"\"PINGRESP received\"",
")",
"self",
".",
"push_event",
"(",
"event",
".",
"EventPingResp",
"(",
")",
")",
"return",
"NC",
".",
"ERR_SUCCESS"
] | Handle incoming PINGRESP packet. | [
"Handle",
"incoming",
"PINGRESP",
"packet",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L329-L333 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.handle_suback | def handle_suback(self):
"""Handle incoming SUBACK packet."""
self.logger.info("SUBACK received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
qos_count = self.in_packet.remaining_length - self.in_packet.pos
... | python | def handle_suback(self):
"""Handle incoming SUBACK packet."""
self.logger.info("SUBACK received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
qos_count = self.in_packet.remaining_length - self.in_packet.pos
... | [
"def",
"handle_suback",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"SUBACK received\"",
")",
"ret",
",",
"mid",
"=",
"self",
".",
"in_packet",
".",
"read_uint16",
"(",
")",
"if",
"ret",
"!=",
"NC",
".",
"ERR_SUCCESS",
":",
"retur... | Handle incoming SUBACK packet. | [
"Handle",
"incoming",
"SUBACK",
"packet",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L335-L367 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.handle_unsuback | def handle_unsuback(self):
"""Handle incoming UNSUBACK packet."""
self.logger.info("UNSUBACK received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
evt = event.EventUnsuback(mid)
self.push_event(evt)
return NC.ERR_S... | python | def handle_unsuback(self):
"""Handle incoming UNSUBACK packet."""
self.logger.info("UNSUBACK received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
evt = event.EventUnsuback(mid)
self.push_event(evt)
return NC.ERR_S... | [
"def",
"handle_unsuback",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"UNSUBACK received\"",
")",
"ret",
",",
"mid",
"=",
"self",
".",
"in_packet",
".",
"read_uint16",
"(",
")",
"if",
"ret",
"!=",
"NC",
".",
"ERR_SUCCESS",
":",
"r... | Handle incoming UNSUBACK packet. | [
"Handle",
"incoming",
"UNSUBACK",
"packet",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L369-L381 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.handle_publish | def handle_publish(self):
"""Handle incoming PUBLISH packet."""
self.logger.debug("PUBLISH received")
header = self.in_packet.command
message = NyamukMsgAll()
message.direction = NC.DIRECTION_IN
message.dup = (header & 0x08) >> 3
message.msg.qos ... | python | def handle_publish(self):
"""Handle incoming PUBLISH packet."""
self.logger.debug("PUBLISH received")
header = self.in_packet.command
message = NyamukMsgAll()
message.direction = NC.DIRECTION_IN
message.dup = (header & 0x08) >> 3
message.msg.qos ... | [
"def",
"handle_publish",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"\"PUBLISH received\"",
")",
"header",
"=",
"self",
".",
"in_packet",
".",
"command",
"message",
"=",
"NyamukMsgAll",
"(",
")",
"message",
".",
"direction",
"=",
"NC"... | Handle incoming PUBLISH packet. | [
"Handle",
"incoming",
"PUBLISH",
"packet",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L388-L436 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.send_publish | def send_publish(self, mid, topic, payload, qos, retain, dup):
"""Send PUBLISH."""
self.logger.debug("Send PUBLISH")
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
#NOTE: payload may be any kind of data
# yet if it is a unicode string we utf8-encode it... | python | def send_publish(self, mid, topic, payload, qos, retain, dup):
"""Send PUBLISH."""
self.logger.debug("Send PUBLISH")
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
#NOTE: payload may be any kind of data
# yet if it is a unicode string we utf8-encode it... | [
"def",
"send_publish",
"(",
"self",
",",
"mid",
",",
"topic",
",",
"payload",
",",
"qos",
",",
"retain",
",",
"dup",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"\"Send PUBLISH\"",
")",
"if",
"self",
".",
"sock",
"==",
"NC",
".",
"INVALID_SOC... | Send PUBLISH. | [
"Send",
"PUBLISH",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L438-L446 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.handle_puback | def handle_puback(self):
"""Handle incoming PUBACK packet."""
self.logger.info("PUBACK received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
evt = event.EventPuback(mid)
self.push_event(evt)
return NC.ERR_SUCCESS | python | def handle_puback(self):
"""Handle incoming PUBACK packet."""
self.logger.info("PUBACK received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
evt = event.EventPuback(mid)
self.push_event(evt)
return NC.ERR_SUCCESS | [
"def",
"handle_puback",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"PUBACK received\"",
")",
"ret",
",",
"mid",
"=",
"self",
".",
"in_packet",
".",
"read_uint16",
"(",
")",
"if",
"ret",
"!=",
"NC",
".",
"ERR_SUCCESS",
":",
"retur... | Handle incoming PUBACK packet. | [
"Handle",
"incoming",
"PUBACK",
"packet",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L455-L467 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.handle_pubrec | def handle_pubrec(self):
"""Handle incoming PUBREC packet."""
self.logger.info("PUBREC received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
evt = event.EventPubrec(mid)
self.push_event(evt)
return NC.ERR_SUCCESS | python | def handle_pubrec(self):
"""Handle incoming PUBREC packet."""
self.logger.info("PUBREC received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
evt = event.EventPubrec(mid)
self.push_event(evt)
return NC.ERR_SUCCESS | [
"def",
"handle_pubrec",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"PUBREC received\"",
")",
"ret",
",",
"mid",
"=",
"self",
".",
"in_packet",
".",
"read_uint16",
"(",
")",
"if",
"ret",
"!=",
"NC",
".",
"ERR_SUCCESS",
":",
"retur... | Handle incoming PUBREC packet. | [
"Handle",
"incoming",
"PUBREC",
"packet",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L469-L481 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.handle_pubrel | def handle_pubrel(self):
"""Handle incoming PUBREL packet."""
self.logger.info("PUBREL received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
evt = event.EventPubrel(mid)
self.push_event(evt)
return NC.ERR_SUCCESS | python | def handle_pubrel(self):
"""Handle incoming PUBREL packet."""
self.logger.info("PUBREL received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
evt = event.EventPubrel(mid)
self.push_event(evt)
return NC.ERR_SUCCESS | [
"def",
"handle_pubrel",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"PUBREL received\"",
")",
"ret",
",",
"mid",
"=",
"self",
".",
"in_packet",
".",
"read_uint16",
"(",
")",
"if",
"ret",
"!=",
"NC",
".",
"ERR_SUCCESS",
":",
"retur... | Handle incoming PUBREL packet. | [
"Handle",
"incoming",
"PUBREL",
"packet",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L483-L495 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.handle_pubcomp | def handle_pubcomp(self):
"""Handle incoming PUBCOMP packet."""
self.logger.info("PUBCOMP received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
evt = event.EventPubcomp(mid)
self.push_event(evt)
return NC.ERR_SUCCE... | python | def handle_pubcomp(self):
"""Handle incoming PUBCOMP packet."""
self.logger.info("PUBCOMP received")
ret, mid = self.in_packet.read_uint16()
if ret != NC.ERR_SUCCESS:
return ret
evt = event.EventPubcomp(mid)
self.push_event(evt)
return NC.ERR_SUCCE... | [
"def",
"handle_pubcomp",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"PUBCOMP received\"",
")",
"ret",
",",
"mid",
"=",
"self",
".",
"in_packet",
".",
"read_uint16",
"(",
")",
"if",
"ret",
"!=",
"NC",
".",
"ERR_SUCCESS",
":",
"ret... | Handle incoming PUBCOMP packet. | [
"Handle",
"incoming",
"PUBCOMP",
"packet",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L497-L509 | train |
iwanbk/nyamuk | nyamuk/nyamuk.py | Nyamuk.pubrec | def pubrec(self, mid):
"""Send PUBREC response to server."""
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.logger.info("Send PUBREC (msgid=%s)", mid)
pkt = MqttPkt()
pkt.command = NC.CMD_PUBREC
pkt.remaining_length = 2
ret = pkt.allo... | python | def pubrec(self, mid):
"""Send PUBREC response to server."""
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.logger.info("Send PUBREC (msgid=%s)", mid)
pkt = MqttPkt()
pkt.command = NC.CMD_PUBREC
pkt.remaining_length = 2
ret = pkt.allo... | [
"def",
"pubrec",
"(",
"self",
",",
"mid",
")",
":",
"if",
"self",
".",
"sock",
"==",
"NC",
".",
"INVALID_SOCKET",
":",
"return",
"NC",
".",
"ERR_NO_CONN",
"self",
".",
"logger",
".",
"info",
"(",
"\"Send PUBREC (msgid=%s)\"",
",",
"mid",
")",
"pkt",
"=... | Send PUBREC response to server. | [
"Send",
"PUBREC",
"response",
"to",
"server",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk.py#L552-L570 | train |
iwanbk/nyamuk | nyamuk/nyamuk_net.py | connect | def connect(sock, addr):
"""Connect to some addr."""
try:
sock.connect(addr)
except ssl.SSLError as e:
return (ssl.SSLError, e.strerror if e.strerror else e.message)
except socket.herror as (_, msg):
return (socket.herror, msg)
except socket.gaierror as (_, msg):
retu... | python | def connect(sock, addr):
"""Connect to some addr."""
try:
sock.connect(addr)
except ssl.SSLError as e:
return (ssl.SSLError, e.strerror if e.strerror else e.message)
except socket.herror as (_, msg):
return (socket.herror, msg)
except socket.gaierror as (_, msg):
retu... | [
"def",
"connect",
"(",
"sock",
",",
"addr",
")",
":",
"try",
":",
"sock",
".",
"connect",
"(",
"addr",
")",
"except",
"ssl",
".",
"SSLError",
"as",
"e",
":",
"return",
"(",
"ssl",
".",
"SSLError",
",",
"e",
".",
"strerror",
"if",
"e",
".",
"strer... | Connect to some addr. | [
"Connect",
"to",
"some",
"addr",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk_net.py#L17-L32 | train |
iwanbk/nyamuk | nyamuk/nyamuk_net.py | read | def read(sock, count):
"""Read from socket and return it's byte array representation.
count = number of bytes to read
"""
data = None
try:
data = sock.recv(count)
except ssl.SSLError as e:
return data, e.errno, e.strerror if strerror else e.message
except socket.herror as (e... | python | def read(sock, count):
"""Read from socket and return it's byte array representation.
count = number of bytes to read
"""
data = None
try:
data = sock.recv(count)
except ssl.SSLError as e:
return data, e.errno, e.strerror if strerror else e.message
except socket.herror as (e... | [
"def",
"read",
"(",
"sock",
",",
"count",
")",
":",
"data",
"=",
"None",
"try",
":",
"data",
"=",
"sock",
".",
"recv",
"(",
"count",
")",
"except",
"ssl",
".",
"SSLError",
"as",
"e",
":",
"return",
"data",
",",
"e",
".",
"errno",
",",
"e",
".",... | Read from socket and return it's byte array representation.
count = number of bytes to read | [
"Read",
"from",
"socket",
"and",
"return",
"it",
"s",
"byte",
"array",
"representation",
".",
"count",
"=",
"number",
"of",
"bytes",
"to",
"read"
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk_net.py#L34-L58 | train |
iwanbk/nyamuk | nyamuk/nyamuk_net.py | write | def write(sock, payload):
"""Write payload to socket."""
try:
length = sock.send(payload)
except ssl.SSLError as e:
return -1, (ssl.SSLError, e.strerror if strerror else e.message)
except socket.herror as (_, msg):
return -1, (socket.error, msg)
except socket.gaierror as (_, ... | python | def write(sock, payload):
"""Write payload to socket."""
try:
length = sock.send(payload)
except ssl.SSLError as e:
return -1, (ssl.SSLError, e.strerror if strerror else e.message)
except socket.herror as (_, msg):
return -1, (socket.error, msg)
except socket.gaierror as (_, ... | [
"def",
"write",
"(",
"sock",
",",
"payload",
")",
":",
"try",
":",
"length",
"=",
"sock",
".",
"send",
"(",
"payload",
")",
"except",
"ssl",
".",
"SSLError",
"as",
"e",
":",
"return",
"-",
"1",
",",
"(",
"ssl",
".",
"SSLError",
",",
"e",
".",
"... | Write payload to socket. | [
"Write",
"payload",
"to",
"socket",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/nyamuk_net.py#L60-L75 | train |
iwanbk/nyamuk | nyamuk/mqtt_pkt.py | MqttPkt.dump | def dump(self):
"""Print packet content."""
print "-----MqttPkt------"
print "command = ", self.command
print "have_remaining = ", self.have_remaining
print "remaining_count = ", self.remaining_count
print "mid = ", self.mid
print "remaining_mult = ", self.remaini... | python | def dump(self):
"""Print packet content."""
print "-----MqttPkt------"
print "command = ", self.command
print "have_remaining = ", self.have_remaining
print "remaining_count = ", self.remaining_count
print "mid = ", self.mid
print "remaining_mult = ", self.remaini... | [
"def",
"dump",
"(",
"self",
")",
":",
"print",
"\"-----MqttPkt------\"",
"print",
"\"command = \"",
",",
"self",
".",
"command",
"print",
"\"have_remaining = \"",
",",
"self",
".",
"have_remaining",
"print",
"\"remaining_count = \"",
",",
"self",
".",
"remaining_cou... | Print packet content. | [
"Print",
"packet",
"content",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/mqtt_pkt.py#L32-L45 | train |
iwanbk/nyamuk | nyamuk/mqtt_pkt.py | MqttPkt.alloc | def alloc(self):
"""from _mosquitto_packet_alloc."""
byte = 0
remaining_bytes = bytearray(5)
i = 0
remaining_length = self.remaining_length
self.payload = None
self.remaining_count = 0
loop_flag = True
#self.dump()
... | python | def alloc(self):
"""from _mosquitto_packet_alloc."""
byte = 0
remaining_bytes = bytearray(5)
i = 0
remaining_length = self.remaining_length
self.payload = None
self.remaining_count = 0
loop_flag = True
#self.dump()
... | [
"def",
"alloc",
"(",
"self",
")",
":",
"byte",
"=",
"0",
"remaining_bytes",
"=",
"bytearray",
"(",
"5",
")",
"i",
"=",
"0",
"remaining_length",
"=",
"self",
".",
"remaining_length",
"self",
".",
"payload",
"=",
"None",
"self",
".",
"remaining_count",
"="... | from _mosquitto_packet_alloc. | [
"from",
"_mosquitto_packet_alloc",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/mqtt_pkt.py#L47-L88 | train |
iwanbk/nyamuk | nyamuk/mqtt_pkt.py | MqttPkt.connect_build | def connect_build(self, nyamuk, keepalive, clean_session, retain = 0, dup = 0, version = 3):
"""Build packet for CONNECT command."""
will = 0; will_topic = None
byte = 0
client_id = utf8encode(nyamuk.client_id)
username = utf8encode(nyamuk.username) if nyamuk.username is not No... | python | def connect_build(self, nyamuk, keepalive, clean_session, retain = 0, dup = 0, version = 3):
"""Build packet for CONNECT command."""
will = 0; will_topic = None
byte = 0
client_id = utf8encode(nyamuk.client_id)
username = utf8encode(nyamuk.username) if nyamuk.username is not No... | [
"def",
"connect_build",
"(",
"self",
",",
"nyamuk",
",",
"keepalive",
",",
"clean_session",
",",
"retain",
"=",
"0",
",",
"dup",
"=",
"0",
",",
"version",
"=",
"3",
")",
":",
"will",
"=",
"0",
"will_topic",
"=",
"None",
"byte",
"=",
"0",
"client_id",... | Build packet for CONNECT command. | [
"Build",
"packet",
"for",
"CONNECT",
"command",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/mqtt_pkt.py#L100-L159 | train |
iwanbk/nyamuk | nyamuk/mqtt_pkt.py | MqttPkt.write_string | def write_string(self, string):
"""Write a string to this packet."""
self.write_uint16(len(string))
self.write_bytes(string, len(string)) | python | def write_string(self, string):
"""Write a string to this packet."""
self.write_uint16(len(string))
self.write_bytes(string, len(string)) | [
"def",
"write_string",
"(",
"self",
",",
"string",
")",
":",
"self",
".",
"write_uint16",
"(",
"len",
"(",
"string",
")",
")",
"self",
".",
"write_bytes",
"(",
"string",
",",
"len",
"(",
"string",
")",
")"
] | Write a string to this packet. | [
"Write",
"a",
"string",
"to",
"this",
"packet",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/mqtt_pkt.py#L161-L164 | train |
iwanbk/nyamuk | nyamuk/mqtt_pkt.py | MqttPkt.write_uint16 | def write_uint16(self, word):
"""Write 2 bytes."""
self.write_byte(nyamuk_net.MOSQ_MSB(word))
self.write_byte(nyamuk_net.MOSQ_LSB(word)) | python | def write_uint16(self, word):
"""Write 2 bytes."""
self.write_byte(nyamuk_net.MOSQ_MSB(word))
self.write_byte(nyamuk_net.MOSQ_LSB(word)) | [
"def",
"write_uint16",
"(",
"self",
",",
"word",
")",
":",
"self",
".",
"write_byte",
"(",
"nyamuk_net",
".",
"MOSQ_MSB",
"(",
"word",
")",
")",
"self",
".",
"write_byte",
"(",
"nyamuk_net",
".",
"MOSQ_LSB",
"(",
"word",
")",
")"
] | Write 2 bytes. | [
"Write",
"2",
"bytes",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/mqtt_pkt.py#L166-L169 | train |
iwanbk/nyamuk | nyamuk/mqtt_pkt.py | MqttPkt.write_byte | def write_byte(self, byte):
"""Write one byte."""
self.payload[self.pos] = byte
self.pos = self.pos + 1 | python | def write_byte(self, byte):
"""Write one byte."""
self.payload[self.pos] = byte
self.pos = self.pos + 1 | [
"def",
"write_byte",
"(",
"self",
",",
"byte",
")",
":",
"self",
".",
"payload",
"[",
"self",
".",
"pos",
"]",
"=",
"byte",
"self",
".",
"pos",
"=",
"self",
".",
"pos",
"+",
"1"
] | Write one byte. | [
"Write",
"one",
"byte",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/mqtt_pkt.py#L171-L174 | train |
iwanbk/nyamuk | nyamuk/mqtt_pkt.py | MqttPkt.write_bytes | def write_bytes(self, data, n):
"""Write n number of bytes to this packet."""
for pos in xrange(0, n):
self.payload[self.pos + pos] = data[pos]
self.pos += n | python | def write_bytes(self, data, n):
"""Write n number of bytes to this packet."""
for pos in xrange(0, n):
self.payload[self.pos + pos] = data[pos]
self.pos += n | [
"def",
"write_bytes",
"(",
"self",
",",
"data",
",",
"n",
")",
":",
"for",
"pos",
"in",
"xrange",
"(",
"0",
",",
"n",
")",
":",
"self",
".",
"payload",
"[",
"self",
".",
"pos",
"+",
"pos",
"]",
"=",
"data",
"[",
"pos",
"]",
"self",
".",
"pos"... | Write n number of bytes to this packet. | [
"Write",
"n",
"number",
"of",
"bytes",
"to",
"this",
"packet",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/mqtt_pkt.py#L176-L181 | train |
iwanbk/nyamuk | nyamuk/mqtt_pkt.py | MqttPkt.read_byte | def read_byte(self):
"""Read a byte."""
if self.pos + 1 > self.remaining_length:
return NC.ERR_PROTOCOL, None
byte = self.payload[self.pos]
self.pos += 1
return NC.ERR_SUCCESS, byte | python | def read_byte(self):
"""Read a byte."""
if self.pos + 1 > self.remaining_length:
return NC.ERR_PROTOCOL, None
byte = self.payload[self.pos]
self.pos += 1
return NC.ERR_SUCCESS, byte | [
"def",
"read_byte",
"(",
"self",
")",
":",
"if",
"self",
".",
"pos",
"+",
"1",
">",
"self",
".",
"remaining_length",
":",
"return",
"NC",
".",
"ERR_PROTOCOL",
",",
"None",
"byte",
"=",
"self",
".",
"payload",
"[",
"self",
".",
"pos",
"]",
"self",
"... | Read a byte. | [
"Read",
"a",
"byte",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/mqtt_pkt.py#L183-L191 | train |
iwanbk/nyamuk | nyamuk/mqtt_pkt.py | MqttPkt.read_uint16 | def read_uint16(self):
"""Read 2 bytes."""
if self.pos + 2 > self.remaining_length:
return NC.ERR_PROTOCOL
msb = self.payload[self.pos]
self.pos += 1
lsb = self.payload[self.pos]
self.pos += 1
word = (msb << 8) + lsb
return NC... | python | def read_uint16(self):
"""Read 2 bytes."""
if self.pos + 2 > self.remaining_length:
return NC.ERR_PROTOCOL
msb = self.payload[self.pos]
self.pos += 1
lsb = self.payload[self.pos]
self.pos += 1
word = (msb << 8) + lsb
return NC... | [
"def",
"read_uint16",
"(",
"self",
")",
":",
"if",
"self",
".",
"pos",
"+",
"2",
">",
"self",
".",
"remaining_length",
":",
"return",
"NC",
".",
"ERR_PROTOCOL",
"msb",
"=",
"self",
".",
"payload",
"[",
"self",
".",
"pos",
"]",
"self",
".",
"pos",
"... | Read 2 bytes. | [
"Read",
"2",
"bytes",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/mqtt_pkt.py#L193-L204 | train |
iwanbk/nyamuk | nyamuk/mqtt_pkt.py | MqttPkt.read_bytes | def read_bytes(self, count):
"""Read count number of bytes."""
if self.pos + count > self.remaining_length:
return NC.ERR_PROTOCOL, None
ba = bytearray(count)
for x in xrange(0, count):
ba[x] = self.payload[self.pos]
self.pos += 1
... | python | def read_bytes(self, count):
"""Read count number of bytes."""
if self.pos + count > self.remaining_length:
return NC.ERR_PROTOCOL, None
ba = bytearray(count)
for x in xrange(0, count):
ba[x] = self.payload[self.pos]
self.pos += 1
... | [
"def",
"read_bytes",
"(",
"self",
",",
"count",
")",
":",
"if",
"self",
".",
"pos",
"+",
"count",
">",
"self",
".",
"remaining_length",
":",
"return",
"NC",
".",
"ERR_PROTOCOL",
",",
"None",
"ba",
"=",
"bytearray",
"(",
"count",
")",
"for",
"x",
"in"... | Read count number of bytes. | [
"Read",
"count",
"number",
"of",
"bytes",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/mqtt_pkt.py#L206-L216 | train |
iwanbk/nyamuk | nyamuk/mqtt_pkt.py | MqttPkt.read_string | def read_string(self):
"""Read string."""
rc, length = self.read_uint16()
if rc != NC.ERR_SUCCESS:
return rc, None
if self.pos + length > self.remaining_length:
return NC.ERR_PROTOCOL, None
ba = bytearray(length)
if ba is... | python | def read_string(self):
"""Read string."""
rc, length = self.read_uint16()
if rc != NC.ERR_SUCCESS:
return rc, None
if self.pos + length > self.remaining_length:
return NC.ERR_PROTOCOL, None
ba = bytearray(length)
if ba is... | [
"def",
"read_string",
"(",
"self",
")",
":",
"rc",
",",
"length",
"=",
"self",
".",
"read_uint16",
"(",
")",
"if",
"rc",
"!=",
"NC",
".",
"ERR_SUCCESS",
":",
"return",
"rc",
",",
"None",
"if",
"self",
".",
"pos",
"+",
"length",
">",
"self",
".",
... | Read string. | [
"Read",
"string",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/mqtt_pkt.py#L218-L236 | train |
iwanbk/nyamuk | nyamuk/base_nyamuk.py | BaseNyamuk.pop_event | def pop_event(self):
"""Pop an event from event_list."""
if len(self.event_list) > 0:
evt = self.event_list.pop(0)
return evt
return None | python | def pop_event(self):
"""Pop an event from event_list."""
if len(self.event_list) > 0:
evt = self.event_list.pop(0)
return evt
return None | [
"def",
"pop_event",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"event_list",
")",
">",
"0",
":",
"evt",
"=",
"self",
".",
"event_list",
".",
"pop",
"(",
"0",
")",
"return",
"evt",
"return",
"None"
] | Pop an event from event_list. | [
"Pop",
"an",
"event",
"from",
"event_list",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/base_nyamuk.py#L66-L71 | train |
iwanbk/nyamuk | nyamuk/base_nyamuk.py | BaseNyamuk.mid_generate | def mid_generate(self):
"""Generate mid. TODO : check."""
self.last_mid += 1
if self.last_mid == 0:
self.last_mid += 1
return self.last_mid | python | def mid_generate(self):
"""Generate mid. TODO : check."""
self.last_mid += 1
if self.last_mid == 0:
self.last_mid += 1
return self.last_mid | [
"def",
"mid_generate",
"(",
"self",
")",
":",
"self",
".",
"last_mid",
"+=",
"1",
"if",
"self",
".",
"last_mid",
"==",
"0",
":",
"self",
".",
"last_mid",
"+=",
"1",
"return",
"self",
".",
"last_mid"
] | Generate mid. TODO : check. | [
"Generate",
"mid",
".",
"TODO",
":",
"check",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/base_nyamuk.py#L77-L82 | train |
iwanbk/nyamuk | nyamuk/base_nyamuk.py | BaseNyamuk.packet_queue | def packet_queue(self, pkt):
"""Enqueue packet to out_packet queue."""
pkt.pos = 0
pkt.to_process = pkt.packet_length
self.out_packet.append(pkt)
return NC.ERR_SUCCESS | python | def packet_queue(self, pkt):
"""Enqueue packet to out_packet queue."""
pkt.pos = 0
pkt.to_process = pkt.packet_length
self.out_packet.append(pkt)
return NC.ERR_SUCCESS | [
"def",
"packet_queue",
"(",
"self",
",",
"pkt",
")",
":",
"pkt",
".",
"pos",
"=",
"0",
"pkt",
".",
"to_process",
"=",
"pkt",
".",
"packet_length",
"self",
".",
"out_packet",
".",
"append",
"(",
"pkt",
")",
"return",
"NC",
".",
"ERR_SUCCESS"
] | Enqueue packet to out_packet queue. | [
"Enqueue",
"packet",
"to",
"out_packet",
"queue",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/base_nyamuk.py#L87-L94 | train |
iwanbk/nyamuk | nyamuk/base_nyamuk.py | BaseNyamuk.packet_write | def packet_write(self):
"""Write packet to network."""
bytes_written = 0
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN, bytes_written
while len(self.out_packet) > 0:
pkt = self.out_packet[0]
write_length, status = nyamuk_ne... | python | def packet_write(self):
"""Write packet to network."""
bytes_written = 0
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN, bytes_written
while len(self.out_packet) > 0:
pkt = self.out_packet[0]
write_length, status = nyamuk_ne... | [
"def",
"packet_write",
"(",
"self",
")",
":",
"bytes_written",
"=",
"0",
"if",
"self",
".",
"sock",
"==",
"NC",
".",
"INVALID_SOCKET",
":",
"return",
"NC",
".",
"ERR_NO_CONN",
",",
"bytes_written",
"while",
"len",
"(",
"self",
".",
"out_packet",
")",
">"... | Write packet to network. | [
"Write",
"packet",
"to",
"network",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/base_nyamuk.py#L96-L137 | train |
iwanbk/nyamuk | nyamuk/base_nyamuk.py | BaseNyamuk.packet_read | def packet_read(self):
"""Read packet from network."""
bytes_received = 0
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
if self.in_packet.command == 0:
ba_data, errnum, errmsg = nyamuk_net.read(self.sock, 1)
if errnum == 0 ... | python | def packet_read(self):
"""Read packet from network."""
bytes_received = 0
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
if self.in_packet.command == 0:
ba_data, errnum, errmsg = nyamuk_net.read(self.sock, 1)
if errnum == 0 ... | [
"def",
"packet_read",
"(",
"self",
")",
":",
"bytes_received",
"=",
"0",
"if",
"self",
".",
"sock",
"==",
"NC",
".",
"INVALID_SOCKET",
":",
"return",
"NC",
".",
"ERR_NO_CONN",
"if",
"self",
".",
"in_packet",
".",
"command",
"==",
"0",
":",
"ba_data",
"... | Read packet from network. | [
"Read",
"packet",
"from",
"network",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/base_nyamuk.py#L139-L230 | train |
iwanbk/nyamuk | nyamuk/base_nyamuk.py | BaseNyamuk.socket_close | def socket_close(self):
"""Close our socket."""
if self.sock != NC.INVALID_SOCKET:
self.sock.close()
self.sock = NC.INVALID_SOCKET | python | def socket_close(self):
"""Close our socket."""
if self.sock != NC.INVALID_SOCKET:
self.sock.close()
self.sock = NC.INVALID_SOCKET | [
"def",
"socket_close",
"(",
"self",
")",
":",
"if",
"self",
".",
"sock",
"!=",
"NC",
".",
"INVALID_SOCKET",
":",
"self",
".",
"sock",
".",
"close",
"(",
")",
"self",
".",
"sock",
"=",
"NC",
".",
"INVALID_SOCKET"
] | Close our socket. | [
"Close",
"our",
"socket",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/base_nyamuk.py#L232-L236 | train |
iwanbk/nyamuk | nyamuk/base_nyamuk.py | BaseNyamuk.build_publish_pkt | def build_publish_pkt(self, mid, topic, payload, qos, retain, dup):
"""Build PUBLISH packet."""
pkt = MqttPkt()
payloadlen = len(payload)
packetlen = 2 + len(topic) + payloadlen
if qos > 0:
packetlen += 2
pkt.mid = mid
pkt.command = N... | python | def build_publish_pkt(self, mid, topic, payload, qos, retain, dup):
"""Build PUBLISH packet."""
pkt = MqttPkt()
payloadlen = len(payload)
packetlen = 2 + len(topic) + payloadlen
if qos > 0:
packetlen += 2
pkt.mid = mid
pkt.command = N... | [
"def",
"build_publish_pkt",
"(",
"self",
",",
"mid",
",",
"topic",
",",
"payload",
",",
"qos",
",",
"retain",
",",
"dup",
")",
":",
"pkt",
"=",
"MqttPkt",
"(",
")",
"payloadlen",
"=",
"len",
"(",
"payload",
")",
"packetlen",
"=",
"2",
"+",
"len",
"... | Build PUBLISH packet. | [
"Build",
"PUBLISH",
"packet",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/base_nyamuk.py#L251-L278 | train |
iwanbk/nyamuk | nyamuk/base_nyamuk.py | BaseNyamuk.send_simple_command | def send_simple_command(self, cmd):
"""Send simple mqtt commands."""
pkt = MqttPkt()
pkt.command = cmd
pkt.remaining_length = 0
ret = pkt.alloc()
if ret != NC.ERR_SUCCESS:
return ret
return self.packet_queue(pkt) | python | def send_simple_command(self, cmd):
"""Send simple mqtt commands."""
pkt = MqttPkt()
pkt.command = cmd
pkt.remaining_length = 0
ret = pkt.alloc()
if ret != NC.ERR_SUCCESS:
return ret
return self.packet_queue(pkt) | [
"def",
"send_simple_command",
"(",
"self",
",",
"cmd",
")",
":",
"pkt",
"=",
"MqttPkt",
"(",
")",
"pkt",
".",
"command",
"=",
"cmd",
"pkt",
".",
"remaining_length",
"=",
"0",
"ret",
"=",
"pkt",
".",
"alloc",
"(",
")",
"if",
"ret",
"!=",
"NC",
".",
... | Send simple mqtt commands. | [
"Send",
"simple",
"mqtt",
"commands",
"."
] | ac4c6028de288a4c8e0b332ae16eae889deb643d | https://github.com/iwanbk/nyamuk/blob/ac4c6028de288a4c8e0b332ae16eae889deb643d/nyamuk/base_nyamuk.py#L280-L291 | train |
DusanMadar/TorIpChanger | toripchanger/changer.py | TorIpChanger.real_ip | def real_ip(self):
"""
The actual public IP of this host.
"""
if self._real_ip is None:
response = get(ICANHAZIP)
self._real_ip = self._get_response_text(response)
return self._real_ip | python | def real_ip(self):
"""
The actual public IP of this host.
"""
if self._real_ip is None:
response = get(ICANHAZIP)
self._real_ip = self._get_response_text(response)
return self._real_ip | [
"def",
"real_ip",
"(",
"self",
")",
":",
"if",
"self",
".",
"_real_ip",
"is",
"None",
":",
"response",
"=",
"get",
"(",
"ICANHAZIP",
")",
"self",
".",
"_real_ip",
"=",
"self",
".",
"_get_response_text",
"(",
"response",
")",
"return",
"self",
".",
"_re... | The actual public IP of this host. | [
"The",
"actual",
"public",
"IP",
"of",
"this",
"host",
"."
] | c2c4371e16f239b01ea36b82d971612bae00526d | https://github.com/DusanMadar/TorIpChanger/blob/c2c4371e16f239b01ea36b82d971612bae00526d/toripchanger/changer.py#L72-L80 | train |
DusanMadar/TorIpChanger | toripchanger/changer.py | TorIpChanger.get_current_ip | def get_current_ip(self):
"""
Get the current IP Tor is using.
:returns str
:raises TorIpError
"""
response = get(ICANHAZIP, proxies={"http": self.local_http_proxy})
if response.ok:
return self._get_response_text(response)
raise TorIpError("... | python | def get_current_ip(self):
"""
Get the current IP Tor is using.
:returns str
:raises TorIpError
"""
response = get(ICANHAZIP, proxies={"http": self.local_http_proxy})
if response.ok:
return self._get_response_text(response)
raise TorIpError("... | [
"def",
"get_current_ip",
"(",
"self",
")",
":",
"response",
"=",
"get",
"(",
"ICANHAZIP",
",",
"proxies",
"=",
"{",
"\"http\"",
":",
"self",
".",
"local_http_proxy",
"}",
")",
"if",
"response",
".",
"ok",
":",
"return",
"self",
".",
"_get_response_text",
... | Get the current IP Tor is using.
:returns str
:raises TorIpError | [
"Get",
"the",
"current",
"IP",
"Tor",
"is",
"using",
"."
] | c2c4371e16f239b01ea36b82d971612bae00526d | https://github.com/DusanMadar/TorIpChanger/blob/c2c4371e16f239b01ea36b82d971612bae00526d/toripchanger/changer.py#L82-L94 | train |
DusanMadar/TorIpChanger | toripchanger/changer.py | TorIpChanger.get_new_ip | def get_new_ip(self):
"""
Try to obtain new a usable TOR IP.
:returns bool
:raises TorIpError
"""
attempts = 0
while True:
if attempts == self.new_ip_max_attempts:
raise TorIpError("Failed to obtain a new usable Tor IP")
... | python | def get_new_ip(self):
"""
Try to obtain new a usable TOR IP.
:returns bool
:raises TorIpError
"""
attempts = 0
while True:
if attempts == self.new_ip_max_attempts:
raise TorIpError("Failed to obtain a new usable Tor IP")
... | [
"def",
"get_new_ip",
"(",
"self",
")",
":",
"attempts",
"=",
"0",
"while",
"True",
":",
"if",
"attempts",
"==",
"self",
".",
"new_ip_max_attempts",
":",
"raise",
"TorIpError",
"(",
"\"Failed to obtain a new usable Tor IP\"",
")",
"attempts",
"+=",
"1",
"try",
... | Try to obtain new a usable TOR IP.
:returns bool
:raises TorIpError | [
"Try",
"to",
"obtain",
"new",
"a",
"usable",
"TOR",
"IP",
"."
] | c2c4371e16f239b01ea36b82d971612bae00526d | https://github.com/DusanMadar/TorIpChanger/blob/c2c4371e16f239b01ea36b82d971612bae00526d/toripchanger/changer.py#L96-L124 | train |
DusanMadar/TorIpChanger | toripchanger/changer.py | TorIpChanger._ip_is_usable | def _ip_is_usable(self, current_ip):
"""
Check if the current Tor's IP is usable.
:argument current_ip: current Tor IP
:type current_ip: str
:returns bool
"""
# Consider IP addresses only.
try:
ipaddress.ip_address(current_ip)
except ... | python | def _ip_is_usable(self, current_ip):
"""
Check if the current Tor's IP is usable.
:argument current_ip: current Tor IP
:type current_ip: str
:returns bool
"""
# Consider IP addresses only.
try:
ipaddress.ip_address(current_ip)
except ... | [
"def",
"_ip_is_usable",
"(",
"self",
",",
"current_ip",
")",
":",
"# Consider IP addresses only.",
"try",
":",
"ipaddress",
".",
"ip_address",
"(",
"current_ip",
")",
"except",
"ValueError",
":",
"return",
"False",
"# Never use real IP.",
"if",
"current_ip",
"==",
... | Check if the current Tor's IP is usable.
:argument current_ip: current Tor IP
:type current_ip: str
:returns bool | [
"Check",
"if",
"the",
"current",
"Tor",
"s",
"IP",
"is",
"usable",
"."
] | c2c4371e16f239b01ea36b82d971612bae00526d | https://github.com/DusanMadar/TorIpChanger/blob/c2c4371e16f239b01ea36b82d971612bae00526d/toripchanger/changer.py#L140-L163 | train |
DusanMadar/TorIpChanger | toripchanger/changer.py | TorIpChanger._manage_used_ips | def _manage_used_ips(self, current_ip):
"""
Handle registering and releasing used Tor IPs.
:argument current_ip: current Tor IP
:type current_ip: str
"""
# Register current IP.
self.used_ips.append(current_ip)
# Release the oldest registred IP.
i... | python | def _manage_used_ips(self, current_ip):
"""
Handle registering and releasing used Tor IPs.
:argument current_ip: current Tor IP
:type current_ip: str
"""
# Register current IP.
self.used_ips.append(current_ip)
# Release the oldest registred IP.
i... | [
"def",
"_manage_used_ips",
"(",
"self",
",",
"current_ip",
")",
":",
"# Register current IP.",
"self",
".",
"used_ips",
".",
"append",
"(",
"current_ip",
")",
"# Release the oldest registred IP.",
"if",
"self",
".",
"reuse_threshold",
":",
"if",
"len",
"(",
"self"... | Handle registering and releasing used Tor IPs.
:argument current_ip: current Tor IP
:type current_ip: str | [
"Handle",
"registering",
"and",
"releasing",
"used",
"Tor",
"IPs",
"."
] | c2c4371e16f239b01ea36b82d971612bae00526d | https://github.com/DusanMadar/TorIpChanger/blob/c2c4371e16f239b01ea36b82d971612bae00526d/toripchanger/changer.py#L165-L178 | train |
DusanMadar/TorIpChanger | toripchanger/changer.py | TorIpChanger._obtain_new_ip | def _obtain_new_ip(self):
"""
Change Tor's IP.
"""
with Controller.from_port(
address=self.tor_address, port=self.tor_port
) as controller:
controller.authenticate(password=self.tor_password)
controller.signal(Signal.NEWNYM)
# Wait til... | python | def _obtain_new_ip(self):
"""
Change Tor's IP.
"""
with Controller.from_port(
address=self.tor_address, port=self.tor_port
) as controller:
controller.authenticate(password=self.tor_password)
controller.signal(Signal.NEWNYM)
# Wait til... | [
"def",
"_obtain_new_ip",
"(",
"self",
")",
":",
"with",
"Controller",
".",
"from_port",
"(",
"address",
"=",
"self",
".",
"tor_address",
",",
"port",
"=",
"self",
".",
"tor_port",
")",
"as",
"controller",
":",
"controller",
".",
"authenticate",
"(",
"passw... | Change Tor's IP. | [
"Change",
"Tor",
"s",
"IP",
"."
] | c2c4371e16f239b01ea36b82d971612bae00526d | https://github.com/DusanMadar/TorIpChanger/blob/c2c4371e16f239b01ea36b82d971612bae00526d/toripchanger/changer.py#L180-L191 | train |
devassistant/devassistant | devassistant/excepthook.py | is_local_subsection | def is_local_subsection(command_dict):
"""Returns True if command dict is "local subsection", meaning
that it is "if", "else" or "for" (not a real call, but calls
run_section recursively."""
for local_com in ['if ', 'for ', 'else ']:
if list(command_dict.keys())[0].startswith(local_com):
... | python | def is_local_subsection(command_dict):
"""Returns True if command dict is "local subsection", meaning
that it is "if", "else" or "for" (not a real call, but calls
run_section recursively."""
for local_com in ['if ', 'for ', 'else ']:
if list(command_dict.keys())[0].startswith(local_com):
... | [
"def",
"is_local_subsection",
"(",
"command_dict",
")",
":",
"for",
"local_com",
"in",
"[",
"'if '",
",",
"'for '",
",",
"'else '",
"]",
":",
"if",
"list",
"(",
"command_dict",
".",
"keys",
"(",
")",
")",
"[",
"0",
"]",
".",
"startswith",
"(",
"local_c... | Returns True if command dict is "local subsection", meaning
that it is "if", "else" or "for" (not a real call, but calls
run_section recursively. | [
"Returns",
"True",
"if",
"command",
"dict",
"is",
"local",
"subsection",
"meaning",
"that",
"it",
"is",
"if",
"else",
"or",
"for",
"(",
"not",
"a",
"real",
"call",
"but",
"calls",
"run_section",
"recursively",
"."
] | 2dbfeaa666a64127263664d18969c55d19ecc83e | https://github.com/devassistant/devassistant/blob/2dbfeaa666a64127263664d18969c55d19ecc83e/devassistant/excepthook.py#L24-L31 | train |
devassistant/devassistant | devassistant/dapi/dapicli.py | _process_req_txt | def _process_req_txt(req):
'''Returns a processed request or raises an exception'''
if req.status_code == 404:
return ''
if req.status_code != 200:
raise DapiCommError('Response of the server was {code}'.format(code=req.status_code))
return req.text | python | def _process_req_txt(req):
'''Returns a processed request or raises an exception'''
if req.status_code == 404:
return ''
if req.status_code != 200:
raise DapiCommError('Response of the server was {code}'.format(code=req.status_code))
return req.text | [
"def",
"_process_req_txt",
"(",
"req",
")",
":",
"if",
"req",
".",
"status_code",
"==",
"404",
":",
"return",
"''",
"if",
"req",
".",
"status_code",
"!=",
"200",
":",
"raise",
"DapiCommError",
"(",
"'Response of the server was {code}'",
".",
"format",
"(",
"... | Returns a processed request or raises an exception | [
"Returns",
"a",
"processed",
"request",
"or",
"raises",
"an",
"exception"
] | 2dbfeaa666a64127263664d18969c55d19ecc83e | https://github.com/devassistant/devassistant/blob/2dbfeaa666a64127263664d18969c55d19ecc83e/devassistant/dapi/dapicli.py#L49-L55 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.