repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
fulfilio/fulfil-python-api | fulfil_client/model.py | Query.order_by | def order_by(self, *criterion):
"""
apply one or more ORDER BY criterion to the query and
return the newly resulting Query
All existing ORDER BY settings can be suppressed by passing None -
this will suppress any ORDER BY configured on mappers as well.
"""
query ... | python | def order_by(self, *criterion):
"""
apply one or more ORDER BY criterion to the query and
return the newly resulting Query
All existing ORDER BY settings can be suppressed by passing None -
this will suppress any ORDER BY configured on mappers as well.
"""
query ... | [
"def",
"order_by",
"(",
"self",
",",
"*",
"criterion",
")",
":",
"query",
"=",
"self",
".",
"_copy",
"(",
")",
"query",
".",
"_order_by",
"=",
"criterion",
"return",
"query"
] | apply one or more ORDER BY criterion to the query and
return the newly resulting Query
All existing ORDER BY settings can be suppressed by passing None -
this will suppress any ORDER BY configured on mappers as well. | [
"apply",
"one",
"or",
"more",
"ORDER",
"BY",
"criterion",
"to",
"the",
"query",
"and",
"return",
"the",
"newly",
"resulting",
"Query"
] | train | https://github.com/fulfilio/fulfil-python-api/blob/180ac969c427b1292439a0371866aa5f169ffa6b/fulfil_client/model.py#L472-L482 |
fulfilio/fulfil-python-api | fulfil_client/model.py | Query.delete | def delete(self):
"""
Delete all records matching the query.
Warning: This is a desctructive operation.
Not every model allows deletion of records and several models
even restrict based on status. For example, deleting products
that have been transacted is restricted. A... | python | def delete(self):
"""
Delete all records matching the query.
Warning: This is a desctructive operation.
Not every model allows deletion of records and several models
even restrict based on status. For example, deleting products
that have been transacted is restricted. A... | [
"def",
"delete",
"(",
"self",
")",
":",
"ids",
"=",
"self",
".",
"rpc_model",
".",
"search",
"(",
"self",
".",
"domain",
",",
"context",
"=",
"self",
".",
"context",
")",
"if",
"ids",
":",
"self",
".",
"rpc_model",
".",
"delete",
"(",
"ids",
")"
] | Delete all records matching the query.
Warning: This is a desctructive operation.
Not every model allows deletion of records and several models
even restrict based on status. For example, deleting products
that have been transacted is restricted. Another example is sales
orders... | [
"Delete",
"all",
"records",
"matching",
"the",
"query",
"."
] | train | https://github.com/fulfilio/fulfil-python-api/blob/180ac969c427b1292439a0371866aa5f169ffa6b/fulfil_client/model.py#L484-L499 |
fulfilio/fulfil-python-api | fulfil_client/model.py | Query.archive | def archive(self):
"""
Archives (soft delete) all the records matching the query.
This assumes that the model allows archiving (not many do - especially
transactional documents).
Internal implementation sets the active field to False.
"""
ids = self.rpc_model.se... | python | def archive(self):
"""
Archives (soft delete) all the records matching the query.
This assumes that the model allows archiving (not many do - especially
transactional documents).
Internal implementation sets the active field to False.
"""
ids = self.rpc_model.se... | [
"def",
"archive",
"(",
"self",
")",
":",
"ids",
"=",
"self",
".",
"rpc_model",
".",
"search",
"(",
"self",
".",
"domain",
",",
"context",
"=",
"self",
".",
"context",
")",
"if",
"ids",
":",
"self",
".",
"rpc_model",
".",
"write",
"(",
"ids",
",",
... | Archives (soft delete) all the records matching the query.
This assumes that the model allows archiving (not many do - especially
transactional documents).
Internal implementation sets the active field to False. | [
"Archives",
"(",
"soft",
"delete",
")",
"all",
"the",
"records",
"matching",
"the",
"query",
"."
] | train | https://github.com/fulfilio/fulfil-python-api/blob/180ac969c427b1292439a0371866aa5f169ffa6b/fulfil_client/model.py#L501-L512 |
317070/python-twitch-stream | twitchstream/chat.py | TwitchChatStream._logged_in_successful | def _logged_in_successful(data):
"""
Test the login status from the returned communication of the
server.
:param data: bytes received from server during login
:type data: list of bytes
:return boolean, True when you are logged in.
"""
if re.match(r'^:(te... | python | def _logged_in_successful(data):
"""
Test the login status from the returned communication of the
server.
:param data: bytes received from server during login
:type data: list of bytes
:return boolean, True when you are logged in.
"""
if re.match(r'^:(te... | [
"def",
"_logged_in_successful",
"(",
"data",
")",
":",
"if",
"re",
".",
"match",
"(",
"r'^:(testserver\\.local|tmi\\.twitch\\.tv)'",
"r' NOTICE \\* :'",
"r'(Login unsuccessful|Error logging in)*$'",
",",
"data",
".",
"strip",
"(",
")",
")",
":",
"return",
"False",
"el... | Test the login status from the returned communication of the
server.
:param data: bytes received from server during login
:type data: list of bytes
:return boolean, True when you are logged in. | [
"Test",
"the",
"login",
"status",
"from",
"the",
"returned",
"communication",
"of",
"the",
"server",
"."
] | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/chat.py#L51-L67 |
317070/python-twitch-stream | twitchstream/chat.py | TwitchChatStream.connect | def connect(self):
"""
Connect to Twitch
"""
# Do not use non-blocking stream, they are not reliably
# non-blocking
# s.setblocking(False)
# s.settimeout(1.0)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connect_host = "irc.twitch.tv"
... | python | def connect(self):
"""
Connect to Twitch
"""
# Do not use non-blocking stream, they are not reliably
# non-blocking
# s.setblocking(False)
# s.settimeout(1.0)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connect_host = "irc.twitch.tv"
... | [
"def",
"connect",
"(",
"self",
")",
":",
"# Do not use non-blocking stream, they are not reliably",
"# non-blocking",
"# s.setblocking(False)",
"# s.settimeout(1.0)",
"s",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
"SOCK_STREAM",
")... | Connect to Twitch | [
"Connect",
"to",
"Twitch"
] | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/chat.py#L109-L157 |
317070/python-twitch-stream | twitchstream/chat.py | TwitchChatStream._push_from_buffer | def _push_from_buffer(self):
"""
Push a message on the stack to the IRC stream.
This is necessary to avoid Twitch overflow control.
"""
if len(self.buffer) > 0:
if time.time() - self.last_sent_time > 5:
try:
message = self.buffer.po... | python | def _push_from_buffer(self):
"""
Push a message on the stack to the IRC stream.
This is necessary to avoid Twitch overflow control.
"""
if len(self.buffer) > 0:
if time.time() - self.last_sent_time > 5:
try:
message = self.buffer.po... | [
"def",
"_push_from_buffer",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"buffer",
")",
">",
"0",
":",
"if",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"last_sent_time",
">",
"5",
":",
"try",
":",
"message",
"=",
"self",
".",
"buff... | Push a message on the stack to the IRC stream.
This is necessary to avoid Twitch overflow control. | [
"Push",
"a",
"message",
"on",
"the",
"stack",
"to",
"the",
"IRC",
"stream",
".",
"This",
"is",
"necessary",
"to",
"avoid",
"Twitch",
"overflow",
"control",
"."
] | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/chat.py#L159-L172 |
317070/python-twitch-stream | twitchstream/chat.py | TwitchChatStream.join_channel | def join_channel(self, channel):
"""
Join a different chat channel on Twitch.
Note, this function returns immediately, but the switch might
take a moment
:param channel: name of the channel (without #)
"""
self.s.send(('JOIN #%s\r\n' % channel).encode('utf-8'))
... | python | def join_channel(self, channel):
"""
Join a different chat channel on Twitch.
Note, this function returns immediately, but the switch might
take a moment
:param channel: name of the channel (without #)
"""
self.s.send(('JOIN #%s\r\n' % channel).encode('utf-8'))
... | [
"def",
"join_channel",
"(",
"self",
",",
"channel",
")",
":",
"self",
".",
"s",
".",
"send",
"(",
"(",
"'JOIN #%s\\r\\n'",
"%",
"channel",
")",
".",
"encode",
"(",
"'utf-8'",
")",
")",
"if",
"self",
".",
"verbose",
":",
"print",
"(",
"'JOIN #%s\\r\\n'"... | Join a different chat channel on Twitch.
Note, this function returns immediately, but the switch might
take a moment
:param channel: name of the channel (without #) | [
"Join",
"a",
"different",
"chat",
"channel",
"on",
"Twitch",
".",
"Note",
"this",
"function",
"returns",
"immediately",
"but",
"the",
"switch",
"might",
"take",
"a",
"moment"
] | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/chat.py#L190-L200 |
317070/python-twitch-stream | twitchstream/chat.py | TwitchChatStream._parse_message | def _parse_message(self, data):
"""
Parse the bytes received from the socket.
:param data: the bytes received from the socket
:return:
"""
if TwitchChatStream._check_has_ping(data):
self._send_pong()
if TwitchChatStream._check_has_channel(data):
... | python | def _parse_message(self, data):
"""
Parse the bytes received from the socket.
:param data: the bytes received from the socket
:return:
"""
if TwitchChatStream._check_has_ping(data):
self._send_pong()
if TwitchChatStream._check_has_channel(data):
... | [
"def",
"_parse_message",
"(",
"self",
",",
"data",
")",
":",
"if",
"TwitchChatStream",
".",
"_check_has_ping",
"(",
"data",
")",
":",
"self",
".",
"_send_pong",
"(",
")",
"if",
"TwitchChatStream",
".",
"_check_has_channel",
"(",
"data",
")",
":",
"self",
"... | Parse the bytes received from the socket.
:param data: the bytes received from the socket
:return: | [
"Parse",
"the",
"bytes",
"received",
"from",
"the",
"socket",
"."
] | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/chat.py#L210-L235 |
317070/python-twitch-stream | twitchstream/chat.py | TwitchChatStream.twitch_receive_messages | def twitch_receive_messages(self):
"""
Call this function to process everything received by the socket
This needs to be called frequently enough (~10s) Twitch logs off
users not replying to ping commands.
:return: list of chat messages received. Each message is a dict
... | python | def twitch_receive_messages(self):
"""
Call this function to process everything received by the socket
This needs to be called frequently enough (~10s) Twitch logs off
users not replying to ping commands.
:return: list of chat messages received. Each message is a dict
... | [
"def",
"twitch_receive_messages",
"(",
"self",
")",
":",
"self",
".",
"_push_from_buffer",
"(",
")",
"result",
"=",
"[",
"]",
"while",
"True",
":",
"# process the complete buffer, until no data is left no more",
"try",
":",
"msg",
"=",
"self",
".",
"s",
".",
"re... | Call this function to process everything received by the socket
This needs to be called frequently enough (~10s) Twitch logs off
users not replying to ping commands.
:return: list of chat messages received. Each message is a dict
with the keys ['channel', 'username', 'message'] | [
"Call",
"this",
"function",
"to",
"process",
"everything",
"received",
"by",
"the",
"socket",
"This",
"needs",
"to",
"be",
"called",
"frequently",
"enough",
"(",
"~10s",
")",
"Twitch",
"logs",
"off",
"users",
"not",
"replying",
"to",
"ping",
"commands",
"."
... | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/chat.py#L237-L271 |
317070/python-twitch-stream | twitchstream/outputvideo.py | TwitchOutputStream.reset | def reset(self):
"""
Reset the videostream by restarting ffmpeg
"""
if self.ffmpeg_process is not None:
# Close the previous stream
try:
self.ffmpeg_process.send_signal(signal.SIGINT)
except OSError:
pass
comma... | python | def reset(self):
"""
Reset the videostream by restarting ffmpeg
"""
if self.ffmpeg_process is not None:
# Close the previous stream
try:
self.ffmpeg_process.send_signal(signal.SIGINT)
except OSError:
pass
comma... | [
"def",
"reset",
"(",
"self",
")",
":",
"if",
"self",
".",
"ffmpeg_process",
"is",
"not",
"None",
":",
"# Close the previous stream",
"try",
":",
"self",
".",
"ffmpeg_process",
".",
"send_signal",
"(",
"signal",
".",
"SIGINT",
")",
"except",
"OSError",
":",
... | Reset the videostream by restarting ffmpeg | [
"Reset",
"the",
"videostream",
"by",
"restarting",
"ffmpeg"
] | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/outputvideo.py#L75-L174 |
317070/python-twitch-stream | twitchstream/outputvideo.py | TwitchOutputStream.send_video_frame | def send_video_frame(self, frame):
"""Send frame of shape (height, width, 3)
with values between 0 and 1.
Raises an OSError when the stream is closed.
:param frame: array containing the frame.
:type frame: numpy array with shape (height, width, 3)
containing values b... | python | def send_video_frame(self, frame):
"""Send frame of shape (height, width, 3)
with values between 0 and 1.
Raises an OSError when the stream is closed.
:param frame: array containing the frame.
:type frame: numpy array with shape (height, width, 3)
containing values b... | [
"def",
"send_video_frame",
"(",
"self",
",",
"frame",
")",
":",
"if",
"self",
".",
"video_pipe",
"is",
"None",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"'/tmp/videopipe'",
")",
":",
"os",
".",
"mkfifo",
"(",
"'/tmp/videopipe'",
")",
"se... | Send frame of shape (height, width, 3)
with values between 0 and 1.
Raises an OSError when the stream is closed.
:param frame: array containing the frame.
:type frame: numpy array with shape (height, width, 3)
containing values between 0.0 and 1.0 | [
"Send",
"frame",
"of",
"shape",
"(",
"height",
"width",
"3",
")",
"with",
"values",
"between",
"0",
"and",
"1",
".",
"Raises",
"an",
"OSError",
"when",
"the",
"stream",
"is",
"closed",
"."
] | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/outputvideo.py#L185-L207 |
317070/python-twitch-stream | twitchstream/outputvideo.py | TwitchOutputStream.send_audio | def send_audio(self, left_channel, right_channel):
"""Add the audio samples to the stream. The left and the right
channel should have the same shape.
Raises an OSError when the stream is closed.
:param left_channel: array containing the audio signal.
:type left_channel: numpy ar... | python | def send_audio(self, left_channel, right_channel):
"""Add the audio samples to the stream. The left and the right
channel should have the same shape.
Raises an OSError when the stream is closed.
:param left_channel: array containing the audio signal.
:type left_channel: numpy ar... | [
"def",
"send_audio",
"(",
"self",
",",
"left_channel",
",",
"right_channel",
")",
":",
"if",
"self",
".",
"audio_pipe",
"is",
"None",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"'/tmp/audiopipe'",
")",
":",
"os",
".",
"mkfifo",
"(",
"'/tm... | Add the audio samples to the stream. The left and the right
channel should have the same shape.
Raises an OSError when the stream is closed.
:param left_channel: array containing the audio signal.
:type left_channel: numpy array with shape (k, )
containing values between -1.... | [
"Add",
"the",
"audio",
"samples",
"to",
"the",
"stream",
".",
"The",
"left",
"and",
"the",
"right",
"channel",
"should",
"have",
"the",
"same",
"shape",
".",
"Raises",
"an",
"OSError",
"when",
"the",
"stream",
"is",
"closed",
"."
] | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/outputvideo.py#L209-L237 |
317070/python-twitch-stream | twitchstream/outputvideo.py | TwitchOutputStreamRepeater.send_audio | def send_audio(self, left_channel, right_channel):
"""Add the audio samples to the stream. The left and the right
channel should have the same shape.
:param left_channel: array containing the audio signal.
:type left_channel: numpy array with shape (k, )
containing values be... | python | def send_audio(self, left_channel, right_channel):
"""Add the audio samples to the stream. The left and the right
channel should have the same shape.
:param left_channel: array containing the audio signal.
:type left_channel: numpy array with shape (k, )
containing values be... | [
"def",
"send_audio",
"(",
"self",
",",
"left_channel",
",",
"right_channel",
")",
":",
"self",
".",
"lastaudioframe_left",
"=",
"left_channel",
"self",
".",
"lastaudioframe_right",
"=",
"right_channel"
] | Add the audio samples to the stream. The left and the right
channel should have the same shape.
:param left_channel: array containing the audio signal.
:type left_channel: numpy array with shape (k, )
containing values between -1.0 and 1.0. k can be any integer
:param right_... | [
"Add",
"the",
"audio",
"samples",
"to",
"the",
"stream",
".",
"The",
"left",
"and",
"the",
"right",
"channel",
"should",
"have",
"the",
"same",
"shape",
"."
] | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/outputvideo.py#L300-L312 |
317070/python-twitch-stream | twitchstream/outputvideo.py | TwitchBufferedOutputStream.send_video_frame | def send_video_frame(self, frame, frame_counter=None):
"""send frame of shape (height, width, 3)
with values between 0 and 1
:param frame: array containing the frame.
:type frame: numpy array with shape (height, width, 3)
containing values between 0.0 and 1.0
:param ... | python | def send_video_frame(self, frame, frame_counter=None):
"""send frame of shape (height, width, 3)
with values between 0 and 1
:param frame: array containing the frame.
:type frame: numpy array with shape (height, width, 3)
containing values between 0.0 and 1.0
:param ... | [
"def",
"send_video_frame",
"(",
"self",
",",
"frame",
",",
"frame_counter",
"=",
"None",
")",
":",
"if",
"frame_counter",
"is",
"None",
":",
"frame_counter",
"=",
"self",
".",
"frame_counter",
"self",
".",
"frame_counter",
"+=",
"1",
"self",
".",
"q_video",
... | send frame of shape (height, width, 3)
with values between 0 and 1
:param frame: array containing the frame.
:type frame: numpy array with shape (height, width, 3)
containing values between 0.0 and 1.0
:param frame_counter: frame position number within stream.
Pr... | [
"send",
"frame",
"of",
"shape",
"(",
"height",
"width",
"3",
")",
"with",
"values",
"between",
"0",
"and",
"1"
] | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/outputvideo.py#L446-L462 |
317070/python-twitch-stream | twitchstream/outputvideo.py | TwitchBufferedOutputStream.send_audio | def send_audio(self,
left_channel,
right_channel,
frame_counter=None):
"""Add the audio samples to the stream. The left and the right
channel should have the same shape.
:param left_channel: array containing the audio signal.
:typ... | python | def send_audio(self,
left_channel,
right_channel,
frame_counter=None):
"""Add the audio samples to the stream. The left and the right
channel should have the same shape.
:param left_channel: array containing the audio signal.
:typ... | [
"def",
"send_audio",
"(",
"self",
",",
"left_channel",
",",
"right_channel",
",",
"frame_counter",
"=",
"None",
")",
":",
"if",
"frame_counter",
"is",
"None",
":",
"frame_counter",
"=",
"self",
".",
"audio_frame_counter",
"self",
".",
"audio_frame_counter",
"+="... | Add the audio samples to the stream. The left and the right
channel should have the same shape.
:param left_channel: array containing the audio signal.
:type left_channel: numpy array with shape (k, )
containing values between -1.0 and 1.0. l can be any integer
:param right_... | [
"Add",
"the",
"audio",
"samples",
"to",
"the",
"stream",
".",
"The",
"left",
"and",
"the",
"right",
"channel",
"should",
"have",
"the",
"same",
"shape",
"."
] | train | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/outputvideo.py#L464-L486 |
flashingpumpkin/django-socialregistration | socialregistration/mixins.py | CommonMixin.import_attribute | def import_attribute(self, path):
"""
Import an attribute from a module.
"""
module = '.'.join(path.split('.')[:-1])
function = path.split('.')[-1]
module = importlib.import_module(module)
return getattr(module, function) | python | def import_attribute(self, path):
"""
Import an attribute from a module.
"""
module = '.'.join(path.split('.')[:-1])
function = path.split('.')[-1]
module = importlib.import_module(module)
return getattr(module, function) | [
"def",
"import_attribute",
"(",
"self",
",",
"path",
")",
":",
"module",
"=",
"'.'",
".",
"join",
"(",
"path",
".",
"split",
"(",
"'.'",
")",
"[",
":",
"-",
"1",
"]",
")",
"function",
"=",
"path",
".",
"split",
"(",
"'.'",
")",
"[",
"-",
"1",
... | Import an attribute from a module. | [
"Import",
"an",
"attribute",
"from",
"a",
"module",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L21-L29 |
flashingpumpkin/django-socialregistration | socialregistration/mixins.py | CommonMixin.get_next | def get_next(self, request):
"""
Returns a url to redirect to after the login / signup.
"""
if 'next' in request.session:
next = request.session['next']
del request.session['next']
elif 'next' in request.GET:
next = request.GET.get('next')
... | python | def get_next(self, request):
"""
Returns a url to redirect to after the login / signup.
"""
if 'next' in request.session:
next = request.session['next']
del request.session['next']
elif 'next' in request.GET:
next = request.GET.get('next')
... | [
"def",
"get_next",
"(",
"self",
",",
"request",
")",
":",
"if",
"'next'",
"in",
"request",
".",
"session",
":",
"next",
"=",
"request",
".",
"session",
"[",
"'next'",
"]",
"del",
"request",
".",
"session",
"[",
"'next'",
"]",
"elif",
"'next'",
"in",
... | Returns a url to redirect to after the login / signup. | [
"Returns",
"a",
"url",
"to",
"redirect",
"to",
"after",
"the",
"login",
"/",
"signup",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L31-L50 |
flashingpumpkin/django-socialregistration | socialregistration/mixins.py | CommonMixin.inactive_response | def inactive_response(self, request):
"""
Return an inactive message.
"""
inactive_url = getattr(settings, 'LOGIN_INACTIVE_REDIRECT_URL', '')
if inactive_url:
return HttpResponseRedirect(inactive_url)
else:
return self.error_to_response(request, {'... | python | def inactive_response(self, request):
"""
Return an inactive message.
"""
inactive_url = getattr(settings, 'LOGIN_INACTIVE_REDIRECT_URL', '')
if inactive_url:
return HttpResponseRedirect(inactive_url)
else:
return self.error_to_response(request, {'... | [
"def",
"inactive_response",
"(",
"self",
",",
"request",
")",
":",
"inactive_url",
"=",
"getattr",
"(",
"settings",
",",
"'LOGIN_INACTIVE_REDIRECT_URL'",
",",
"''",
")",
"if",
"inactive_url",
":",
"return",
"HttpResponseRedirect",
"(",
"inactive_url",
")",
"else",... | Return an inactive message. | [
"Return",
"an",
"inactive",
"message",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L64-L72 |
flashingpumpkin/django-socialregistration | socialregistration/mixins.py | ProfileMixin.create_profile | def create_profile(self, user, save=False, **kwargs):
"""
Create a profile model.
:param user: A user object
:param save: If this is set, the profile will
be saved to DB straight away
:type save: bool
"""
profile = self.get_model()(user=user, **kwargs... | python | def create_profile(self, user, save=False, **kwargs):
"""
Create a profile model.
:param user: A user object
:param save: If this is set, the profile will
be saved to DB straight away
:type save: bool
"""
profile = self.get_model()(user=user, **kwargs... | [
"def",
"create_profile",
"(",
"self",
",",
"user",
",",
"save",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"profile",
"=",
"self",
".",
"get_model",
"(",
")",
"(",
"user",
"=",
"user",
",",
"*",
"*",
"kwargs",
")",
"if",
"save",
":",
"profi... | Create a profile model.
:param user: A user object
:param save: If this is set, the profile will
be saved to DB straight away
:type save: bool | [
"Create",
"a",
"profile",
"model",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L128-L142 |
flashingpumpkin/django-socialregistration | socialregistration/mixins.py | ProfileMixin.get_or_create_profile | def get_or_create_profile(self, user, save=False, **kwargs):
"""
Return a profile from DB or if there is none, create a new one.
:param user: A user object
:param save: If set, a new profile will be saved.
:type save: bool
"""
try:
profile = self.get_... | python | def get_or_create_profile(self, user, save=False, **kwargs):
"""
Return a profile from DB or if there is none, create a new one.
:param user: A user object
:param save: If set, a new profile will be saved.
:type save: bool
"""
try:
profile = self.get_... | [
"def",
"get_or_create_profile",
"(",
"self",
",",
"user",
",",
"save",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"profile",
"=",
"self",
".",
"get_model",
"(",
")",
".",
"objects",
".",
"get",
"(",
"user",
"=",
"user",
",",
"*",
... | Return a profile from DB or if there is none, create a new one.
:param user: A user object
:param save: If set, a new profile will be saved.
:type save: bool | [
"Return",
"a",
"profile",
"from",
"DB",
"or",
"if",
"there",
"is",
"none",
"create",
"a",
"new",
"one",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L150-L163 |
flashingpumpkin/django-socialregistration | socialregistration/mixins.py | SessionMixin.get_session_data | def get_session_data(self, request):
"""
Return a tuple ``(user, profile, client)`` from the session.
"""
user = request.session['%suser' % SESSION_KEY]
profile = request.session['%sprofile' % SESSION_KEY]
client = request.session['%sclient' % SESSION_KEY]
return ... | python | def get_session_data(self, request):
"""
Return a tuple ``(user, profile, client)`` from the session.
"""
user = request.session['%suser' % SESSION_KEY]
profile = request.session['%sprofile' % SESSION_KEY]
client = request.session['%sclient' % SESSION_KEY]
return ... | [
"def",
"get_session_data",
"(",
"self",
",",
"request",
")",
":",
"user",
"=",
"request",
".",
"session",
"[",
"'%suser'",
"%",
"SESSION_KEY",
"]",
"profile",
"=",
"request",
".",
"session",
"[",
"'%sprofile'",
"%",
"SESSION_KEY",
"]",
"client",
"=",
"requ... | Return a tuple ``(user, profile, client)`` from the session. | [
"Return",
"a",
"tuple",
"(",
"user",
"profile",
"client",
")",
"from",
"the",
"session",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L190-L197 |
flashingpumpkin/django-socialregistration | socialregistration/mixins.py | SignalMixin.send_login_signal | def send_login_signal(self, request, user, profile, client):
"""
Send a signal that a user logged in. This signal should be sent only if
the user was *not* logged into Django.
"""
signals.login.send(sender=profile.__class__, user=user,
profile=profile, client=client, ... | python | def send_login_signal(self, request, user, profile, client):
"""
Send a signal that a user logged in. This signal should be sent only if
the user was *not* logged into Django.
"""
signals.login.send(sender=profile.__class__, user=user,
profile=profile, client=client, ... | [
"def",
"send_login_signal",
"(",
"self",
",",
"request",
",",
"user",
",",
"profile",
",",
"client",
")",
":",
"signals",
".",
"login",
".",
"send",
"(",
"sender",
"=",
"profile",
".",
"__class__",
",",
"user",
"=",
"user",
",",
"profile",
"=",
"profil... | Send a signal that a user logged in. This signal should be sent only if
the user was *not* logged into Django. | [
"Send",
"a",
"signal",
"that",
"a",
"user",
"logged",
"in",
".",
"This",
"signal",
"should",
"be",
"sent",
"only",
"if",
"the",
"user",
"was",
"*",
"not",
"*",
"logged",
"into",
"Django",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L214-L220 |
flashingpumpkin/django-socialregistration | socialregistration/mixins.py | SignalMixin.send_connect_signal | def send_connect_signal(self, request, user, profile, client):
"""
Send a signal that a user connected a social profile to his Django
account. This signal should be sent *only* when the a new social
connection was created.
"""
signals.connect.send(sender=profile.__class__... | python | def send_connect_signal(self, request, user, profile, client):
"""
Send a signal that a user connected a social profile to his Django
account. This signal should be sent *only* when the a new social
connection was created.
"""
signals.connect.send(sender=profile.__class__... | [
"def",
"send_connect_signal",
"(",
"self",
",",
"request",
",",
"user",
",",
"profile",
",",
"client",
")",
":",
"signals",
".",
"connect",
".",
"send",
"(",
"sender",
"=",
"profile",
".",
"__class__",
",",
"user",
"=",
"user",
",",
"profile",
"=",
"pr... | Send a signal that a user connected a social profile to his Django
account. This signal should be sent *only* when the a new social
connection was created. | [
"Send",
"a",
"signal",
"that",
"a",
"user",
"connected",
"a",
"social",
"profile",
"to",
"his",
"Django",
"account",
".",
"This",
"signal",
"should",
"be",
"sent",
"*",
"only",
"*",
"when",
"the",
"a",
"new",
"social",
"connection",
"was",
"created",
"."... | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L222-L229 |
flashingpumpkin/django-socialregistration | socialregistration/contrib/foursquare/client.py | Foursquare.request_access_token | def request_access_token(self, params):
"""
Foursquare does not accept POST requests to retrieve an access token,
so we'll be doing a GET request instead.
"""
return self.request(self.access_token_url, method="GET", params=params) | python | def request_access_token(self, params):
"""
Foursquare does not accept POST requests to retrieve an access token,
so we'll be doing a GET request instead.
"""
return self.request(self.access_token_url, method="GET", params=params) | [
"def",
"request_access_token",
"(",
"self",
",",
"params",
")",
":",
"return",
"self",
".",
"request",
"(",
"self",
".",
"access_token_url",
",",
"method",
"=",
"\"GET\"",
",",
"params",
"=",
"params",
")"
] | Foursquare does not accept POST requests to retrieve an access token,
so we'll be doing a GET request instead. | [
"Foursquare",
"does",
"not",
"accept",
"POST",
"requests",
"to",
"retrieve",
"an",
"access",
"token",
"so",
"we",
"ll",
"be",
"doing",
"a",
"GET",
"request",
"instead",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/contrib/foursquare/client.py#L32-L37 |
flashingpumpkin/django-socialregistration | socialregistration/contrib/openid/templatetags/openid.py | openid_form | def openid_form(parser, token):
"""
Render OpenID form. Allows to pre set the provider::
{% openid_form "https://www.google.com/accounts/o8/id" %}
Also creates custom button URLs by concatenating all arguments
after the provider's URL
{% openid_form "https://www.google.com/accounts/o8/id" S... | python | def openid_form(parser, token):
"""
Render OpenID form. Allows to pre set the provider::
{% openid_form "https://www.google.com/accounts/o8/id" %}
Also creates custom button URLs by concatenating all arguments
after the provider's URL
{% openid_form "https://www.google.com/accounts/o8/id" S... | [
"def",
"openid_form",
"(",
"parser",
",",
"token",
")",
":",
"bits",
"=",
"get_bits",
"(",
"token",
")",
"if",
"len",
"(",
"bits",
")",
">",
"1",
":",
"return",
"FormNode",
"(",
"bits",
"[",
"0",
"]",
",",
"bits",
"[",
"1",
":",
"]",
")",
"if",... | Render OpenID form. Allows to pre set the provider::
{% openid_form "https://www.google.com/accounts/o8/id" %}
Also creates custom button URLs by concatenating all arguments
after the provider's URL
{% openid_form "https://www.google.com/accounts/o8/id" STATIC_URL "image/for/google.jpg" %} | [
"Render",
"OpenID",
"form",
".",
"Allows",
"to",
"pre",
"set",
"the",
"provider",
"::"
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/contrib/openid/templatetags/openid.py#L7-L26 |
flashingpumpkin/django-socialregistration | socialregistration/views.py | Setup.get_initial_data | def get_initial_data(self, request, user, profile, client):
"""
Return initial data for the setup form. The function can be
controlled with ``SOCIALREGISTRATION_INITIAL_DATA_FUNCTION``.
:param request: The current request object
:param user: The unsaved user object
:para... | python | def get_initial_data(self, request, user, profile, client):
"""
Return initial data for the setup form. The function can be
controlled with ``SOCIALREGISTRATION_INITIAL_DATA_FUNCTION``.
:param request: The current request object
:param user: The unsaved user object
:para... | [
"def",
"get_initial_data",
"(",
"self",
",",
"request",
",",
"user",
",",
"profile",
",",
"client",
")",
":",
"if",
"INITAL_DATA_FUNCTION",
":",
"func",
"=",
"self",
".",
"import_attribute",
"(",
"INITAL_DATA_FUNCTION",
")",
"return",
"func",
"(",
"request",
... | Return initial data for the setup form. The function can be
controlled with ``SOCIALREGISTRATION_INITIAL_DATA_FUNCTION``.
:param request: The current request object
:param user: The unsaved user object
:param profile: The unsaved profile object
:param client: The API client | [
"Return",
"initial",
"data",
"for",
"the",
"setup",
"form",
".",
"The",
"function",
"can",
"be",
"controlled",
"with",
"SOCIALREGISTRATION_INITIAL_DATA_FUNCTION",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L55-L68 |
flashingpumpkin/django-socialregistration | socialregistration/views.py | Setup.get_context | def get_context(self, request, user, profile, client):
"""
Return additional context for the setup view. The function can
be controlled with ``SOCIALREGISTRATION_SETUP_CONTEXT_FUNCTION``.
:param request: The current request object
:param user: The unsaved user object
:pa... | python | def get_context(self, request, user, profile, client):
"""
Return additional context for the setup view. The function can
be controlled with ``SOCIALREGISTRATION_SETUP_CONTEXT_FUNCTION``.
:param request: The current request object
:param user: The unsaved user object
:pa... | [
"def",
"get_context",
"(",
"self",
",",
"request",
",",
"user",
",",
"profile",
",",
"client",
")",
":",
"if",
"CONTEXT_FUNCTION",
":",
"func",
"=",
"self",
".",
"import_attribute",
"(",
"CONTEXT_FUNCTION",
")",
"return",
"func",
"(",
"request",
",",
"user... | Return additional context for the setup view. The function can
be controlled with ``SOCIALREGISTRATION_SETUP_CONTEXT_FUNCTION``.
:param request: The current request object
:param user: The unsaved user object
:param profile: The unsaved profile object
:param client: The API clie... | [
"Return",
"additional",
"context",
"for",
"the",
"setup",
"view",
".",
"The",
"function",
"can",
"be",
"controlled",
"with",
"SOCIALREGISTRATION_SETUP_CONTEXT_FUNCTION",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L70-L83 |
flashingpumpkin/django-socialregistration | socialregistration/views.py | Setup.generate_username_and_redirect | def generate_username_and_redirect(self, request, user, profile, client):
"""
Generate a username and then redirect the user to the correct place.
This method is called when ``SOCIALREGISTRATION_GENERATE_USERNAME``
is set.
:param request: The current request object
:pa... | python | def generate_username_and_redirect(self, request, user, profile, client):
"""
Generate a username and then redirect the user to the correct place.
This method is called when ``SOCIALREGISTRATION_GENERATE_USERNAME``
is set.
:param request: The current request object
:pa... | [
"def",
"generate_username_and_redirect",
"(",
"self",
",",
"request",
",",
"user",
",",
"profile",
",",
"client",
")",
":",
"func",
"=",
"self",
".",
"get_username_function",
"(",
")",
"user",
".",
"username",
"=",
"func",
"(",
"user",
",",
"profile",
",",... | Generate a username and then redirect the user to the correct place.
This method is called when ``SOCIALREGISTRATION_GENERATE_USERNAME``
is set.
:param request: The current request object
:param user: The unsaved user object
:param profile: The unsaved profile object
:... | [
"Generate",
"a",
"username",
"and",
"then",
"redirect",
"the",
"user",
"to",
"the",
"correct",
"place",
".",
"This",
"method",
"is",
"called",
"when",
"SOCIALREGISTRATION_GENERATE_USERNAME",
"is",
"set",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L85-L115 |
flashingpumpkin/django-socialregistration | socialregistration/views.py | Setup.get | def get(self, request):
"""
When signing a new user up - either display a setup form, or
generate the username automatically.
"""
if request.user.is_authenticated():
return HttpResponseRedirect(self.get_next(request))
try:
user, profile, client =... | python | def get(self, request):
"""
When signing a new user up - either display a setup form, or
generate the username automatically.
"""
if request.user.is_authenticated():
return HttpResponseRedirect(self.get_next(request))
try:
user, profile, client =... | [
"def",
"get",
"(",
"self",
",",
"request",
")",
":",
"if",
"request",
".",
"user",
".",
"is_authenticated",
"(",
")",
":",
"return",
"HttpResponseRedirect",
"(",
"self",
".",
"get_next",
"(",
"request",
")",
")",
"try",
":",
"user",
",",
"profile",
","... | When signing a new user up - either display a setup form, or
generate the username automatically. | [
"When",
"signing",
"a",
"new",
"user",
"up",
"-",
"either",
"display",
"a",
"setup",
"form",
"or",
"generate",
"the",
"username",
"automatically",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L117-L138 |
flashingpumpkin/django-socialregistration | socialregistration/views.py | Setup.post | def post(self, request):
"""
Save the user and profile, login and send the right signals.
"""
if request.user.is_authenticated():
return self.error_to_response(request, dict(
error=_("You are already logged in.")))
try:
user, profile, cli... | python | def post(self, request):
"""
Save the user and profile, login and send the right signals.
"""
if request.user.is_authenticated():
return self.error_to_response(request, dict(
error=_("You are already logged in.")))
try:
user, profile, cli... | [
"def",
"post",
"(",
"self",
",",
"request",
")",
":",
"if",
"request",
".",
"user",
".",
"is_authenticated",
"(",
")",
":",
"return",
"self",
".",
"error_to_response",
"(",
"request",
",",
"dict",
"(",
"error",
"=",
"_",
"(",
"\"You are already logged in.\... | Save the user and profile, login and send the right signals. | [
"Save",
"the",
"user",
"and",
"profile",
"login",
"and",
"send",
"the",
"right",
"signals",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L140-L174 |
flashingpumpkin/django-socialregistration | socialregistration/views.py | OAuthRedirect.post | def post(self, request):
"""
Create a client, store it in the user's session and redirect the user
to the API provider to authorize our app and permissions.
"""
request.session['next'] = self.get_next(request)
client = self.get_client()()
request.session[self.get_... | python | def post(self, request):
"""
Create a client, store it in the user's session and redirect the user
to the API provider to authorize our app and permissions.
"""
request.session['next'] = self.get_next(request)
client = self.get_client()()
request.session[self.get_... | [
"def",
"post",
"(",
"self",
",",
"request",
")",
":",
"request",
".",
"session",
"[",
"'next'",
"]",
"=",
"self",
".",
"get_next",
"(",
"request",
")",
"client",
"=",
"self",
".",
"get_client",
"(",
")",
"(",
")",
"request",
".",
"session",
"[",
"s... | Create a client, store it in the user's session and redirect the user
to the API provider to authorize our app and permissions. | [
"Create",
"a",
"client",
"store",
"it",
"in",
"the",
"user",
"s",
"session",
"and",
"redirect",
"the",
"user",
"to",
"the",
"API",
"provider",
"to",
"authorize",
"our",
"app",
"and",
"permissions",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L202-L218 |
flashingpumpkin/django-socialregistration | socialregistration/views.py | OAuthCallback.get | def get(self, request):
"""
Called after the user is redirected back to our application.
Tries to:
- Complete the OAuth / OAuth2 flow
- Redirect the user to another view that deals with login, connecting
or user creation.
"""
try:
client ... | python | def get(self, request):
"""
Called after the user is redirected back to our application.
Tries to:
- Complete the OAuth / OAuth2 flow
- Redirect the user to another view that deals with login, connecting
or user creation.
"""
try:
client ... | [
"def",
"get",
"(",
"self",
",",
"request",
")",
":",
"try",
":",
"client",
"=",
"request",
".",
"session",
"[",
"self",
".",
"get_client",
"(",
")",
".",
"get_session_key",
"(",
")",
"]",
"logger",
".",
"debug",
"(",
"\"API returned: %s\"",
",",
"reque... | Called after the user is redirected back to our application.
Tries to:
- Complete the OAuth / OAuth2 flow
- Redirect the user to another view that deals with login, connecting
or user creation. | [
"Called",
"after",
"the",
"user",
"is",
"redirected",
"back",
"to",
"our",
"application",
".",
"Tries",
"to",
":"
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L243-L265 |
flashingpumpkin/django-socialregistration | socialregistration/views.py | SetupCallback.get | def get(self, request):
"""
Called after authorization was granted and the OAuth flow
successfully completed.
Tries to:
- Connect the remote account if the user is logged in already
- Log the user in if a local profile of the remote account
exists a... | python | def get(self, request):
"""
Called after authorization was granted and the OAuth flow
successfully completed.
Tries to:
- Connect the remote account if the user is logged in already
- Log the user in if a local profile of the remote account
exists a... | [
"def",
"get",
"(",
"self",
",",
"request",
")",
":",
"try",
":",
"client",
"=",
"request",
".",
"session",
"[",
"self",
".",
"get_client",
"(",
")",
".",
"get_session_key",
"(",
")",
"]",
"except",
"KeyError",
":",
"return",
"self",
".",
"error_to_resp... | Called after authorization was granted and the OAuth flow
successfully completed.
Tries to:
- Connect the remote account if the user is logged in already
- Log the user in if a local profile of the remote account
exists already
- Create a user and profile o... | [
"Called",
"after",
"authorization",
"was",
"granted",
"and",
"the",
"OAuth",
"flow",
"successfully",
"completed",
".",
"Tries",
"to",
":"
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L273-L348 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth.client | def client(self, verifier=None):
"""
Return the correct client depending on which stage of the OAuth process
we're in.
"""
# We're just starting out and don't have neither request nor access
# token. Return the standard client
if not self._request_token and not se... | python | def client(self, verifier=None):
"""
Return the correct client depending on which stage of the OAuth process
we're in.
"""
# We're just starting out and don't have neither request nor access
# token. Return the standard client
if not self._request_token and not se... | [
"def",
"client",
"(",
"self",
",",
"verifier",
"=",
"None",
")",
":",
"# We're just starting out and don't have neither request nor access",
"# token. Return the standard client",
"if",
"not",
"self",
".",
"_request_token",
"and",
"not",
"self",
".",
"_access_token",
":",... | Return the correct client depending on which stage of the OAuth process
we're in. | [
"Return",
"the",
"correct",
"client",
"depending",
"on",
"which",
"stage",
"of",
"the",
"OAuth",
"process",
"we",
"re",
"in",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L64-L86 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth._get_request_token | def _get_request_token(self):
"""
Fetch a request token from `self.request_token_url`.
"""
params = {
'oauth_callback': self.get_callback_url()
}
response, content = self.client().request(self.request_token_url,
"POST", b... | python | def _get_request_token(self):
"""
Fetch a request token from `self.request_token_url`.
"""
params = {
'oauth_callback': self.get_callback_url()
}
response, content = self.client().request(self.request_token_url,
"POST", b... | [
"def",
"_get_request_token",
"(",
"self",
")",
":",
"params",
"=",
"{",
"'oauth_callback'",
":",
"self",
".",
"get_callback_url",
"(",
")",
"}",
"response",
",",
"content",
"=",
"self",
".",
"client",
"(",
")",
".",
"request",
"(",
"self",
".",
"request_... | Fetch a request token from `self.request_token_url`. | [
"Fetch",
"a",
"request",
"token",
"from",
"self",
".",
"request_token_url",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L88-L110 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth._get_access_token | def _get_access_token(self, verifier=None):
"""
Fetch an access token from `self.access_token_url`.
"""
response, content = self.client(verifier).request(
self.access_token_url, "POST")
content = smart_unicode(content)
if not response['statu... | python | def _get_access_token(self, verifier=None):
"""
Fetch an access token from `self.access_token_url`.
"""
response, content = self.client(verifier).request(
self.access_token_url, "POST")
content = smart_unicode(content)
if not response['statu... | [
"def",
"_get_access_token",
"(",
"self",
",",
"verifier",
"=",
"None",
")",
":",
"response",
",",
"content",
"=",
"self",
".",
"client",
"(",
"verifier",
")",
".",
"request",
"(",
"self",
".",
"access_token_url",
",",
"\"POST\"",
")",
"content",
"=",
"sm... | Fetch an access token from `self.access_token_url`. | [
"Fetch",
"an",
"access",
"token",
"from",
"self",
".",
"access_token_url",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L112-L131 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth.get_request_token | def get_request_token(self):
"""
Return the request token for this API. If we've not fetched it yet,
go out, request and memoize it.
"""
if self._request_token is None:
self._request_token = self._get_request_token()
return self._request_token | python | def get_request_token(self):
"""
Return the request token for this API. If we've not fetched it yet,
go out, request and memoize it.
"""
if self._request_token is None:
self._request_token = self._get_request_token()
return self._request_token | [
"def",
"get_request_token",
"(",
"self",
")",
":",
"if",
"self",
".",
"_request_token",
"is",
"None",
":",
"self",
".",
"_request_token",
"=",
"self",
".",
"_get_request_token",
"(",
")",
"return",
"self",
".",
"_request_token"
] | Return the request token for this API. If we've not fetched it yet,
go out, request and memoize it. | [
"Return",
"the",
"request",
"token",
"for",
"this",
"API",
".",
"If",
"we",
"ve",
"not",
"fetched",
"it",
"yet",
"go",
"out",
"request",
"and",
"memoize",
"it",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L133-L141 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth.get_access_token | def get_access_token(self, verifier=None):
"""
Return the access token for this API. If we've not fetched it yet,
go out, request and memoize it.
"""
if self._access_token is None:
self._access_token, self._access_token_dict = self._get_access_token(verifier)... | python | def get_access_token(self, verifier=None):
"""
Return the access token for this API. If we've not fetched it yet,
go out, request and memoize it.
"""
if self._access_token is None:
self._access_token, self._access_token_dict = self._get_access_token(verifier)... | [
"def",
"get_access_token",
"(",
"self",
",",
"verifier",
"=",
"None",
")",
":",
"if",
"self",
".",
"_access_token",
"is",
"None",
":",
"self",
".",
"_access_token",
",",
"self",
".",
"_access_token_dict",
"=",
"self",
".",
"_get_access_token",
"(",
"verifier... | Return the access token for this API. If we've not fetched it yet,
go out, request and memoize it. | [
"Return",
"the",
"access",
"token",
"for",
"this",
"API",
".",
"If",
"we",
"ve",
"not",
"fetched",
"it",
"yet",
"go",
"out",
"request",
"and",
"memoize",
"it",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L143-L151 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth.get_redirect_url | def get_redirect_url(self, **kwargs):
"""
Return the authorization/authentication URL signed with the request
token.
"""
params = {
'oauth_token': self.get_request_token().key,
}
return '%s?%s' % (self.auth_url, urllib.urlencode(params)) | python | def get_redirect_url(self, **kwargs):
"""
Return the authorization/authentication URL signed with the request
token.
"""
params = {
'oauth_token': self.get_request_token().key,
}
return '%s?%s' % (self.auth_url, urllib.urlencode(params)) | [
"def",
"get_redirect_url",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'oauth_token'",
":",
"self",
".",
"get_request_token",
"(",
")",
".",
"key",
",",
"}",
"return",
"'%s?%s'",
"%",
"(",
"self",
".",
"auth_url",
",",
"urllib"... | Return the authorization/authentication URL signed with the request
token. | [
"Return",
"the",
"authorization",
"/",
"authentication",
"URL",
"signed",
"with",
"the",
"request",
"token",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L154-L162 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth.complete | def complete(self, GET):
"""
When redirect back to our application, try to complete the flow by
requesting an access token. If the access token request fails, it'll
throw an `OAuthError`.
Tries to complete the flow by validating against the `GET` paramters
recei... | python | def complete(self, GET):
"""
When redirect back to our application, try to complete the flow by
requesting an access token. If the access token request fails, it'll
throw an `OAuthError`.
Tries to complete the flow by validating against the `GET` paramters
recei... | [
"def",
"complete",
"(",
"self",
",",
"GET",
")",
":",
"token",
"=",
"self",
".",
"get_access_token",
"(",
"verifier",
"=",
"GET",
".",
"get",
"(",
"'oauth_verifier'",
",",
"None",
")",
")",
"return",
"token"
] | When redirect back to our application, try to complete the flow by
requesting an access token. If the access token request fails, it'll
throw an `OAuthError`.
Tries to complete the flow by validating against the `GET` paramters
received. | [
"When",
"redirect",
"back",
"to",
"our",
"application",
"try",
"to",
"complete",
"the",
"flow",
"by",
"requesting",
"an",
"access",
"token",
".",
"If",
"the",
"access",
"token",
"request",
"fails",
"it",
"ll",
"throw",
"an",
"OAuthError",
".",
"Tries",
"to... | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L164-L174 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth.request | def request(self, url, method="GET", params=None, headers=None):
"""
Make signed requests against `url`.
"""
params = params or {}
headers = headers or {}
logger.debug("URL: %s", url)
logger.debug("Method: %s", method)
logger.debug("Headers: %s", headers)... | python | def request(self, url, method="GET", params=None, headers=None):
"""
Make signed requests against `url`.
"""
params = params or {}
headers = headers or {}
logger.debug("URL: %s", url)
logger.debug("Method: %s", method)
logger.debug("Headers: %s", headers)... | [
"def",
"request",
"(",
"self",
",",
"url",
",",
"method",
"=",
"\"GET\"",
",",
"params",
"=",
"None",
",",
"headers",
"=",
"None",
")",
":",
"params",
"=",
"params",
"or",
"{",
"}",
"headers",
"=",
"headers",
"or",
"{",
"}",
"logger",
".",
"debug",... | Make signed requests against `url`. | [
"Make",
"signed",
"requests",
"against",
"url",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L176-L201 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth2.get_redirect_url | def get_redirect_url(self, state='', **kwargs):
"""
Assemble the URL to where we'll be redirecting the user to to request
permissions.
"""
params = {
'response_type': 'code',
'client_id': self.client_id,
'redirect_uri': self.get_callback_url(**... | python | def get_redirect_url(self, state='', **kwargs):
"""
Assemble the URL to where we'll be redirecting the user to to request
permissions.
"""
params = {
'response_type': 'code',
'client_id': self.client_id,
'redirect_uri': self.get_callback_url(**... | [
"def",
"get_redirect_url",
"(",
"self",
",",
"state",
"=",
"''",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'response_type'",
":",
"'code'",
",",
"'client_id'",
":",
"self",
".",
"client_id",
",",
"'redirect_uri'",
":",
"self",
".",
"get_cal... | Assemble the URL to where we'll be redirecting the user to to request
permissions. | [
"Assemble",
"the",
"URL",
"to",
"where",
"we",
"ll",
"be",
"redirecting",
"the",
"user",
"to",
"to",
"request",
"permissions",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L241-L254 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth2.request_access_token | def request_access_token(self, params):
"""
Request the access token from `self.access_token_url`. The default
behaviour is to use a `POST` request, but some services use `GET`
requests. Individual clients can override this method to use the
correct HTTP method.
"""
... | python | def request_access_token(self, params):
"""
Request the access token from `self.access_token_url`. The default
behaviour is to use a `POST` request, but some services use `GET`
requests. Individual clients can override this method to use the
correct HTTP method.
"""
... | [
"def",
"request_access_token",
"(",
"self",
",",
"params",
")",
":",
"return",
"self",
".",
"request",
"(",
"self",
".",
"access_token_url",
",",
"method",
"=",
"\"POST\"",
",",
"params",
"=",
"params",
",",
"is_signed",
"=",
"False",
")"
] | Request the access token from `self.access_token_url`. The default
behaviour is to use a `POST` request, but some services use `GET`
requests. Individual clients can override this method to use the
correct HTTP method. | [
"Request",
"the",
"access",
"token",
"from",
"self",
".",
"access_token_url",
".",
"The",
"default",
"behaviour",
"is",
"to",
"use",
"a",
"POST",
"request",
"but",
"some",
"services",
"use",
"GET",
"requests",
".",
"Individual",
"clients",
"can",
"override",
... | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L263-L271 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth2._get_access_token | def _get_access_token(self, code, **params):
"""
Fetch an access token with the provided `code`.
"""
params.update({
'code': code,
'client_id': self.client_id,
'client_secret': self.secret,
'redirect_uri': self.get_callback_url(),
}... | python | def _get_access_token(self, code, **params):
"""
Fetch an access token with the provided `code`.
"""
params.update({
'code': code,
'client_id': self.client_id,
'client_secret': self.secret,
'redirect_uri': self.get_callback_url(),
}... | [
"def",
"_get_access_token",
"(",
"self",
",",
"code",
",",
"*",
"*",
"params",
")",
":",
"params",
".",
"update",
"(",
"{",
"'code'",
":",
"code",
",",
"'client_id'",
":",
"self",
".",
"client_id",
",",
"'client_secret'",
":",
"self",
".",
"secret",
",... | Fetch an access token with the provided `code`. | [
"Fetch",
"an",
"access",
"token",
"with",
"the",
"provided",
"code",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L273-L300 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth2.get_access_token | def get_access_token(self, code=None, **params):
"""
Return the memoized access token or go out and fetch one.
"""
if self._access_token is None:
if code is None:
raise ValueError(_('Invalid code.'))
self.access_token_dict = self._get_... | python | def get_access_token(self, code=None, **params):
"""
Return the memoized access token or go out and fetch one.
"""
if self._access_token is None:
if code is None:
raise ValueError(_('Invalid code.'))
self.access_token_dict = self._get_... | [
"def",
"get_access_token",
"(",
"self",
",",
"code",
"=",
"None",
",",
"*",
"*",
"params",
")",
":",
"if",
"self",
".",
"_access_token",
"is",
"None",
":",
"if",
"code",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"_",
"(",
"'Invalid code.'",
")",
... | Return the memoized access token or go out and fetch one. | [
"Return",
"the",
"memoized",
"access",
"token",
"or",
"go",
"out",
"and",
"fetch",
"one",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L302-L316 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth2.complete | def complete(self, GET):
"""
Complete the OAuth2 flow by fetching an access token with the provided
code in the GET parameters.
"""
if 'error' in GET:
raise OAuthError(
_("Received error while obtaining access token from %s: %s") % (
... | python | def complete(self, GET):
"""
Complete the OAuth2 flow by fetching an access token with the provided
code in the GET parameters.
"""
if 'error' in GET:
raise OAuthError(
_("Received error while obtaining access token from %s: %s") % (
... | [
"def",
"complete",
"(",
"self",
",",
"GET",
")",
":",
"if",
"'error'",
"in",
"GET",
":",
"raise",
"OAuthError",
"(",
"_",
"(",
"\"Received error while obtaining access token from %s: %s\"",
")",
"%",
"(",
"self",
".",
"access_token_url",
",",
"GET",
"[",
"'err... | Complete the OAuth2 flow by fetching an access token with the provided
code in the GET parameters. | [
"Complete",
"the",
"OAuth2",
"flow",
"by",
"fetching",
"an",
"access",
"token",
"with",
"the",
"provided",
"code",
"in",
"the",
"GET",
"parameters",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L318-L327 |
flashingpumpkin/django-socialregistration | socialregistration/clients/oauth.py | OAuth2.request | def request(self, url, method="GET", params=None, headers=None, is_signed=True):
"""
Make a request against ``url``. By default, the request is signed with
an access token, but can be turned off by passing ``is_signed=False``.
"""
params = params or {}
headers = headers o... | python | def request(self, url, method="GET", params=None, headers=None, is_signed=True):
"""
Make a request against ``url``. By default, the request is signed with
an access token, but can be turned off by passing ``is_signed=False``.
"""
params = params or {}
headers = headers o... | [
"def",
"request",
"(",
"self",
",",
"url",
",",
"method",
"=",
"\"GET\"",
",",
"params",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"is_signed",
"=",
"True",
")",
":",
"params",
"=",
"params",
"or",
"{",
"}",
"headers",
"=",
"headers",
"or",
"{... | Make a request against ``url``. By default, the request is signed with
an access token, but can be turned off by passing ``is_signed=False``. | [
"Make",
"a",
"request",
"against",
"url",
".",
"By",
"default",
"the",
"request",
"is",
"signed",
"with",
"an",
"access",
"token",
"but",
"can",
"be",
"turned",
"off",
"by",
"passing",
"is_signed",
"=",
"False",
"."
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L337-L351 |
flashingpumpkin/django-socialregistration | socialregistration/contrib/google/client.py | Google.request_access_token | def request_access_token(self, params):
"""
Google requires correct content-type for POST requests
"""
return self.client().request(self.access_token_url, method="POST", body=urllib.urlencode(params), headers={'Content-Type':'application/x-www-form-urlencoded'}) | python | def request_access_token(self, params):
"""
Google requires correct content-type for POST requests
"""
return self.client().request(self.access_token_url, method="POST", body=urllib.urlencode(params), headers={'Content-Type':'application/x-www-form-urlencoded'}) | [
"def",
"request_access_token",
"(",
"self",
",",
"params",
")",
":",
"return",
"self",
".",
"client",
"(",
")",
".",
"request",
"(",
"self",
".",
"access_token_url",
",",
"method",
"=",
"\"POST\"",
",",
"body",
"=",
"urllib",
".",
"urlencode",
"(",
"para... | Google requires correct content-type for POST requests | [
"Google",
"requires",
"correct",
"content",
"-",
"type",
"for",
"POST",
"requests"
] | train | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/contrib/google/client.py#L33-L37 |
adafruit/Adafruit_Python_MAX31855 | Adafruit_MAX31855/MAX31855.py | MAX31855.readInternalC | def readInternalC(self):
"""Return internal temperature value in degrees celsius."""
v = self._read32()
# Ignore bottom 4 bits of thermocouple data.
v >>= 4
# Grab bottom 11 bits as internal temperature data.
internal = v & 0x7FF
if v & 0x800:
# Negati... | python | def readInternalC(self):
"""Return internal temperature value in degrees celsius."""
v = self._read32()
# Ignore bottom 4 bits of thermocouple data.
v >>= 4
# Grab bottom 11 bits as internal temperature data.
internal = v & 0x7FF
if v & 0x800:
# Negati... | [
"def",
"readInternalC",
"(",
"self",
")",
":",
"v",
"=",
"self",
".",
"_read32",
"(",
")",
"# Ignore bottom 4 bits of thermocouple data.",
"v",
">>=",
"4",
"# Grab bottom 11 bits as internal temperature data.",
"internal",
"=",
"v",
"&",
"0x7FF",
"if",
"v",
"&",
"... | Return internal temperature value in degrees celsius. | [
"Return",
"internal",
"temperature",
"value",
"in",
"degrees",
"celsius",
"."
] | train | https://github.com/adafruit/Adafruit_Python_MAX31855/blob/a74832ebcea36487559ec96497398f99fd9355a5/Adafruit_MAX31855/MAX31855.py#L56-L68 |
adafruit/Adafruit_Python_MAX31855 | Adafruit_MAX31855/MAX31855.py | MAX31855.readTempC | def readTempC(self):
"""Return the thermocouple temperature value in degrees celsius."""
v = self._read32()
# Check for error reading value.
if v & 0x7:
return float('NaN')
# Check if signed bit is set.
if v & 0x80000000:
# Negative value, take 2's... | python | def readTempC(self):
"""Return the thermocouple temperature value in degrees celsius."""
v = self._read32()
# Check for error reading value.
if v & 0x7:
return float('NaN')
# Check if signed bit is set.
if v & 0x80000000:
# Negative value, take 2's... | [
"def",
"readTempC",
"(",
"self",
")",
":",
"v",
"=",
"self",
".",
"_read32",
"(",
")",
"# Check for error reading value.",
"if",
"v",
"&",
"0x7",
":",
"return",
"float",
"(",
"'NaN'",
")",
"# Check if signed bit is set.",
"if",
"v",
"&",
"0x80000000",
":",
... | Return the thermocouple temperature value in degrees celsius. | [
"Return",
"the",
"thermocouple",
"temperature",
"value",
"in",
"degrees",
"celsius",
"."
] | train | https://github.com/adafruit/Adafruit_Python_MAX31855/blob/a74832ebcea36487559ec96497398f99fd9355a5/Adafruit_MAX31855/MAX31855.py#L70-L86 |
adafruit/Adafruit_Python_MAX31855 | Adafruit_MAX31855/MAX31855.py | MAX31855.readLinearizedTempC | def readLinearizedTempC(self):
"""Return the NIST-linearized thermocouple temperature value in degrees celsius.
See https://learn.adafruit.com/calibrating-sensors/maxim-31855-linearization for more info.
"""
# MAX31855 thermocouple voltage reading in mV
thermocoupleVoltage = (sel... | python | def readLinearizedTempC(self):
"""Return the NIST-linearized thermocouple temperature value in degrees celsius.
See https://learn.adafruit.com/calibrating-sensors/maxim-31855-linearization for more info.
"""
# MAX31855 thermocouple voltage reading in mV
thermocoupleVoltage = (sel... | [
"def",
"readLinearizedTempC",
"(",
"self",
")",
":",
"# MAX31855 thermocouple voltage reading in mV",
"thermocoupleVoltage",
"=",
"(",
"self",
".",
"readTempC",
"(",
")",
"-",
"self",
".",
"readInternalC",
"(",
")",
")",
"*",
"0.041276",
"# MAX31855 cold junction volt... | Return the NIST-linearized thermocouple temperature value in degrees celsius.
See https://learn.adafruit.com/calibrating-sensors/maxim-31855-linearization for more info. | [
"Return",
"the",
"NIST",
"-",
"linearized",
"thermocouple",
"temperature",
"value",
"in",
"degrees",
"celsius",
".",
"See",
"https",
":",
"//",
"learn",
".",
"adafruit",
".",
"com",
"/",
"calibrating",
"-",
"sensors",
"/",
"maxim",
"-",
"31855",
"-",
"line... | train | https://github.com/adafruit/Adafruit_Python_MAX31855/blob/a74832ebcea36487559ec96497398f99fd9355a5/Adafruit_MAX31855/MAX31855.py#L99-L167 |
geographika/mappyfile | mappyfile/pprint.py | Quoter.escape_quotes | def escape_quotes(self, val):
"""
Escape any quotes in a value
"""
if self.is_string(val) and self._in_quotes(val, self.quote):
# make sure any previously escaped quotes are not re-escaped
middle = self.remove_quotes(val).replace("\\" + self.quote, self.quote)
... | python | def escape_quotes(self, val):
"""
Escape any quotes in a value
"""
if self.is_string(val) and self._in_quotes(val, self.quote):
# make sure any previously escaped quotes are not re-escaped
middle = self.remove_quotes(val).replace("\\" + self.quote, self.quote)
... | [
"def",
"escape_quotes",
"(",
"self",
",",
"val",
")",
":",
"if",
"self",
".",
"is_string",
"(",
"val",
")",
"and",
"self",
".",
"_in_quotes",
"(",
"val",
",",
"self",
".",
"quote",
")",
":",
"# make sure any previously escaped quotes are not re-escaped",
"midd... | Escape any quotes in a value | [
"Escape",
"any",
"quotes",
"in",
"a",
"value"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L46-L56 |
geographika/mappyfile | mappyfile/pprint.py | Quoter.standardise_quotes | def standardise_quotes(self, val):
"""
Change the quotes used to wrap a value to the pprint default
E.g. "val" to 'val' or 'val' to "val"
"""
if self._in_quotes(val, self.altquote):
middle = self.remove_quotes(val)
val = self.add_quotes(middle)
re... | python | def standardise_quotes(self, val):
"""
Change the quotes used to wrap a value to the pprint default
E.g. "val" to 'val' or 'val' to "val"
"""
if self._in_quotes(val, self.altquote):
middle = self.remove_quotes(val)
val = self.add_quotes(middle)
re... | [
"def",
"standardise_quotes",
"(",
"self",
",",
"val",
")",
":",
"if",
"self",
".",
"_in_quotes",
"(",
"val",
",",
"self",
".",
"altquote",
")",
":",
"middle",
"=",
"self",
".",
"remove_quotes",
"(",
"val",
")",
"val",
"=",
"self",
".",
"add_quotes",
... | Change the quotes used to wrap a value to the pprint default
E.g. "val" to 'val' or 'val' to "val" | [
"Change",
"the",
"quotes",
"used",
"to",
"wrap",
"a",
"value",
"to",
"the",
"pprint",
"default",
"E",
".",
"g",
".",
"val",
"to",
"val",
"or",
"val",
"to",
"val"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L91-L100 |
geographika/mappyfile | mappyfile/pprint.py | PrettyPrinter.process_key_dict | def process_key_dict(self, key, d, level):
"""
Process key value dicts e.g. METADATA "key" "value"
"""
# add any composite level comments
comments = d.get("__comments__", {})
lines = []
self._add_type_comment(level, comments, lines)
lines += [self.add_st... | python | def process_key_dict(self, key, d, level):
"""
Process key value dicts e.g. METADATA "key" "value"
"""
# add any composite level comments
comments = d.get("__comments__", {})
lines = []
self._add_type_comment(level, comments, lines)
lines += [self.add_st... | [
"def",
"process_key_dict",
"(",
"self",
",",
"key",
",",
"d",
",",
"level",
")",
":",
"# add any composite level comments",
"comments",
"=",
"d",
".",
"get",
"(",
"\"__comments__\"",
",",
"{",
"}",
")",
"lines",
"=",
"[",
"]",
"self",
".",
"_add_type_comme... | Process key value dicts e.g. METADATA "key" "value" | [
"Process",
"key",
"value",
"dicts",
"e",
".",
"g",
".",
"METADATA",
"key",
"value"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L158-L172 |
geographika/mappyfile | mappyfile/pprint.py | PrettyPrinter.process_dict | def process_dict(self, d, level, comments):
"""
Process keys and values within a block
"""
lines = []
for k, v in d.items():
if not self.__is_metadata(k):
qk = self.quoter.add_quotes(k)
qv = self.quoter.add_quotes(v)
li... | python | def process_dict(self, d, level, comments):
"""
Process keys and values within a block
"""
lines = []
for k, v in d.items():
if not self.__is_metadata(k):
qk = self.quoter.add_quotes(k)
qv = self.quoter.add_quotes(v)
li... | [
"def",
"process_dict",
"(",
"self",
",",
"d",
",",
"level",
",",
"comments",
")",
":",
"lines",
"=",
"[",
"]",
"for",
"k",
",",
"v",
"in",
"d",
".",
"items",
"(",
")",
":",
"if",
"not",
"self",
".",
"__is_metadata",
"(",
"k",
")",
":",
"qk",
... | Process keys and values within a block | [
"Process",
"keys",
"and",
"values",
"within",
"a",
"block"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L174-L188 |
geographika/mappyfile | mappyfile/pprint.py | PrettyPrinter.process_config_dict | def process_config_dict(self, key, d, level):
"""
Process the CONFIG block
"""
lines = []
for k, v in d.items():
k = "CONFIG {}".format(self.quoter.add_quotes(k.upper()))
v = self.quoter.add_quotes(v)
lines.append(self.__format_line(self.whites... | python | def process_config_dict(self, key, d, level):
"""
Process the CONFIG block
"""
lines = []
for k, v in d.items():
k = "CONFIG {}".format(self.quoter.add_quotes(k.upper()))
v = self.quoter.add_quotes(v)
lines.append(self.__format_line(self.whites... | [
"def",
"process_config_dict",
"(",
"self",
",",
"key",
",",
"d",
",",
"level",
")",
":",
"lines",
"=",
"[",
"]",
"for",
"k",
",",
"v",
"in",
"d",
".",
"items",
"(",
")",
":",
"k",
"=",
"\"CONFIG {}\"",
".",
"format",
"(",
"self",
".",
"quoter",
... | Process the CONFIG block | [
"Process",
"the",
"CONFIG",
"block"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L190-L199 |
geographika/mappyfile | mappyfile/pprint.py | PrettyPrinter.process_repeated_list | def process_repeated_list(self, key, lst, level):
"""
Process blocks of repeated keys e.g. FORMATOPTION
"""
lines = []
for v in lst:
k = key.upper()
v = self.quoter.add_quotes(v)
lines.append(self.__format_line(self.whitespace(level, 1), k, v)... | python | def process_repeated_list(self, key, lst, level):
"""
Process blocks of repeated keys e.g. FORMATOPTION
"""
lines = []
for v in lst:
k = key.upper()
v = self.quoter.add_quotes(v)
lines.append(self.__format_line(self.whitespace(level, 1), k, v)... | [
"def",
"process_repeated_list",
"(",
"self",
",",
"key",
",",
"lst",
",",
"level",
")",
":",
"lines",
"=",
"[",
"]",
"for",
"v",
"in",
"lst",
":",
"k",
"=",
"key",
".",
"upper",
"(",
")",
"v",
"=",
"self",
".",
"quoter",
".",
"add_quotes",
"(",
... | Process blocks of repeated keys e.g. FORMATOPTION | [
"Process",
"blocks",
"of",
"repeated",
"keys",
"e",
".",
"g",
".",
"FORMATOPTION"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L201-L212 |
geographika/mappyfile | mappyfile/pprint.py | PrettyPrinter.format_pair_list | def format_pair_list(self, key, pair_list, level):
"""
Process lists of pairs (e.g. PATTERN block)
"""
lines = [self.add_start_line(key, level)]
list_spacer = self.spacer * (level + 2)
pairs = ["{}{} {}".format(list_spacer, p[0], p[1]) for p in pair_list]
lines ... | python | def format_pair_list(self, key, pair_list, level):
"""
Process lists of pairs (e.g. PATTERN block)
"""
lines = [self.add_start_line(key, level)]
list_spacer = self.spacer * (level + 2)
pairs = ["{}{} {}".format(list_spacer, p[0], p[1]) for p in pair_list]
lines ... | [
"def",
"format_pair_list",
"(",
"self",
",",
"key",
",",
"pair_list",
",",
"level",
")",
":",
"lines",
"=",
"[",
"self",
".",
"add_start_line",
"(",
"key",
",",
"level",
")",
"]",
"list_spacer",
"=",
"self",
".",
"spacer",
"*",
"(",
"level",
"+",
"2"... | Process lists of pairs (e.g. PATTERN block) | [
"Process",
"lists",
"of",
"pairs",
"(",
"e",
".",
"g",
".",
"PATTERN",
"block",
")"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L232-L245 |
geographika/mappyfile | mappyfile/pprint.py | PrettyPrinter.format_repeated_pair_list | def format_repeated_pair_list(self, key, root_list, level):
"""
Process (possibly) repeated lists of pairs e.g. POINTs blocks
"""
lines = []
def depth(L):
return isinstance(L, (tuple, list)) and max(map(depth, L)) + 1
if depth(root_list) == 2:
#... | python | def format_repeated_pair_list(self, key, root_list, level):
"""
Process (possibly) repeated lists of pairs e.g. POINTs blocks
"""
lines = []
def depth(L):
return isinstance(L, (tuple, list)) and max(map(depth, L)) + 1
if depth(root_list) == 2:
#... | [
"def",
"format_repeated_pair_list",
"(",
"self",
",",
"key",
",",
"root_list",
",",
"level",
")",
":",
"lines",
"=",
"[",
"]",
"def",
"depth",
"(",
"L",
")",
":",
"return",
"isinstance",
"(",
"L",
",",
"(",
"tuple",
",",
"list",
")",
")",
"and",
"m... | Process (possibly) repeated lists of pairs e.g. POINTs blocks | [
"Process",
"(",
"possibly",
")",
"repeated",
"lists",
"of",
"pairs",
"e",
".",
"g",
".",
"POINTs",
"blocks"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L247-L264 |
geographika/mappyfile | mappyfile/pprint.py | PrettyPrinter.is_hidden_container | def is_hidden_container(self, key, val):
"""
The key is not one of the Mapfile keywords, and its
values are a list
"""
if key in ("layers", "classes", "styles", "symbols", "labels",
"outputformats", "features", "scaletokens",
"composites") a... | python | def is_hidden_container(self, key, val):
"""
The key is not one of the Mapfile keywords, and its
values are a list
"""
if key in ("layers", "classes", "styles", "symbols", "labels",
"outputformats", "features", "scaletokens",
"composites") a... | [
"def",
"is_hidden_container",
"(",
"self",
",",
"key",
",",
"val",
")",
":",
"if",
"key",
"in",
"(",
"\"layers\"",
",",
"\"classes\"",
",",
"\"styles\"",
",",
"\"symbols\"",
",",
"\"labels\"",
",",
"\"outputformats\"",
",",
"\"features\"",
",",
"\"scaletokens\... | The key is not one of the Mapfile keywords, and its
values are a list | [
"The",
"key",
"is",
"not",
"one",
"of",
"the",
"Mapfile",
"keywords",
"and",
"its",
"values",
"are",
"a",
"list"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L273-L284 |
geographika/mappyfile | mappyfile/pprint.py | PrettyPrinter.pprint | def pprint(self, composites):
"""
Print out a nicely indented Mapfile
"""
# if only a single composite is used then cast to list
# and allow for multiple root composites
if composites and not isinstance(composites, list):
composites = [composites]
l... | python | def pprint(self, composites):
"""
Print out a nicely indented Mapfile
"""
# if only a single composite is used then cast to list
# and allow for multiple root composites
if composites and not isinstance(composites, list):
composites = [composites]
l... | [
"def",
"pprint",
"(",
"self",
",",
"composites",
")",
":",
"# if only a single composite is used then cast to list",
"# and allow for multiple root composites",
"if",
"composites",
"and",
"not",
"isinstance",
"(",
"composites",
",",
"list",
")",
":",
"composites",
"=",
... | Print out a nicely indented Mapfile | [
"Print",
"out",
"a",
"nicely",
"indented",
"Mapfile"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L286-L308 |
geographika/mappyfile | mappyfile/pprint.py | PrettyPrinter.format_value | def format_value(self, attr, attr_props, value):
"""
TODO - refactor and add more specific tests (particularly for expressions)
"""
if isinstance(value, bool):
return str(value).upper()
if any(i in ["enum"] for i in attr_props):
if not isinstance(value, n... | python | def format_value(self, attr, attr_props, value):
"""
TODO - refactor and add more specific tests (particularly for expressions)
"""
if isinstance(value, bool):
return str(value).upper()
if any(i in ["enum"] for i in attr_props):
if not isinstance(value, n... | [
"def",
"format_value",
"(",
"self",
",",
"attr",
",",
"attr_props",
",",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"return",
"str",
"(",
"value",
")",
".",
"upper",
"(",
")",
"if",
"any",
"(",
"i",
"in",
"[",
"\"... | TODO - refactor and add more specific tests (particularly for expressions) | [
"TODO",
"-",
"refactor",
"and",
"add",
"more",
"specific",
"tests",
"(",
"particularly",
"for",
"expressions",
")"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L346-L401 |
geographika/mappyfile | mappyfile/pprint.py | PrettyPrinter.process_attribute | def process_attribute(self, type_, attr, value, level):
"""
Process one of the main composite types (see the type_ value)
"""
attr_props = self.get_attribute_properties(type_, attr)
value = self.format_value(attr, attr_props, value)
line = self.__format_line(self.whitesp... | python | def process_attribute(self, type_, attr, value, level):
"""
Process one of the main composite types (see the type_ value)
"""
attr_props = self.get_attribute_properties(type_, attr)
value = self.format_value(attr, attr_props, value)
line = self.__format_line(self.whitesp... | [
"def",
"process_attribute",
"(",
"self",
",",
"type_",
",",
"attr",
",",
"value",
",",
"level",
")",
":",
"attr_props",
"=",
"self",
".",
"get_attribute_properties",
"(",
"type_",
",",
"attr",
")",
"value",
"=",
"self",
".",
"format_value",
"(",
"attr",
... | Process one of the main composite types (see the type_ value) | [
"Process",
"one",
"of",
"the",
"main",
"composite",
"types",
"(",
"see",
"the",
"type_",
"value",
")"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L403-L412 |
geographika/mappyfile | mappyfile/pprint.py | PrettyPrinter.process_composite_comment | def process_composite_comment(self, level, comments, key):
"""
Process comments for composites such as MAP, LAYER etc.
"""
if key not in comments:
comment = ""
else:
value = comments[key]
spacer = self.whitespace(level, 0)
if isins... | python | def process_composite_comment(self, level, comments, key):
"""
Process comments for composites such as MAP, LAYER etc.
"""
if key not in comments:
comment = ""
else:
value = comments[key]
spacer = self.whitespace(level, 0)
if isins... | [
"def",
"process_composite_comment",
"(",
"self",
",",
"level",
",",
"comments",
",",
"key",
")",
":",
"if",
"key",
"not",
"in",
"comments",
":",
"comment",
"=",
"\"\"",
"else",
":",
"value",
"=",
"comments",
"[",
"key",
"]",
"spacer",
"=",
"self",
".",... | Process comments for composites such as MAP, LAYER etc. | [
"Process",
"comments",
"for",
"composites",
"such",
"as",
"MAP",
"LAYER",
"etc",
"."
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L417-L433 |
geographika/mappyfile | docs/examples/animation/animated_buffer.py | create_animation | def create_animation(img_files):
"""
See http://pillow.readthedocs.io/en/4.2.x/handbook/image-file-formats.html?highlight=append_images#saving
"""
open_images = []
for fn in img_files:
print(fn)
im = Image.open(fn)
open_images.append(im)
im = open_images[0]
im.save... | python | def create_animation(img_files):
"""
See http://pillow.readthedocs.io/en/4.2.x/handbook/image-file-formats.html?highlight=append_images#saving
"""
open_images = []
for fn in img_files:
print(fn)
im = Image.open(fn)
open_images.append(im)
im = open_images[0]
im.save... | [
"def",
"create_animation",
"(",
"img_files",
")",
":",
"open_images",
"=",
"[",
"]",
"for",
"fn",
"in",
"img_files",
":",
"print",
"(",
"fn",
")",
"im",
"=",
"Image",
".",
"open",
"(",
"fn",
")",
"open_images",
".",
"append",
"(",
"im",
")",
"im",
... | See http://pillow.readthedocs.io/en/4.2.x/handbook/image-file-formats.html?highlight=append_images#saving | [
"See",
"http",
":",
"//",
"pillow",
".",
"readthedocs",
".",
"io",
"/",
"en",
"/",
"4",
".",
"2",
".",
"x",
"/",
"handbook",
"/",
"image",
"-",
"file",
"-",
"formats",
".",
"html?highlight",
"=",
"append_images#saving"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/docs/examples/animation/animated_buffer.py#L44-L57 |
geographika/mappyfile | mappyfile/transformer.py | MapfileTransformer.start | def start(self, children):
"""
Parses a MapServer Mapfile
Parsing of partial Mapfiles or lists of composites is also possible
"""
composites = []
for composite_dict in children:
if False and self.include_position:
key_token = composite_dict[1... | python | def start(self, children):
"""
Parses a MapServer Mapfile
Parsing of partial Mapfiles or lists of composites is also possible
"""
composites = []
for composite_dict in children:
if False and self.include_position:
key_token = composite_dict[1... | [
"def",
"start",
"(",
"self",
",",
"children",
")",
":",
"composites",
"=",
"[",
"]",
"for",
"composite_dict",
"in",
"children",
":",
"if",
"False",
"and",
"self",
".",
"include_position",
":",
"key_token",
"=",
"composite_dict",
"[",
"1",
"]",
"key_name",
... | Parses a MapServer Mapfile
Parsing of partial Mapfiles or lists of composites is also possible | [
"Parses",
"a",
"MapServer",
"Mapfile",
"Parsing",
"of",
"partial",
"Mapfiles",
"or",
"lists",
"of",
"composites",
"is",
"also",
"possible"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/transformer.py#L38-L60 |
geographika/mappyfile | mappyfile/transformer.py | MapfileTransformer.composite | def composite(self, t):
"""
Handle the composite types e.g. CLASS..END
t is a list in the form [[Token(__LAYER36, 'LAYER')], [OrderedDict([...])]]
"""
if len(t) == 1:
return t[0] # metadata and values - already processed
key_token = t[0][0]
attribut... | python | def composite(self, t):
"""
Handle the composite types e.g. CLASS..END
t is a list in the form [[Token(__LAYER36, 'LAYER')], [OrderedDict([...])]]
"""
if len(t) == 1:
return t[0] # metadata and values - already processed
key_token = t[0][0]
attribut... | [
"def",
"composite",
"(",
"self",
",",
"t",
")",
":",
"if",
"len",
"(",
"t",
")",
"==",
"1",
":",
"return",
"t",
"[",
"0",
"]",
"# metadata and values - already processed",
"key_token",
"=",
"t",
"[",
"0",
"]",
"[",
"0",
"]",
"attribute_dicts",
"=",
"... | Handle the composite types e.g. CLASS..END
t is a list in the form [[Token(__LAYER36, 'LAYER')], [OrderedDict([...])]] | [
"Handle",
"the",
"composite",
"types",
"e",
".",
"g",
".",
"CLASS",
"..",
"END",
"t",
"is",
"a",
"list",
"in",
"the",
"form",
"[[",
"Token",
"(",
"__LAYER36",
"LAYER",
")",
"]",
"[",
"OrderedDict",
"(",
"[",
"...",
"]",
")",
"]]"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/transformer.py#L122-L234 |
geographika/mappyfile | mappyfile/transformer.py | MapfileTransformer.check_composite_tokens | def check_composite_tokens(self, name, tokens):
"""
Return the key and contents of a KEY..END block
for PATTERN, POINTS, and PROJECTION
"""
assert len(tokens) >= 2
key = tokens[0]
assert key.value.lower() == name
assert tokens[-1].value.lower() == "end"
... | python | def check_composite_tokens(self, name, tokens):
"""
Return the key and contents of a KEY..END block
for PATTERN, POINTS, and PROJECTION
"""
assert len(tokens) >= 2
key = tokens[0]
assert key.value.lower() == name
assert tokens[-1].value.lower() == "end"
... | [
"def",
"check_composite_tokens",
"(",
"self",
",",
"name",
",",
"tokens",
")",
":",
"assert",
"len",
"(",
"tokens",
")",
">=",
"2",
"key",
"=",
"tokens",
"[",
"0",
"]",
"assert",
"key",
".",
"value",
".",
"lower",
"(",
")",
"==",
"name",
"assert",
... | Return the key and contents of a KEY..END block
for PATTERN, POINTS, and PROJECTION | [
"Return",
"the",
"key",
"and",
"contents",
"of",
"a",
"KEY",
"..",
"END",
"block",
"for",
"PATTERN",
"POINTS",
"and",
"PROJECTION"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/transformer.py#L293-L316 |
geographika/mappyfile | mappyfile/transformer.py | MapfileTransformer.process_value_pairs | def process_value_pairs(self, tokens, type_):
"""
Metadata, Values, and Validation blocks can either
have string pairs or attributes
Attributes will already be processed
"""
key, body = self.check_composite_tokens(type_, tokens)
key_name = self.key_name(key)
... | python | def process_value_pairs(self, tokens, type_):
"""
Metadata, Values, and Validation blocks can either
have string pairs or attributes
Attributes will already be processed
"""
key, body = self.check_composite_tokens(type_, tokens)
key_name = self.key_name(key)
... | [
"def",
"process_value_pairs",
"(",
"self",
",",
"tokens",
",",
"type_",
")",
":",
"key",
",",
"body",
"=",
"self",
".",
"check_composite_tokens",
"(",
"type_",
",",
"tokens",
")",
"key_name",
"=",
"self",
".",
"key_name",
"(",
"key",
")",
"d",
"=",
"Ca... | Metadata, Values, and Validation blocks can either
have string pairs or attributes
Attributes will already be processed | [
"Metadata",
"Values",
"and",
"Validation",
"blocks",
"can",
"either",
"have",
"string",
"pairs",
"or",
"attributes",
"Attributes",
"will",
"already",
"be",
"processed"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/transformer.py#L318-L347 |
geographika/mappyfile | mappyfile/transformer.py | MapfileTransformer.func_call | def func_call(self, t):
"""
For function calls e.g. TEXT (tostring([area],"%.2f"))
"""
func, params = t
func_name = func.value
func.value = "({}({}))".format(func_name, params)
return func | python | def func_call(self, t):
"""
For function calls e.g. TEXT (tostring([area],"%.2f"))
"""
func, params = t
func_name = func.value
func.value = "({}({}))".format(func_name, params)
return func | [
"def",
"func_call",
"(",
"self",
",",
"t",
")",
":",
"func",
",",
"params",
"=",
"t",
"func_name",
"=",
"func",
".",
"value",
"func",
".",
"value",
"=",
"\"({}({}))\"",
".",
"format",
"(",
"func_name",
",",
"params",
")",
"return",
"func"
] | For function calls e.g. TEXT (tostring([area],"%.2f")) | [
"For",
"function",
"calls",
"e",
".",
"g",
".",
"TEXT",
"(",
"tostring",
"(",
"[",
"area",
"]",
"%",
".",
"2f",
"))"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/transformer.py#L484-L491 |
geographika/mappyfile | mappyfile/transformer.py | CommentsTransformer.add_metadata_comments | def add_metadata_comments(self, d, metadata):
"""
Any duplicate keys will be replaced with the last duplicate along with comments
"""
if len(metadata) > 2:
string_pairs = metadata[1:-1] # get all metadata pairs
for sp in string_pairs:
# get the r... | python | def add_metadata_comments(self, d, metadata):
"""
Any duplicate keys will be replaced with the last duplicate along with comments
"""
if len(metadata) > 2:
string_pairs = metadata[1:-1] # get all metadata pairs
for sp in string_pairs:
# get the r... | [
"def",
"add_metadata_comments",
"(",
"self",
",",
"d",
",",
"metadata",
")",
":",
"if",
"len",
"(",
"metadata",
")",
">",
"2",
":",
"string_pairs",
"=",
"metadata",
"[",
"1",
":",
"-",
"1",
"]",
"# get all metadata pairs",
"for",
"sp",
"in",
"string_pair... | Any duplicate keys will be replaced with the last duplicate along with comments | [
"Any",
"duplicate",
"keys",
"will",
"be",
"replaced",
"with",
"the",
"last",
"duplicate",
"along",
"with",
"comments"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/transformer.py#L605-L630 |
geographika/mappyfile | mappyfile/parser.py | Parser.assign_comments | def assign_comments(self, tree, comments):
"""
Capture any comments in the tree
header_comments stores comments preceding a node
"""
comments = list(comments)
comments.sort(key=lambda c: c.line)
idx_by_line = {0: 0} # {line_no: comment_idx}
for i, c i... | python | def assign_comments(self, tree, comments):
"""
Capture any comments in the tree
header_comments stores comments preceding a node
"""
comments = list(comments)
comments.sort(key=lambda c: c.line)
idx_by_line = {0: 0} # {line_no: comment_idx}
for i, c i... | [
"def",
"assign_comments",
"(",
"self",
",",
"tree",
",",
"comments",
")",
":",
"comments",
"=",
"list",
"(",
"comments",
")",
"comments",
".",
"sort",
"(",
"key",
"=",
"lambda",
"c",
":",
"c",
".",
"line",
")",
"idx_by_line",
"=",
"{",
"0",
":",
"0... | Capture any comments in the tree
header_comments stores comments preceding a node | [
"Capture",
"any",
"comments",
"in",
"the",
"tree"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/parser.py#L80-L116 |
geographika/mappyfile | mappyfile/parser.py | Parser.parse | def parse(self, text, fn=None):
"""
Parse the Mapfile
"""
if PY2 and not isinstance(text, unicode):
# specify Unicode for Python 2.7
text = unicode(text, 'utf-8')
if self.expand_includes:
text = self.load_includes(text, fn=fn)
try:
... | python | def parse(self, text, fn=None):
"""
Parse the Mapfile
"""
if PY2 and not isinstance(text, unicode):
# specify Unicode for Python 2.7
text = unicode(text, 'utf-8')
if self.expand_includes:
text = self.load_includes(text, fn=fn)
try:
... | [
"def",
"parse",
"(",
"self",
",",
"text",
",",
"fn",
"=",
"None",
")",
":",
"if",
"PY2",
"and",
"not",
"isinstance",
"(",
"text",
",",
"unicode",
")",
":",
"# specify Unicode for Python 2.7",
"text",
"=",
"unicode",
"(",
"text",
",",
"'utf-8'",
")",
"i... | Parse the Mapfile | [
"Parse",
"the",
"Mapfile"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/parser.py#L184-L208 |
geographika/mappyfile | docs/scripts/class_diagrams.py | add_child | def add_child(graph, child_id, child_label, parent_id, colour):
"""
http://www.graphviz.org/doc/info/shapes.html#polygon
"""
node = pydot.Node(child_id, style="filled", fillcolor=colour, label=child_label, shape="polygon", fontname=FONT)
graph.add_node(node)
graph.add_edge(pydot.Edge(parent_id, ... | python | def add_child(graph, child_id, child_label, parent_id, colour):
"""
http://www.graphviz.org/doc/info/shapes.html#polygon
"""
node = pydot.Node(child_id, style="filled", fillcolor=colour, label=child_label, shape="polygon", fontname=FONT)
graph.add_node(node)
graph.add_edge(pydot.Edge(parent_id, ... | [
"def",
"add_child",
"(",
"graph",
",",
"child_id",
",",
"child_label",
",",
"parent_id",
",",
"colour",
")",
":",
"node",
"=",
"pydot",
".",
"Node",
"(",
"child_id",
",",
"style",
"=",
"\"filled\"",
",",
"fillcolor",
"=",
"colour",
",",
"label",
"=",
"... | http://www.graphviz.org/doc/info/shapes.html#polygon | [
"http",
":",
"//",
"www",
".",
"graphviz",
".",
"org",
"/",
"doc",
"/",
"info",
"/",
"shapes",
".",
"html#polygon"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/docs/scripts/class_diagrams.py#L23-L29 |
geographika/mappyfile | mappyfile/validator.py | Validator.get_schema_path | def get_schema_path(self, schemas_folder):
"""
Return a file protocol URI e.g. file:///D:/mappyfile/mappyfile/schemas/ on Windows
and file:////home/user/mappyfile/mappyfile/schemas/ on Linux
"""
# replace any Windows path back slashes with forward slashes
schemas_folder ... | python | def get_schema_path(self, schemas_folder):
"""
Return a file protocol URI e.g. file:///D:/mappyfile/mappyfile/schemas/ on Windows
and file:////home/user/mappyfile/mappyfile/schemas/ on Linux
"""
# replace any Windows path back slashes with forward slashes
schemas_folder ... | [
"def",
"get_schema_path",
"(",
"self",
",",
"schemas_folder",
")",
":",
"# replace any Windows path back slashes with forward slashes",
"schemas_folder",
"=",
"schemas_folder",
".",
"replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
")",
"# HACK Python 2.7 on Linux seems to remove the r... | Return a file protocol URI e.g. file:///D:/mappyfile/mappyfile/schemas/ on Windows
and file:////home/user/mappyfile/mappyfile/schemas/ on Linux | [
"Return",
"a",
"file",
"protocol",
"URI",
"e",
".",
"g",
".",
"file",
":",
"///",
"D",
":",
"/",
"mappyfile",
"/",
"mappyfile",
"/",
"schemas",
"/",
"on",
"Windows",
"and",
"file",
":",
"////",
"home",
"/",
"user",
"/",
"mappyfile",
"/",
"mappyfile",... | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/validator.py#L23-L40 |
geographika/mappyfile | mappyfile/validator.py | Validator.get_schema_validator | def get_schema_validator(self, schema_name):
"""
Had to remove the id property from map.json or it uses URLs for validation
See various issues at https://github.com/Julian/jsonschema/pull/306
"""
if schema_name not in self.schemas:
schema_file = self.get_schema_file(... | python | def get_schema_validator(self, schema_name):
"""
Had to remove the id property from map.json or it uses URLs for validation
See various issues at https://github.com/Julian/jsonschema/pull/306
"""
if schema_name not in self.schemas:
schema_file = self.get_schema_file(... | [
"def",
"get_schema_validator",
"(",
"self",
",",
"schema_name",
")",
":",
"if",
"schema_name",
"not",
"in",
"self",
".",
"schemas",
":",
"schema_file",
"=",
"self",
".",
"get_schema_file",
"(",
"schema_name",
")",
"with",
"open",
"(",
"schema_file",
")",
"as... | Had to remove the id property from map.json or it uses URLs for validation
See various issues at https://github.com/Julian/jsonschema/pull/306 | [
"Had",
"to",
"remove",
"the",
"id",
"property",
"from",
"map",
".",
"json",
"or",
"it",
"uses",
"URLs",
"for",
"validation",
"See",
"various",
"issues",
"at",
"https",
":",
"//",
"github",
".",
"com",
"/",
"Julian",
"/",
"jsonschema",
"/",
"pull",
"/",... | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/validator.py#L56-L82 |
geographika/mappyfile | mappyfile/validator.py | Validator.create_message | def create_message(self, rootdict, path, error, add_comments):
"""
Add a validation comment to the dictionary
path is the path to the error object, it can be empty if the error is in the root object
http://python-jsonschema.readthedocs.io/en/latest/errors/#jsonschema.exceptions.Validatio... | python | def create_message(self, rootdict, path, error, add_comments):
"""
Add a validation comment to the dictionary
path is the path to the error object, it can be empty if the error is in the root object
http://python-jsonschema.readthedocs.io/en/latest/errors/#jsonschema.exceptions.Validatio... | [
"def",
"create_message",
"(",
"self",
",",
"rootdict",
",",
"path",
",",
"error",
",",
"add_comments",
")",
":",
"if",
"not",
"path",
":",
"# error applies to the root type",
"d",
"=",
"rootdict",
"key",
"=",
"d",
"[",
"\"__type__\"",
"]",
"elif",
"isinstanc... | Add a validation comment to the dictionary
path is the path to the error object, it can be empty if the error is in the root object
http://python-jsonschema.readthedocs.io/en/latest/errors/#jsonschema.exceptions.ValidationError.absolute_path
It can also reference an object in a list e.g. [u'laye... | [
"Add",
"a",
"validation",
"comment",
"to",
"the",
"dictionary",
"path",
"is",
"the",
"path",
"to",
"the",
"error",
"object",
"it",
"can",
"be",
"empty",
"if",
"the",
"error",
"is",
"in",
"the",
"root",
"object",
"http",
":",
"//",
"python",
"-",
"jsons... | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/validator.py#L96-L146 |
geographika/mappyfile | mappyfile/validator.py | Validator.validate | def validate(self, value, add_comments=False, schema_name="map"):
"""
verbose - also return the jsonschema error details
"""
validator = self.get_schema_validator(schema_name)
error_messages = []
if isinstance(value, list):
for d in value:
er... | python | def validate(self, value, add_comments=False, schema_name="map"):
"""
verbose - also return the jsonschema error details
"""
validator = self.get_schema_validator(schema_name)
error_messages = []
if isinstance(value, list):
for d in value:
er... | [
"def",
"validate",
"(",
"self",
",",
"value",
",",
"add_comments",
"=",
"False",
",",
"schema_name",
"=",
"\"map\"",
")",
":",
"validator",
"=",
"self",
".",
"get_schema_validator",
"(",
"schema_name",
")",
"error_messages",
"=",
"[",
"]",
"if",
"isinstance"... | verbose - also return the jsonschema error details | [
"verbose",
"-",
"also",
"return",
"the",
"jsonschema",
"error",
"details"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/validator.py#L169-L183 |
geographika/mappyfile | mappyfile/validator.py | Validator.get_expanded_schema | def get_expanded_schema(self, schema_name):
"""
Return a schema file with all $ref properties expanded
"""
if schema_name not in self.expanded_schemas:
fn = self.get_schema_file(schema_name)
schemas_folder = self.get_schemas_folder()
base_uri = self.ge... | python | def get_expanded_schema(self, schema_name):
"""
Return a schema file with all $ref properties expanded
"""
if schema_name not in self.expanded_schemas:
fn = self.get_schema_file(schema_name)
schemas_folder = self.get_schemas_folder()
base_uri = self.ge... | [
"def",
"get_expanded_schema",
"(",
"self",
",",
"schema_name",
")",
":",
"if",
"schema_name",
"not",
"in",
"self",
".",
"expanded_schemas",
":",
"fn",
"=",
"self",
".",
"get_schema_file",
"(",
"schema_name",
")",
"schemas_folder",
"=",
"self",
".",
"get_schema... | Return a schema file with all $ref properties expanded | [
"Return",
"a",
"schema",
"file",
"with",
"all",
"$ref",
"properties",
"expanded"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/validator.py#L185-L202 |
geographika/mappyfile | docs/examples/parsing.py | output | def output(s):
"""
Parse, transform, and pretty print
the result
"""
p = Parser()
t = ExpressionsTransformer()
ast = p.parse(s)
logging.debug(ast.pretty())
print(ast.pretty())
d = t.transform(ast)
print(json.dumps(d, indent=4))
return d | python | def output(s):
"""
Parse, transform, and pretty print
the result
"""
p = Parser()
t = ExpressionsTransformer()
ast = p.parse(s)
logging.debug(ast.pretty())
print(ast.pretty())
d = t.transform(ast)
print(json.dumps(d, indent=4))
return d | [
"def",
"output",
"(",
"s",
")",
":",
"p",
"=",
"Parser",
"(",
")",
"t",
"=",
"ExpressionsTransformer",
"(",
")",
"ast",
"=",
"p",
".",
"parse",
"(",
"s",
")",
"logging",
".",
"debug",
"(",
"ast",
".",
"pretty",
"(",
")",
")",
"print",
"(",
"ast... | Parse, transform, and pretty print
the result | [
"Parse",
"transform",
"and",
"pretty",
"print",
"the",
"result"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/docs/examples/parsing.py#L117-L130 |
geographika/mappyfile | docs/examples/parsing.py | ExpressionsTransformer.comparison | def comparison(self, t):
"""
<PropertyIsEqualTo>
<PropertyName>NAME</PropertyName>
<Literal>Sydney</Literal>
</PropertyIsEqualTo>
"""
assert(len(t) == 3)
d = {"PropertyIsEqualTo": [
t[0], t[1], t[2]
]}
#parts = [str(p.value) for p in t]
... | python | def comparison(self, t):
"""
<PropertyIsEqualTo>
<PropertyName>NAME</PropertyName>
<Literal>Sydney</Literal>
</PropertyIsEqualTo>
"""
assert(len(t) == 3)
d = {"PropertyIsEqualTo": [
t[0], t[1], t[2]
]}
#parts = [str(p.value) for p in t]
... | [
"def",
"comparison",
"(",
"self",
",",
"t",
")",
":",
"assert",
"(",
"len",
"(",
"t",
")",
"==",
"3",
")",
"d",
"=",
"{",
"\"PropertyIsEqualTo\"",
":",
"[",
"t",
"[",
"0",
"]",
",",
"t",
"[",
"1",
"]",
",",
"t",
"[",
"2",
"]",
"]",
"}",
"... | <PropertyIsEqualTo>
<PropertyName>NAME</PropertyName>
<Literal>Sydney</Literal>
</PropertyIsEqualTo> | [
"<PropertyIsEqualTo",
">",
"<PropertyName",
">",
"NAME<",
"/",
"PropertyName",
">",
"<Literal",
">",
"Sydney<",
"/",
"Literal",
">",
"<",
"/",
"PropertyIsEqualTo",
">"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/docs/examples/parsing.py#L76-L95 |
geographika/mappyfile | mappyfile/cli.py | main | def main(ctx, verbose, quiet):
"""
Execute the main mappyfile command
"""
verbosity = verbose - quiet
configure_logging(verbosity)
ctx.obj = {}
ctx.obj['verbosity'] = verbosity | python | def main(ctx, verbose, quiet):
"""
Execute the main mappyfile command
"""
verbosity = verbose - quiet
configure_logging(verbosity)
ctx.obj = {}
ctx.obj['verbosity'] = verbosity | [
"def",
"main",
"(",
"ctx",
",",
"verbose",
",",
"quiet",
")",
":",
"verbosity",
"=",
"verbose",
"-",
"quiet",
"configure_logging",
"(",
"verbosity",
")",
"ctx",
".",
"obj",
"=",
"{",
"}",
"ctx",
".",
"obj",
"[",
"'verbosity'",
"]",
"=",
"verbosity"
] | Execute the main mappyfile command | [
"Execute",
"the",
"main",
"mappyfile",
"command"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/cli.py#L41-L48 |
geographika/mappyfile | mappyfile/cli.py | format | def format(ctx, input_mapfile, output_mapfile, indent, spacer, quote, newlinechar, expand, comments):
"""
Format a the input-mapfile and save as output-mapfile. Note output-mapfile will be
overwritten if it already exists.
Example of formatting a single Mapfile:
mappyfile format C:/Temp/valid.... | python | def format(ctx, input_mapfile, output_mapfile, indent, spacer, quote, newlinechar, expand, comments):
"""
Format a the input-mapfile and save as output-mapfile. Note output-mapfile will be
overwritten if it already exists.
Example of formatting a single Mapfile:
mappyfile format C:/Temp/valid.... | [
"def",
"format",
"(",
"ctx",
",",
"input_mapfile",
",",
"output_mapfile",
",",
"indent",
",",
"spacer",
",",
"quote",
",",
"newlinechar",
",",
"expand",
",",
"comments",
")",
":",
"quote",
"=",
"codecs",
".",
"decode",
"(",
"quote",
",",
"'unicode_escape'"... | Format a the input-mapfile and save as output-mapfile. Note output-mapfile will be
overwritten if it already exists.
Example of formatting a single Mapfile:
mappyfile format C:/Temp/valid.map C:/Temp/valid_formatted.map
Example of formatting a single Mapfile with single quotes and tabs for indent... | [
"Format",
"a",
"the",
"input",
"-",
"mapfile",
"and",
"save",
"as",
"output",
"-",
"mapfile",
".",
"Note",
"output",
"-",
"mapfile",
"will",
"be",
"overwritten",
"if",
"it",
"already",
"exists",
"."
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/cli.py#L61-L85 |
geographika/mappyfile | mappyfile/cli.py | validate | def validate(ctx, mapfiles, expand):
"""
Validate Mapfile(s) against the Mapfile schema
The MAPFILES argument is a list of paths, either to individual Mapfiles, or a folders containing Mapfiles.
Wildcards are supported (natively on Linux, and up to one level deep on Windows).
Validation errors are ... | python | def validate(ctx, mapfiles, expand):
"""
Validate Mapfile(s) against the Mapfile schema
The MAPFILES argument is a list of paths, either to individual Mapfiles, or a folders containing Mapfiles.
Wildcards are supported (natively on Linux, and up to one level deep on Windows).
Validation errors are ... | [
"def",
"validate",
"(",
"ctx",
",",
"mapfiles",
",",
"expand",
")",
":",
"all_mapfiles",
"=",
"get_mapfiles",
"(",
"mapfiles",
")",
"if",
"len",
"(",
"all_mapfiles",
")",
"==",
"0",
":",
"click",
".",
"echo",
"(",
"\"No Mapfiles found at the following paths: {... | Validate Mapfile(s) against the Mapfile schema
The MAPFILES argument is a list of paths, either to individual Mapfiles, or a folders containing Mapfiles.
Wildcards are supported (natively on Linux, and up to one level deep on Windows).
Validation errors are reported to the console. The program returns the ... | [
"Validate",
"Mapfile",
"(",
"s",
")",
"against",
"the",
"Mapfile",
"schema"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/cli.py#L92-L135 |
geographika/mappyfile | misc/docs_parser.py | get_keyword | def get_keyword(text):
"""
Accept a string such as BACKGROUNDCOLOR [r] [g] [b]
and return backgroundcolor
"""
first_word = text.split(" ")[0]
if len(first_word) > 1 and first_word.isupper():
kwd = str(first_word.lower())
else:
kwd = None
return kwd | python | def get_keyword(text):
"""
Accept a string such as BACKGROUNDCOLOR [r] [g] [b]
and return backgroundcolor
"""
first_word = text.split(" ")[0]
if len(first_word) > 1 and first_word.isupper():
kwd = str(first_word.lower())
else:
kwd = None
return kwd | [
"def",
"get_keyword",
"(",
"text",
")",
":",
"first_word",
"=",
"text",
".",
"split",
"(",
"\" \"",
")",
"[",
"0",
"]",
"if",
"len",
"(",
"first_word",
")",
">",
"1",
"and",
"first_word",
".",
"isupper",
"(",
")",
":",
"kwd",
"=",
"str",
"(",
"fi... | Accept a string such as BACKGROUNDCOLOR [r] [g] [b]
and return backgroundcolor | [
"Accept",
"a",
"string",
"such",
"as",
"BACKGROUNDCOLOR",
"[",
"r",
"]",
"[",
"g",
"]",
"[",
"b",
"]",
"and",
"return",
"backgroundcolor"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/misc/docs_parser.py#L82-L94 |
geographika/mappyfile | misc/docs_parser.py | get_values | def get_values(text):
"""
Accept a string such as BACKGROUNDCOLOR [r] [g] [b]
and return ['r', 'g', 'b']
"""
res = re.findall(r"\[(.*?)\]", text)
values = []
for r in res:
if "|" in r:
params = r.split("|")
for p in params:
values.append(p)
... | python | def get_values(text):
"""
Accept a string such as BACKGROUNDCOLOR [r] [g] [b]
and return ['r', 'g', 'b']
"""
res = re.findall(r"\[(.*?)\]", text)
values = []
for r in res:
if "|" in r:
params = r.split("|")
for p in params:
values.append(p)
... | [
"def",
"get_values",
"(",
"text",
")",
":",
"res",
"=",
"re",
".",
"findall",
"(",
"r\"\\[(.*?)\\]\"",
",",
"text",
")",
"values",
"=",
"[",
"]",
"for",
"r",
"in",
"res",
":",
"if",
"\"|\"",
"in",
"r",
":",
"params",
"=",
"r",
".",
"split",
"(",
... | Accept a string such as BACKGROUNDCOLOR [r] [g] [b]
and return ['r', 'g', 'b'] | [
"Accept",
"a",
"string",
"such",
"as",
"BACKGROUNDCOLOR",
"[",
"r",
"]",
"[",
"g",
"]",
"[",
"b",
"]",
"and",
"return",
"[",
"r",
"g",
"b",
"]"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/misc/docs_parser.py#L96-L115 |
geographika/mappyfile | misc/docs_parser.py | process_doc | def process_doc(text):
"""
The :ref: role is supported by Sphinx but not by plain docutils
"""
# remove :ref: directives
document = docutils.core.publish_doctree(text) # http://epydoc.sourceforge.net/docutils/private/docutils.nodes.document-class.html
visitor = RefVisitor(document)
document.... | python | def process_doc(text):
"""
The :ref: role is supported by Sphinx but not by plain docutils
"""
# remove :ref: directives
document = docutils.core.publish_doctree(text) # http://epydoc.sourceforge.net/docutils/private/docutils.nodes.document-class.html
visitor = RefVisitor(document)
document.... | [
"def",
"process_doc",
"(",
"text",
")",
":",
"# remove :ref: directives",
"document",
"=",
"docutils",
".",
"core",
".",
"publish_doctree",
"(",
"text",
")",
"# http://epydoc.sourceforge.net/docutils/private/docutils.nodes.document-class.html",
"visitor",
"=",
"RefVisitor",
... | The :ref: role is supported by Sphinx but not by plain docutils | [
"The",
":",
"ref",
":",
"role",
"is",
"supported",
"by",
"Sphinx",
"but",
"not",
"by",
"plain",
"docutils"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/misc/docs_parser.py#L117-L126 |
geographika/mappyfile | mappyfile/utils.py | open | def open(fn, expand_includes=True, include_comments=False, include_position=False, **kwargs):
"""
Load a Mapfile from the supplied filename into a Python dictionary.
Parameters
----------
fn: string
The path to the Mapfile, or partial Mapfile
expand_includes: boolean
Load any `... | python | def open(fn, expand_includes=True, include_comments=False, include_position=False, **kwargs):
"""
Load a Mapfile from the supplied filename into a Python dictionary.
Parameters
----------
fn: string
The path to the Mapfile, or partial Mapfile
expand_includes: boolean
Load any `... | [
"def",
"open",
"(",
"fn",
",",
"expand_includes",
"=",
"True",
",",
"include_comments",
"=",
"False",
",",
"include_position",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"p",
"=",
"Parser",
"(",
"expand_includes",
"=",
"expand_includes",
",",
"includ... | Load a Mapfile from the supplied filename into a Python dictionary.
Parameters
----------
fn: string
The path to the Mapfile, or partial Mapfile
expand_includes: boolean
Load any ``INCLUDE`` files in the MapFile
include_comments: boolean
Include or discard comment strings ... | [
"Load",
"a",
"Mapfile",
"from",
"the",
"supplied",
"filename",
"into",
"a",
"Python",
"dictionary",
"."
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L34-L75 |
geographika/mappyfile | mappyfile/utils.py | load | def load(fp, expand_includes=True, include_position=False, include_comments=False, **kwargs):
"""
Load a Mapfile from an open file or file-like object.
Parameters
----------
fp: file
A file-like object - as with all Mapfiles this should be encoded in "utf-8"
expand_includes: boolean
... | python | def load(fp, expand_includes=True, include_position=False, include_comments=False, **kwargs):
"""
Load a Mapfile from an open file or file-like object.
Parameters
----------
fp: file
A file-like object - as with all Mapfiles this should be encoded in "utf-8"
expand_includes: boolean
... | [
"def",
"load",
"(",
"fp",
",",
"expand_includes",
"=",
"True",
",",
"include_position",
"=",
"False",
",",
"include_comments",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"p",
"=",
"Parser",
"(",
"expand_includes",
"=",
"expand_includes",
",",
"includ... | Load a Mapfile from an open file or file-like object.
Parameters
----------
fp: file
A file-like object - as with all Mapfiles this should be encoded in "utf-8"
expand_includes: boolean
Load any ``INCLUDE`` files in the MapFile
include_comments: boolean
Include or discard ... | [
"Load",
"a",
"Mapfile",
"from",
"an",
"open",
"file",
"or",
"file",
"-",
"like",
"object",
"."
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L78-L119 |
geographika/mappyfile | mappyfile/utils.py | loads | def loads(s, expand_includes=True, include_position=False, include_comments=False, **kwargs):
"""
Load a Mapfile from a string
Parameters
----------
s: string
The Mapfile, or partial Mapfile, text
expand_includes: boolean
Load any ``INCLUDE`` files in the MapFile
include_co... | python | def loads(s, expand_includes=True, include_position=False, include_comments=False, **kwargs):
"""
Load a Mapfile from a string
Parameters
----------
s: string
The Mapfile, or partial Mapfile, text
expand_includes: boolean
Load any ``INCLUDE`` files in the MapFile
include_co... | [
"def",
"loads",
"(",
"s",
",",
"expand_includes",
"=",
"True",
",",
"include_position",
"=",
"False",
",",
"include_comments",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"p",
"=",
"Parser",
"(",
"expand_includes",
"=",
"expand_includes",
",",
"includ... | Load a Mapfile from a string
Parameters
----------
s: string
The Mapfile, or partial Mapfile, text
expand_includes: boolean
Load any ``INCLUDE`` files in the MapFile
include_comments: boolean
Include or discard comment strings from the Mapfile - *experimental*
include_... | [
"Load",
"a",
"Mapfile",
"from",
"a",
"string"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L122-L161 |
geographika/mappyfile | mappyfile/utils.py | dump | def dump(d, fp, indent=4, spacer=" ", quote='"', newlinechar="\n", end_comment=False):
"""
Write d (the Mapfile dictionary) as a formatted stream to fp
Parameters
----------
d: dict
A Python dictionary based on the the mappyfile schema
fp: file
A file-like object
indent: in... | python | def dump(d, fp, indent=4, spacer=" ", quote='"', newlinechar="\n", end_comment=False):
"""
Write d (the Mapfile dictionary) as a formatted stream to fp
Parameters
----------
d: dict
A Python dictionary based on the the mappyfile schema
fp: file
A file-like object
indent: in... | [
"def",
"dump",
"(",
"d",
",",
"fp",
",",
"indent",
"=",
"4",
",",
"spacer",
"=",
"\" \"",
",",
"quote",
"=",
"'\"'",
",",
"newlinechar",
"=",
"\"\\n\"",
",",
"end_comment",
"=",
"False",
")",
":",
"map_string",
"=",
"_pprint",
"(",
"d",
",",
"inden... | Write d (the Mapfile dictionary) as a formatted stream to fp
Parameters
----------
d: dict
A Python dictionary based on the the mappyfile schema
fp: file
A file-like object
indent: int
The number of ``spacer`` characters to indent structures in the Mapfile
spacer: strin... | [
"Write",
"d",
"(",
"the",
"Mapfile",
"dictionary",
")",
"as",
"a",
"formatted",
"stream",
"to",
"fp"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L164-L202 |
geographika/mappyfile | mappyfile/utils.py | save | def save(d, output_file, indent=4, spacer=" ", quote='"', newlinechar="\n", end_comment=False, **kwargs):
"""
Write a dictionary to an output Mapfile on disk
Parameters
----------
d: dict
A Python dictionary based on the the mappyfile schema
output_file: string
The output filen... | python | def save(d, output_file, indent=4, spacer=" ", quote='"', newlinechar="\n", end_comment=False, **kwargs):
"""
Write a dictionary to an output Mapfile on disk
Parameters
----------
d: dict
A Python dictionary based on the the mappyfile schema
output_file: string
The output filen... | [
"def",
"save",
"(",
"d",
",",
"output_file",
",",
"indent",
"=",
"4",
",",
"spacer",
"=",
"\" \"",
",",
"quote",
"=",
"'\"'",
",",
"newlinechar",
"=",
"\"\\n\"",
",",
"end_comment",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"map_string",
"=",
... | Write a dictionary to an output Mapfile on disk
Parameters
----------
d: dict
A Python dictionary based on the the mappyfile schema
output_file: string
The output filename
indent: int
The number of ``spacer`` characters to indent structures in the Mapfile
spacer: string... | [
"Write",
"a",
"dictionary",
"to",
"an",
"output",
"Mapfile",
"on",
"disk"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L205-L248 |
geographika/mappyfile | mappyfile/utils.py | dumps | def dumps(d, indent=4, spacer=" ", quote='"', newlinechar="\n", end_comment=False, **kwargs):
"""
Output a Mapfile dictionary as a string
Parameters
----------
d: dict
A Python dictionary based on the the mappyfile schema
indent: int
The number of ``spacer`` characters to inden... | python | def dumps(d, indent=4, spacer=" ", quote='"', newlinechar="\n", end_comment=False, **kwargs):
"""
Output a Mapfile dictionary as a string
Parameters
----------
d: dict
A Python dictionary based on the the mappyfile schema
indent: int
The number of ``spacer`` characters to inden... | [
"def",
"dumps",
"(",
"d",
",",
"indent",
"=",
"4",
",",
"spacer",
"=",
"\" \"",
",",
"quote",
"=",
"'\"'",
",",
"newlinechar",
"=",
"\"\\n\"",
",",
"end_comment",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_pprint",
"(",
"d",
",",
... | Output a Mapfile dictionary as a string
Parameters
----------
d: dict
A Python dictionary based on the the mappyfile schema
indent: int
The number of ``spacer`` characters to indent structures in the Mapfile
spacer: string
The character to use for indenting structures in th... | [
"Output",
"a",
"Mapfile",
"dictionary",
"as",
"a",
"string"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L251-L290 |
geographika/mappyfile | mappyfile/utils.py | find | def find(lst, key, value):
"""
Find an item in a list of dicts using a key and a value
Parameters
----------
list: list
A list of composite dictionaries e.g. ``layers``, ``classes``
key: string
The key name to search each dictionary in the list
key: value
The value ... | python | def find(lst, key, value):
"""
Find an item in a list of dicts using a key and a value
Parameters
----------
list: list
A list of composite dictionaries e.g. ``layers``, ``classes``
key: string
The key name to search each dictionary in the list
key: value
The value ... | [
"def",
"find",
"(",
"lst",
",",
"key",
",",
"value",
")",
":",
"return",
"next",
"(",
"(",
"item",
"for",
"item",
"in",
"lst",
"if",
"item",
"[",
"key",
".",
"lower",
"(",
")",
"]",
"==",
"value",
")",
",",
"None",
")"
] | Find an item in a list of dicts using a key and a value
Parameters
----------
list: list
A list of composite dictionaries e.g. ``layers``, ``classes``
key: string
The key name to search each dictionary in the list
key: value
The value to search for
Returns
-------
... | [
"Find",
"an",
"item",
"in",
"a",
"list",
"of",
"dicts",
"using",
"a",
"key",
"and",
"a",
"value"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L293-L339 |
geographika/mappyfile | mappyfile/utils.py | findall | def findall(lst, key, value):
"""
Find all items in lst where key matches value.
For example find all ``LAYER`` s in a ``MAP`` where ``GROUP`` equals ``VALUE``
Parameters
----------
list: list
A list of composite dictionaries e.g. ``layers``, ``classes``
key: string
The key... | python | def findall(lst, key, value):
"""
Find all items in lst where key matches value.
For example find all ``LAYER`` s in a ``MAP`` where ``GROUP`` equals ``VALUE``
Parameters
----------
list: list
A list of composite dictionaries e.g. ``layers``, ``classes``
key: string
The key... | [
"def",
"findall",
"(",
"lst",
",",
"key",
",",
"value",
")",
":",
"return",
"[",
"item",
"for",
"item",
"in",
"lst",
"if",
"item",
"[",
"key",
".",
"lower",
"(",
")",
"]",
"in",
"value",
"]"
] | Find all items in lst where key matches value.
For example find all ``LAYER`` s in a ``MAP`` where ``GROUP`` equals ``VALUE``
Parameters
----------
list: list
A list of composite dictionaries e.g. ``layers``, ``classes``
key: string
The key name to search each dictionary in the lis... | [
"Find",
"all",
"items",
"in",
"lst",
"where",
"key",
"matches",
"value",
".",
"For",
"example",
"find",
"all",
"LAYER",
"s",
"in",
"a",
"MAP",
"where",
"GROUP",
"equals",
"VALUE"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L342-L397 |
geographika/mappyfile | mappyfile/utils.py | findunique | def findunique(lst, key):
"""
Find all unique key values for items in lst.
Parameters
----------
lst: list
A list of composite dictionaries e.g. ``layers``, ``classes``
key: string
The key name to search each dictionary in the list
Returns
-------
list
A ... | python | def findunique(lst, key):
"""
Find all unique key values for items in lst.
Parameters
----------
lst: list
A list of composite dictionaries e.g. ``layers``, ``classes``
key: string
The key name to search each dictionary in the list
Returns
-------
list
A ... | [
"def",
"findunique",
"(",
"lst",
",",
"key",
")",
":",
"return",
"sorted",
"(",
"set",
"(",
"[",
"item",
"[",
"key",
".",
"lower",
"(",
")",
"]",
"for",
"item",
"in",
"lst",
"]",
")",
")"
] | Find all unique key values for items in lst.
Parameters
----------
lst: list
A list of composite dictionaries e.g. ``layers``, ``classes``
key: string
The key name to search each dictionary in the list
Returns
-------
list
A sorted Python list of unique keys in t... | [
"Find",
"all",
"unique",
"key",
"values",
"for",
"items",
"in",
"lst",
"."
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L400-L447 |
geographika/mappyfile | mappyfile/utils.py | findkey | def findkey(d, *keys):
"""
Get a value from a dictionary based on a list of keys and/or list indexes.
Parameters
----------
d: dict
A Python dictionary
keys: list
A list of key names, or list indexes
Returns
-------
dict
The composite dictionary object at ... | python | def findkey(d, *keys):
"""
Get a value from a dictionary based on a list of keys and/or list indexes.
Parameters
----------
d: dict
A Python dictionary
keys: list
A list of key names, or list indexes
Returns
-------
dict
The composite dictionary object at ... | [
"def",
"findkey",
"(",
"d",
",",
"*",
"keys",
")",
":",
"if",
"keys",
":",
"keys",
"=",
"list",
"(",
"keys",
")",
"key",
"=",
"keys",
".",
"pop",
"(",
"0",
")",
"return",
"findkey",
"(",
"d",
"[",
"key",
"]",
",",
"*",
"keys",
")",
"else",
... | Get a value from a dictionary based on a list of keys and/or list indexes.
Parameters
----------
d: dict
A Python dictionary
keys: list
A list of key names, or list indexes
Returns
-------
dict
The composite dictionary object at the path specified by the keys
... | [
"Get",
"a",
"value",
"from",
"a",
"dictionary",
"based",
"on",
"a",
"list",
"of",
"keys",
"and",
"/",
"or",
"list",
"indexes",
"."
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L450-L497 |
geographika/mappyfile | mappyfile/utils.py | update | def update(d1, d2):
"""
Update dict d1 with properties from d2
Note
----
Allows deletion of objects with a special ``__delete__`` key
For any list of dicts new items can be added when updating
Parameters
----------
d1: dict
A Python dictionary
d2: dict
A Pytho... | python | def update(d1, d2):
"""
Update dict d1 with properties from d2
Note
----
Allows deletion of objects with a special ``__delete__`` key
For any list of dicts new items can be added when updating
Parameters
----------
d1: dict
A Python dictionary
d2: dict
A Pytho... | [
"def",
"update",
"(",
"d1",
",",
"d2",
")",
":",
"NoneType",
"=",
"type",
"(",
"None",
")",
"if",
"d2",
".",
"get",
"(",
"\"__delete__\"",
",",
"False",
")",
":",
"return",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"d2",
".",
"items",
"(",
")",
"... | Update dict d1 with properties from d2
Note
----
Allows deletion of objects with a special ``__delete__`` key
For any list of dicts new items can be added when updating
Parameters
----------
d1: dict
A Python dictionary
d2: dict
A Python dictionary that will be used t... | [
"Update",
"dict",
"d1",
"with",
"properties",
"from",
"d2"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L500-L561 |
geographika/mappyfile | docs/examples/geometry/geometry.py | erosion | def erosion(mapfile, dilated):
"""
We will continue to work with the modified Mapfile
If we wanted to start from scratch we could simply reread it
"""
ll = mappyfile.find(mapfile["layers"], "name", "line")
ll["status"] = "OFF"
pl = mappyfile.find(mapfile["layers"], "name", "polygon")
#... | python | def erosion(mapfile, dilated):
"""
We will continue to work with the modified Mapfile
If we wanted to start from scratch we could simply reread it
"""
ll = mappyfile.find(mapfile["layers"], "name", "line")
ll["status"] = "OFF"
pl = mappyfile.find(mapfile["layers"], "name", "polygon")
#... | [
"def",
"erosion",
"(",
"mapfile",
",",
"dilated",
")",
":",
"ll",
"=",
"mappyfile",
".",
"find",
"(",
"mapfile",
"[",
"\"layers\"",
"]",
",",
"\"name\"",
",",
"\"line\"",
")",
"ll",
"[",
"\"status\"",
"]",
"=",
"\"OFF\"",
"pl",
"=",
"mappyfile",
".",
... | We will continue to work with the modified Mapfile
If we wanted to start from scratch we could simply reread it | [
"We",
"will",
"continue",
"to",
"work",
"with",
"the",
"modified",
"Mapfile",
"If",
"we",
"wanted",
"to",
"start",
"from",
"scratch",
"we",
"could",
"simply",
"reread",
"it"
] | train | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/docs/examples/geometry/geometry.py#L23-L45 |
dpursehouse/pygerrit2 | pygerrit2/rest/__init__.py | _decode_response | def _decode_response(response):
"""Strip off Gerrit's magic prefix and decode a response.
:returns:
Decoded JSON content as a dict, or raw text if content could not be
decoded as JSON.
:raises:
requests.HTTPError if the response contains an HTTP error status code.
"""
cont... | python | def _decode_response(response):
"""Strip off Gerrit's magic prefix and decode a response.
:returns:
Decoded JSON content as a dict, or raw text if content could not be
decoded as JSON.
:raises:
requests.HTTPError if the response contains an HTTP error status code.
"""
cont... | [
"def",
"_decode_response",
"(",
"response",
")",
":",
"content_type",
"=",
"response",
".",
"headers",
".",
"get",
"(",
"'content-type'",
",",
"''",
")",
"logger",
".",
"debug",
"(",
"\"status[%s] content_type[%s] encoding[%s]\"",
"%",
"(",
"response",
".",
"sta... | Strip off Gerrit's magic prefix and decode a response.
:returns:
Decoded JSON content as a dict, or raw text if content could not be
decoded as JSON.
:raises:
requests.HTTPError if the response contains an HTTP error status code. | [
"Strip",
"off",
"Gerrit",
"s",
"magic",
"prefix",
"and",
"decode",
"a",
"response",
"."
] | train | https://github.com/dpursehouse/pygerrit2/blob/141031469603b33369d89c38c703390eb3786bd0/pygerrit2/rest/__init__.py#L46-L75 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.