repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
fulfilio/fulfil-python-api | fulfil_client/model.py | Query.limit | def limit(self, limit):
"""
Apply a LIMIT to the query and return the newly resulting Query.
"""
query = self._copy()
query._limit = limit
return query | python | def limit(self, limit):
"""
Apply a LIMIT to the query and return the newly resulting Query.
"""
query = self._copy()
query._limit = limit
return query | [
"def",
"limit",
"(",
"self",
",",
"limit",
")",
":",
"query",
"=",
"self",
".",
"_copy",
"(",
")",
"query",
".",
"_limit",
"=",
"limit",
"return",
"query"
] | Apply a LIMIT to the query and return the newly resulting Query. | [
"Apply",
"a",
"LIMIT",
"to",
"the",
"query",
"and",
"return",
"the",
"newly",
"resulting",
"Query",
"."
] | 180ac969c427b1292439a0371866aa5f169ffa6b | https://github.com/fulfilio/fulfil-python-api/blob/180ac969c427b1292439a0371866aa5f169ffa6b/fulfil_client/model.py#L437-L443 | train |
fulfilio/fulfil-python-api | fulfil_client/model.py | Query.offset | def offset(self, offset):
"""
Apply an OFFSET to the query and return the newly resulting Query.
"""
query = self._copy()
query._offset = offset
return query | python | def offset(self, offset):
"""
Apply an OFFSET to the query and return the newly resulting Query.
"""
query = self._copy()
query._offset = offset
return query | [
"def",
"offset",
"(",
"self",
",",
"offset",
")",
":",
"query",
"=",
"self",
".",
"_copy",
"(",
")",
"query",
".",
"_offset",
"=",
"offset",
"return",
"query"
] | Apply an OFFSET to the query and return the newly resulting Query. | [
"Apply",
"an",
"OFFSET",
"to",
"the",
"query",
"and",
"return",
"the",
"newly",
"resulting",
"Query",
"."
] | 180ac969c427b1292439a0371866aa5f169ffa6b | https://github.com/fulfilio/fulfil-python-api/blob/180ac969c427b1292439a0371866aa5f169ffa6b/fulfil_client/model.py#L445-L451 | train |
fulfilio/fulfil-python-api | fulfil_client/model.py | Query.one | def one(self):
"""
Return exactly one result or raise an exception.
Raises fulfil_client.exc.NoResultFound if the query selects no rows.
Raises fulfil_client.exc.MultipleResultsFound if multiple rows are
found.
"""
results = self.rpc_model.search_read(
... | python | def one(self):
"""
Return exactly one result or raise an exception.
Raises fulfil_client.exc.NoResultFound if the query selects no rows.
Raises fulfil_client.exc.MultipleResultsFound if multiple rows are
found.
"""
results = self.rpc_model.search_read(
... | [
"def",
"one",
"(",
"self",
")",
":",
"results",
"=",
"self",
".",
"rpc_model",
".",
"search_read",
"(",
"self",
".",
"domain",
",",
"2",
",",
"None",
",",
"self",
".",
"_order_by",
",",
"self",
".",
"fields",
",",
"context",
"=",
"self",
".",
"cont... | Return exactly one result or raise an exception.
Raises fulfil_client.exc.NoResultFound if the query selects no rows.
Raises fulfil_client.exc.MultipleResultsFound if multiple rows are
found. | [
"Return",
"exactly",
"one",
"result",
"or",
"raise",
"an",
"exception",
"."
] | 180ac969c427b1292439a0371866aa5f169ffa6b | https://github.com/fulfilio/fulfil-python-api/blob/180ac969c427b1292439a0371866aa5f169ffa6b/fulfil_client/model.py#L454-L470 | train |
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"
] | 180ac969c427b1292439a0371866aa5f169ffa6b | https://github.com/fulfilio/fulfil-python-api/blob/180ac969c427b1292439a0371866aa5f169ffa6b/fulfil_client/model.py#L472-L482 | train |
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",
"."
] | 180ac969c427b1292439a0371866aa5f169ffa6b | https://github.com/fulfilio/fulfil-python-api/blob/180ac969c427b1292439a0371866aa5f169ffa6b/fulfil_client/model.py#L484-L499 | train |
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",
"."
] | 83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6 | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/chat.py#L51-L67 | train |
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",
")",
":",
"s",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
"SOCK_STREAM",
")",
"connect_host",
"=",
"\"irc.twitch.tv\"",
"connect_port",
"=",
"6667",
"try",
":",
"s",
".",
"connect",
"("... | Connect to Twitch | [
"Connect",
"to",
"Twitch"
] | 83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6 | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/chat.py#L109-L157 | train |
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",
"."
] | 83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6 | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/chat.py#L159-L172 | train |
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"
] | 83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6 | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/chat.py#L190-L200 | train |
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",
"."
] | 83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6 | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/chat.py#L210-L235 | train |
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",
":",
"try",
":",
"self",
".",
"ffmpeg_process",
".",
"send_signal",
"(",
"signal",
".",
"SIGINT",
")",
"except",
"OSError",
":",
"pass",
"command",
"=",
"[... | Reset the videostream by restarting ffmpeg | [
"Reset",
"the",
"videostream",
"by",
"restarting",
"ffmpeg"
] | 83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6 | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/outputvideo.py#L75-L174 | train |
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",
"."
] | 83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6 | https://github.com/317070/python-twitch-stream/blob/83b4c2a27ee368fc3316b59ab1d25fcf0b0bcda6/twitchstream/outputvideo.py#L209-L237 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L21-L29 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L64-L72 | train |
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",
":",
"profile",
".",
... | 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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L128-L142 | train |
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",
",",
"**",
"kw... | 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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/mixins.py#L150-L163 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/contrib/foursquare/client.py#L32-L37 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L55-L68 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L70-L83 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L85-L115 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L117-L138 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L140-L174 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/views.py#L202-L218 | train |
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",
")",
":",
"if",
"not",
"self",
".",
"_request_token",
"and",
"not",
"self",
".",
"_access_token",
":",
"client",
"=",
"oauth",
".",
"Client",
"(",
"self",
".",
"consumer",
",",
"timeout",
"=",... | 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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L64-L86 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L88-L110 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L112-L131 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L133-L141 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L143-L151 | train |
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... | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L164-L174 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L176-L201 | train |
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_callback_... | 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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L241-L254 | train |
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",
... | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L263-L271 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L273-L300 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L302-L316 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L318-L327 | train |
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",
"."
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/clients/oauth.py#L337-L351 | train |
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"
] | 9da9fb83c9bf79997ff81fe1378ab5ca3074b32b | https://github.com/flashingpumpkin/django-socialregistration/blob/9da9fb83c9bf79997ff81fe1378ab5ca3074b32b/socialregistration/contrib/google/client.py#L33-L37 | train |
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",
"(",
")",
"v",
">>=",
"4",
"internal",
"=",
"v",
"&",
"0x7FF",
"if",
"v",
"&",
"0x800",
":",
"internal",
"-=",
"4096",
"return",
"internal",
"*",
"0.0625"
] | Return internal temperature value in degrees celsius. | [
"Return",
"internal",
"temperature",
"value",
"in",
"degrees",
"celsius",
"."
] | a74832ebcea36487559ec96497398f99fd9355a5 | https://github.com/adafruit/Adafruit_Python_MAX31855/blob/a74832ebcea36487559ec96497398f99fd9355a5/Adafruit_MAX31855/MAX31855.py#L56-L68 | train |
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",
"(",
")",
"if",
"v",
"&",
"0x7",
":",
"return",
"float",
"(",
"'NaN'",
")",
"if",
"v",
"&",
"0x80000000",
":",
"v",
">>=",
"18",
"v",
"-=",
"16384",
"else",
":",
"v",
... | Return the thermocouple temperature value in degrees celsius. | [
"Return",
"the",
"thermocouple",
"temperature",
"value",
"in",
"degrees",
"celsius",
"."
] | a74832ebcea36487559ec96497398f99fd9355a5 | https://github.com/adafruit/Adafruit_Python_MAX31855/blob/a74832ebcea36487559ec96497398f99fd9355a5/Adafruit_MAX31855/MAX31855.py#L70-L86 | train |
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",
")",
":",
"middle",
"=",
"self",
".",
"remove_quotes",
"(",
"val",
... | Escape any quotes in a value | [
"Escape",
"any",
"quotes",
"in",
"a",
"value"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L46-L56 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L91-L100 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L174-L188 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L190-L199 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L273-L284 | train |
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",
"composites",
"and",
"not",
"isinstance",
"(",
"composites",
",",
"list",
")",
":",
"composites",
"=",
"[",
"composites",
"]",
"lines",
"=",
"[",
"]",
"for",
"composite",
"in",
"composites"... | Print out a nicely indented Mapfile | [
"Print",
"out",
"a",
"nicely",
"indented",
"Mapfile"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L286-L308 | train |
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",
"."
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/pprint.py#L417-L433 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/transformer.py#L38-L60 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/transformer.py#L293-L316 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/transformer.py#L318-L347 | train |
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",
"]",
"for",
"sp",
"in",
"string_pairs",
":",
"if",
"isinstan... | 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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/transformer.py#L605-L630 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/parser.py#L80-L116 | train |
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",
")",
":",
"text",
"=",
"unicode",
"(",
"text",
",",
"'utf-8'",
")",
"if",
"self",
".",
"expand_include... | Parse the Mapfile | [
"Parse",
"the",
"Mapfile"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/parser.py#L184-L208 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/validator.py#L169-L183 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/docs/examples/parsing.py#L117-L130 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/cli.py#L41-L48 | train |
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",
"."
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/cli.py#L61-L85 | train |
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",
",",
"include_comm... | 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",
"."
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L34-L75 | train |
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",
",",
"include_comm... | 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",
"."
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L78-L119 | train |
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",
",",
"include_comm... | 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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L122-L161 | train |
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",
"=",
"_pp... | 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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L205-L248 | train |
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",
",",
"ind... | 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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L251-L290 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L293-L339 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L342-L397 | train |
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",
"."
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L400-L447 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/mappyfile/utils.py#L500-L561 | train |
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"
] | aecbc5e66ec06896bc4c5db41313503468829d00 | https://github.com/geographika/mappyfile/blob/aecbc5e66ec06896bc4c5db41313503468829d00/docs/examples/geometry/geometry.py#L23-L45 | train |
dpursehouse/pygerrit2 | pygerrit2/rest/__init__.py | GerritRestAPI.translate_kwargs | def translate_kwargs(self, **kwargs):
"""Translate kwargs replacing `data` with `json` if necessary."""
local_kwargs = self.kwargs.copy()
local_kwargs.update(kwargs)
if "data" in local_kwargs and "json" in local_kwargs:
raise ValueError("Cannot use data and json together")
... | python | def translate_kwargs(self, **kwargs):
"""Translate kwargs replacing `data` with `json` if necessary."""
local_kwargs = self.kwargs.copy()
local_kwargs.update(kwargs)
if "data" in local_kwargs and "json" in local_kwargs:
raise ValueError("Cannot use data and json together")
... | [
"def",
"translate_kwargs",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"local_kwargs",
"=",
"self",
".",
"kwargs",
".",
"copy",
"(",
")",
"local_kwargs",
".",
"update",
"(",
"kwargs",
")",
"if",
"\"data\"",
"in",
"local_kwargs",
"and",
"\"json\"",
"in",
... | Translate kwargs replacing `data` with `json` if necessary. | [
"Translate",
"kwargs",
"replacing",
"data",
"with",
"json",
"if",
"necessary",
"."
] | 141031469603b33369d89c38c703390eb3786bd0 | https://github.com/dpursehouse/pygerrit2/blob/141031469603b33369d89c38c703390eb3786bd0/pygerrit2/rest/__init__.py#L133-L152 | train |
dpursehouse/pygerrit2 | pygerrit2/rest/__init__.py | GerritRestAPI.post | def post(self, endpoint, return_response=False, **kwargs):
"""Send HTTP POST to the endpoint.
:arg str endpoint: The endpoint to send to.
:returns:
JSON decoded result.
:raises:
requests.RequestException on timeout or connection error.
"""
args... | python | def post(self, endpoint, return_response=False, **kwargs):
"""Send HTTP POST to the endpoint.
:arg str endpoint: The endpoint to send to.
:returns:
JSON decoded result.
:raises:
requests.RequestException on timeout or connection error.
"""
args... | [
"def",
"post",
"(",
"self",
",",
"endpoint",
",",
"return_response",
"=",
"False",
",",
"**",
"kwargs",
")",
":",
"args",
"=",
"self",
".",
"translate_kwargs",
"(",
"**",
"kwargs",
")",
"response",
"=",
"self",
".",
"session",
".",
"post",
"(",
"self",... | Send HTTP POST to the endpoint.
:arg str endpoint: The endpoint to send to.
:returns:
JSON decoded result.
:raises:
requests.RequestException on timeout or connection error. | [
"Send",
"HTTP",
"POST",
"to",
"the",
"endpoint",
"."
] | 141031469603b33369d89c38c703390eb3786bd0 | https://github.com/dpursehouse/pygerrit2/blob/141031469603b33369d89c38c703390eb3786bd0/pygerrit2/rest/__init__.py#L197-L216 | train |
dpursehouse/pygerrit2 | pygerrit2/__init__.py | escape_string | def escape_string(string):
"""Escape a string for use in Gerrit commands.
:arg str string: The string to escape.
:returns: The string with necessary escapes and surrounding double quotes
so that it can be passed to any of the Gerrit commands that require
double-quoted strings.
"""
... | python | def escape_string(string):
"""Escape a string for use in Gerrit commands.
:arg str string: The string to escape.
:returns: The string with necessary escapes and surrounding double quotes
so that it can be passed to any of the Gerrit commands that require
double-quoted strings.
"""
... | [
"def",
"escape_string",
"(",
"string",
")",
":",
"result",
"=",
"string",
"result",
"=",
"result",
".",
"replace",
"(",
"'\\\\'",
",",
"'\\\\\\\\'",
")",
"result",
"=",
"result",
".",
"replace",
"(",
"'\"'",
",",
"'\\\\\"'",
")",
"return",
"'\"'",
"+",
... | Escape a string for use in Gerrit commands.
:arg str string: The string to escape.
:returns: The string with necessary escapes and surrounding double quotes
so that it can be passed to any of the Gerrit commands that require
double-quoted strings. | [
"Escape",
"a",
"string",
"for",
"use",
"in",
"Gerrit",
"commands",
"."
] | 141031469603b33369d89c38c703390eb3786bd0 | https://github.com/dpursehouse/pygerrit2/blob/141031469603b33369d89c38c703390eb3786bd0/pygerrit2/__init__.py#L49-L62 | train |
dpursehouse/pygerrit2 | pygerrit2/__init__.py | GerritReviewMessageFormatter.append | def append(self, data):
"""Append the given `data` to the output.
:arg data: If a list, it is formatted as a bullet list with each
entry in the list being a separate bullet. Otherwise if it is a
string, the string is added as a paragraph.
:raises: ValueError if `data` ... | python | def append(self, data):
"""Append the given `data` to the output.
:arg data: If a list, it is formatted as a bullet list with each
entry in the list being a separate bullet. Otherwise if it is a
string, the string is added as a paragraph.
:raises: ValueError if `data` ... | [
"def",
"append",
"(",
"self",
",",
"data",
")",
":",
"if",
"not",
"data",
":",
"return",
"if",
"isinstance",
"(",
"data",
",",
"list",
")",
":",
"_items",
"=",
"[",
"x",
".",
"replace",
"(",
"\"\\n\"",
",",
"\" \"",
")",
".",
"strip",
"(",
")",
... | Append the given `data` to the output.
:arg data: If a list, it is formatted as a bullet list with each
entry in the list being a separate bullet. Otherwise if it is a
string, the string is added as a paragraph.
:raises: ValueError if `data` is not a list or a string. | [
"Append",
"the",
"given",
"data",
"to",
"the",
"output",
"."
] | 141031469603b33369d89c38c703390eb3786bd0 | https://github.com/dpursehouse/pygerrit2/blob/141031469603b33369d89c38c703390eb3786bd0/pygerrit2/__init__.py#L87-L125 | train |
dpursehouse/pygerrit2 | pygerrit2/__init__.py | GerritReviewMessageFormatter.format | def format(self):
"""Format the message parts to a string.
:Returns: A string of all the message parts separated into paragraphs,
with header and footer paragraphs if they were specified in the
constructor.
"""
message = ""
if self.paragraphs:
... | python | def format(self):
"""Format the message parts to a string.
:Returns: A string of all the message parts separated into paragraphs,
with header and footer paragraphs if they were specified in the
constructor.
"""
message = ""
if self.paragraphs:
... | [
"def",
"format",
"(",
"self",
")",
":",
"message",
"=",
"\"\"",
"if",
"self",
".",
"paragraphs",
":",
"if",
"self",
".",
"header",
":",
"message",
"+=",
"(",
"self",
".",
"header",
"+",
"'\\n\\n'",
")",
"message",
"+=",
"\"\\n\\n\"",
".",
"join",
"("... | Format the message parts to a string.
:Returns: A string of all the message parts separated into paragraphs,
with header and footer paragraphs if they were specified in the
constructor. | [
"Format",
"the",
"message",
"parts",
"to",
"a",
"string",
"."
] | 141031469603b33369d89c38c703390eb3786bd0 | https://github.com/dpursehouse/pygerrit2/blob/141031469603b33369d89c38c703390eb3786bd0/pygerrit2/__init__.py#L135-L150 | train |
Zimbra-Community/python-zimbra | pythonzimbra/request.py | Request.enable_batch | def enable_batch(self, onerror="continue"):
""" Enables batch request gathering.
Do this first and then consecutively call "add_request" to add more
requests.
:param onerror: "continue" (default) if one request fails (and
response with soap Faults for the request) or "stop" ... | python | def enable_batch(self, onerror="continue"):
""" Enables batch request gathering.
Do this first and then consecutively call "add_request" to add more
requests.
:param onerror: "continue" (default) if one request fails (and
response with soap Faults for the request) or "stop" ... | [
"def",
"enable_batch",
"(",
"self",
",",
"onerror",
"=",
"\"continue\"",
")",
":",
"self",
".",
"batch_request",
"=",
"True",
"self",
".",
"batch_request_id",
"=",
"1",
"self",
".",
"_create_batch_node",
"(",
"onerror",
")"
] | Enables batch request gathering.
Do this first and then consecutively call "add_request" to add more
requests.
:param onerror: "continue" (default) if one request fails (and
response with soap Faults for the request) or "stop" processing. | [
"Enables",
"batch",
"request",
"gathering",
"."
] | 8b839143c64b0507a30a9908ff39066ae4ef5d03 | https://github.com/Zimbra-Community/python-zimbra/blob/8b839143c64b0507a30a9908ff39066ae4ef5d03/pythonzimbra/request.py#L75-L89 | train |
Zimbra-Community/python-zimbra | pythonzimbra/response.py | Response._filter_response | def _filter_response(self, response_dict):
""" Add additional filters to the response dictionary
Currently the response dictionary is filtered like this:
* If a list only has one item, the list is replaced by that item
* Namespace-Keys (_jsns and xmlns) are removed
:param... | python | def _filter_response(self, response_dict):
""" Add additional filters to the response dictionary
Currently the response dictionary is filtered like this:
* If a list only has one item, the list is replaced by that item
* Namespace-Keys (_jsns and xmlns) are removed
:param... | [
"def",
"_filter_response",
"(",
"self",
",",
"response_dict",
")",
":",
"filtered_dict",
"=",
"{",
"}",
"for",
"key",
",",
"value",
"in",
"response_dict",
".",
"items",
"(",
")",
":",
"if",
"key",
"==",
"\"_jsns\"",
":",
"continue",
"if",
"key",
"==",
... | Add additional filters to the response dictionary
Currently the response dictionary is filtered like this:
* If a list only has one item, the list is replaced by that item
* Namespace-Keys (_jsns and xmlns) are removed
:param response_dict: the pregenerated, but unfiltered respons... | [
"Add",
"additional",
"filters",
"to",
"the",
"response",
"dictionary"
] | 8b839143c64b0507a30a9908ff39066ae4ef5d03 | https://github.com/Zimbra-Community/python-zimbra/blob/8b839143c64b0507a30a9908ff39066ae4ef5d03/pythonzimbra/response.py#L151-L197 | train |
Zimbra-Community/python-zimbra | pythonzimbra/tools/preauth.py | create_preauth | def create_preauth(byval, key, by='name', expires=0, timestamp=None):
""" Generates a zimbra preauth value
:param byval: The value of the targeted user (according to the
by-parameter). For example: The account name, if "by" is "name".
:param key: The domain preauth key (you can retrieve that using z... | python | def create_preauth(byval, key, by='name', expires=0, timestamp=None):
""" Generates a zimbra preauth value
:param byval: The value of the targeted user (according to the
by-parameter). For example: The account name, if "by" is "name".
:param key: The domain preauth key (you can retrieve that using z... | [
"def",
"create_preauth",
"(",
"byval",
",",
"key",
",",
"by",
"=",
"'name'",
",",
"expires",
"=",
"0",
",",
"timestamp",
"=",
"None",
")",
":",
"if",
"timestamp",
"is",
"None",
":",
"timestamp",
"=",
"int",
"(",
"datetime",
".",
"now",
"(",
")",
".... | Generates a zimbra preauth value
:param byval: The value of the targeted user (according to the
by-parameter). For example: The account name, if "by" is "name".
:param key: The domain preauth key (you can retrieve that using zmprov gd)
:param by: What type is the byval-parameter? Valid parameters are... | [
"Generates",
"a",
"zimbra",
"preauth",
"value"
] | 8b839143c64b0507a30a9908ff39066ae4ef5d03 | https://github.com/Zimbra-Community/python-zimbra/blob/8b839143c64b0507a30a9908ff39066ae4ef5d03/pythonzimbra/tools/preauth.py#L8-L38 | train |
Zimbra-Community/python-zimbra | pythonzimbra/tools/dict.py | zimbra_to_python | def zimbra_to_python(zimbra_dict, key_attribute="n",
content_attribute="_content"):
"""
Converts single level Zimbra dicts to a standard python dict
:param zimbra_dict: The dictionary in Zimbra-Format
:return: A native python dict
"""
local_dict = {}
for item in zimb... | python | def zimbra_to_python(zimbra_dict, key_attribute="n",
content_attribute="_content"):
"""
Converts single level Zimbra dicts to a standard python dict
:param zimbra_dict: The dictionary in Zimbra-Format
:return: A native python dict
"""
local_dict = {}
for item in zimb... | [
"def",
"zimbra_to_python",
"(",
"zimbra_dict",
",",
"key_attribute",
"=",
"\"n\"",
",",
"content_attribute",
"=",
"\"_content\"",
")",
":",
"local_dict",
"=",
"{",
"}",
"for",
"item",
"in",
"zimbra_dict",
":",
"local_dict",
"[",
"item",
"[",
"key_attribute",
"... | Converts single level Zimbra dicts to a standard python dict
:param zimbra_dict: The dictionary in Zimbra-Format
:return: A native python dict | [
"Converts",
"single",
"level",
"Zimbra",
"dicts",
"to",
"a",
"standard",
"python",
"dict"
] | 8b839143c64b0507a30a9908ff39066ae4ef5d03 | https://github.com/Zimbra-Community/python-zimbra/blob/8b839143c64b0507a30a9908ff39066ae4ef5d03/pythonzimbra/tools/dict.py#L15-L31 | train |
Zimbra-Community/python-zimbra | pythonzimbra/tools/dict.py | get_value | def get_value(haystack, needle, key_attribute="n",
content_attribute="_content"):
""" Fetch a value from a zimbra-like json dict (keys are "n", values are
"_content"
This function may be slightly faster than zimbra_to_python(haystack)[
needle], because it doesn't necessarily iterate over... | python | def get_value(haystack, needle, key_attribute="n",
content_attribute="_content"):
""" Fetch a value from a zimbra-like json dict (keys are "n", values are
"_content"
This function may be slightly faster than zimbra_to_python(haystack)[
needle], because it doesn't necessarily iterate over... | [
"def",
"get_value",
"(",
"haystack",
",",
"needle",
",",
"key_attribute",
"=",
"\"n\"",
",",
"content_attribute",
"=",
"\"_content\"",
")",
":",
"for",
"value",
"in",
"haystack",
":",
"if",
"value",
"[",
"key_attribute",
"]",
"==",
"needle",
":",
"return",
... | Fetch a value from a zimbra-like json dict (keys are "n", values are
"_content"
This function may be slightly faster than zimbra_to_python(haystack)[
needle], because it doesn't necessarily iterate over the complete list.
:param haystack: The list in zimbra-dict format
:param needle: the key to se... | [
"Fetch",
"a",
"value",
"from",
"a",
"zimbra",
"-",
"like",
"json",
"dict",
"(",
"keys",
"are",
"n",
"values",
"are",
"_content"
] | 8b839143c64b0507a30a9908ff39066ae4ef5d03 | https://github.com/Zimbra-Community/python-zimbra/blob/8b839143c64b0507a30a9908ff39066ae4ef5d03/pythonzimbra/tools/dict.py#L34-L54 | train |
Zimbra-Community/python-zimbra | pythonzimbra/tools/xmlserializer.py | dict_to_dom | def dict_to_dom(root_node, xml_dict):
""" Create a DOM node and optionally several subnodes from a dictionary.
:param root_node: DOM-Node set the dictionary is applied upon
:type root_node: xml.dom.Element
:param xml_dict: The dictionary containing the nodes to process
:type xml_dict: dict
"""
... | python | def dict_to_dom(root_node, xml_dict):
""" Create a DOM node and optionally several subnodes from a dictionary.
:param root_node: DOM-Node set the dictionary is applied upon
:type root_node: xml.dom.Element
:param xml_dict: The dictionary containing the nodes to process
:type xml_dict: dict
"""
... | [
"def",
"dict_to_dom",
"(",
"root_node",
",",
"xml_dict",
")",
":",
"if",
"'_content'",
"in",
"list",
"(",
"xml_dict",
".",
"keys",
"(",
")",
")",
":",
"root_node",
".",
"appendChild",
"(",
"root_node",
".",
"ownerDocument",
".",
"createTextNode",
"(",
"con... | Create a DOM node and optionally several subnodes from a dictionary.
:param root_node: DOM-Node set the dictionary is applied upon
:type root_node: xml.dom.Element
:param xml_dict: The dictionary containing the nodes to process
:type xml_dict: dict | [
"Create",
"a",
"DOM",
"node",
"and",
"optionally",
"several",
"subnodes",
"from",
"a",
"dictionary",
"."
] | 8b839143c64b0507a30a9908ff39066ae4ef5d03 | https://github.com/Zimbra-Community/python-zimbra/blob/8b839143c64b0507a30a9908ff39066ae4ef5d03/pythonzimbra/tools/xmlserializer.py#L28-L77 | train |
Zimbra-Community/python-zimbra | pythonzimbra/tools/xmlserializer.py | dom_to_dict | def dom_to_dict(root_node):
""" Serializes the given node to the dictionary
Serializes the given node to the documented dictionary format.
:param root_node: Node to serialize
:returns: The dictionary
:rtype: dict
"""
# Remove namespaces from tagname
tag = root_node.tagName
if "... | python | def dom_to_dict(root_node):
""" Serializes the given node to the dictionary
Serializes the given node to the documented dictionary format.
:param root_node: Node to serialize
:returns: The dictionary
:rtype: dict
"""
# Remove namespaces from tagname
tag = root_node.tagName
if "... | [
"def",
"dom_to_dict",
"(",
"root_node",
")",
":",
"tag",
"=",
"root_node",
".",
"tagName",
"if",
"\":\"",
"in",
"tag",
":",
"tag",
"=",
"tag",
".",
"split",
"(",
"\":\"",
")",
"[",
"1",
"]",
"root_dict",
"=",
"{",
"tag",
":",
"{",
"}",
"}",
"node... | Serializes the given node to the dictionary
Serializes the given node to the documented dictionary format.
:param root_node: Node to serialize
:returns: The dictionary
:rtype: dict | [
"Serializes",
"the",
"given",
"node",
"to",
"the",
"dictionary"
] | 8b839143c64b0507a30a9908ff39066ae4ef5d03 | https://github.com/Zimbra-Community/python-zimbra/blob/8b839143c64b0507a30a9908ff39066ae4ef5d03/pythonzimbra/tools/xmlserializer.py#L80-L148 | train |
Zimbra-Community/python-zimbra | pythonzimbra/tools/urllib2_tls.py | TLS1Connection.connect | def connect(self):
"""Overrides HTTPSConnection.connect to specify TLS version"""
# Standard implementation from HTTPSConnection, which is not
# designed for extension, unfortunately
sock = socket.create_connection((self.host, self.port),
self.time... | python | def connect(self):
"""Overrides HTTPSConnection.connect to specify TLS version"""
# Standard implementation from HTTPSConnection, which is not
# designed for extension, unfortunately
sock = socket.create_connection((self.host, self.port),
self.time... | [
"def",
"connect",
"(",
"self",
")",
":",
"sock",
"=",
"socket",
".",
"create_connection",
"(",
"(",
"self",
".",
"host",
",",
"self",
".",
"port",
")",
",",
"self",
".",
"timeout",
",",
"self",
".",
"source_address",
")",
"if",
"getattr",
"(",
"self"... | Overrides HTTPSConnection.connect to specify TLS version | [
"Overrides",
"HTTPSConnection",
".",
"connect",
"to",
"specify",
"TLS",
"version"
] | 8b839143c64b0507a30a9908ff39066ae4ef5d03 | https://github.com/Zimbra-Community/python-zimbra/blob/8b839143c64b0507a30a9908ff39066ae4ef5d03/pythonzimbra/tools/urllib2_tls.py#L22-L34 | train |
Zimbra-Community/python-zimbra | pythonzimbra/communication.py | Communication.gen_request | def gen_request(self, request_type="json", token=None, set_batch=False,
batch_onerror=None):
""" Convenience method to quickly generate a token
:param request_type: Type of request (defaults to json)
:param token: Authentication token
:param set_batch: Also set this... | python | def gen_request(self, request_type="json", token=None, set_batch=False,
batch_onerror=None):
""" Convenience method to quickly generate a token
:param request_type: Type of request (defaults to json)
:param token: Authentication token
:param set_batch: Also set this... | [
"def",
"gen_request",
"(",
"self",
",",
"request_type",
"=",
"\"json\"",
",",
"token",
"=",
"None",
",",
"set_batch",
"=",
"False",
",",
"batch_onerror",
"=",
"None",
")",
":",
"if",
"request_type",
"==",
"\"json\"",
":",
"local_request",
"=",
"RequestJson",... | Convenience method to quickly generate a token
:param request_type: Type of request (defaults to json)
:param token: Authentication token
:param set_batch: Also set this request to batch mode?
:param batch_onerror: Onerror-parameter for batch mode
:return: The request | [
"Convenience",
"method",
"to",
"quickly",
"generate",
"a",
"token"
] | 8b839143c64b0507a30a9908ff39066ae4ef5d03 | https://github.com/Zimbra-Community/python-zimbra/blob/8b839143c64b0507a30a9908ff39066ae4ef5d03/pythonzimbra/communication.py#L54-L84 | train |
Zimbra-Community/python-zimbra | pythonzimbra/communication.py | Communication.send_request | def send_request(self, request, response=None):
""" Send the request.
Sends the request and retrieves the results, formats them and returns
them in a dict or a list (when it's a batchresponse). If something
goes wrong, raises a SoapFailure or a HTTPError on system-side
failu... | python | def send_request(self, request, response=None):
""" Send the request.
Sends the request and retrieves the results, formats them and returns
them in a dict or a list (when it's a batchresponse). If something
goes wrong, raises a SoapFailure or a HTTPError on system-side
failu... | [
"def",
"send_request",
"(",
"self",
",",
"request",
",",
"response",
"=",
"None",
")",
":",
"local_response",
"=",
"None",
"if",
"response",
"is",
"None",
":",
"if",
"request",
".",
"request_type",
"==",
"\"json\"",
":",
"local_response",
"=",
"ResponseJson"... | Send the request.
Sends the request and retrieves the results, formats them and returns
them in a dict or a list (when it's a batchresponse). If something
goes wrong, raises a SoapFailure or a HTTPError on system-side
failures. Note: AuthRequest raises an HTTPError on failed
... | [
"Send",
"the",
"request",
"."
] | 8b839143c64b0507a30a9908ff39066ae4ef5d03 | https://github.com/Zimbra-Community/python-zimbra/blob/8b839143c64b0507a30a9908ff39066ae4ef5d03/pythonzimbra/communication.py#L86-L169 | train |
Zimbra-Community/python-zimbra | pythonzimbra/tools/auth.py | authenticate | def authenticate(url, account, key, by='name', expires=0, timestamp=None,
timeout=None, request_type="xml", admin_auth=False,
use_password=False, raise_on_error=False):
""" Authenticate to the Zimbra server
:param url: URL of Zimbra SOAP service
:param account: The accoun... | python | def authenticate(url, account, key, by='name', expires=0, timestamp=None,
timeout=None, request_type="xml", admin_auth=False,
use_password=False, raise_on_error=False):
""" Authenticate to the Zimbra server
:param url: URL of Zimbra SOAP service
:param account: The accoun... | [
"def",
"authenticate",
"(",
"url",
",",
"account",
",",
"key",
",",
"by",
"=",
"'name'",
",",
"expires",
"=",
"0",
",",
"timestamp",
"=",
"None",
",",
"timeout",
"=",
"None",
",",
"request_type",
"=",
"\"xml\"",
",",
"admin_auth",
"=",
"False",
",",
... | Authenticate to the Zimbra server
:param url: URL of Zimbra SOAP service
:param account: The account to be authenticated against
:param key: The preauth key of the domain of the account or a password (if
admin_auth or use_password is True)
:param by: If the account is specified as a name, an ID o... | [
"Authenticate",
"to",
"the",
"Zimbra",
"server"
] | 8b839143c64b0507a30a9908ff39066ae4ef5d03 | https://github.com/Zimbra-Community/python-zimbra/blob/8b839143c64b0507a30a9908ff39066ae4ef5d03/pythonzimbra/tools/auth.py#L15-L119 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/read_dbf.py | read_dbf | def read_dbf(dbf_path, index = None, cols = False, incl_index = False):
"""
Read a dbf file as a pandas.DataFrame, optionally selecting the index
variable and which columns are to be loaded.
__author__ = "Dani Arribas-Bel <darribas@asu.edu> "
...
Arguments
---------
dbf_path : str
... | python | def read_dbf(dbf_path, index = None, cols = False, incl_index = False):
"""
Read a dbf file as a pandas.DataFrame, optionally selecting the index
variable and which columns are to be loaded.
__author__ = "Dani Arribas-Bel <darribas@asu.edu> "
...
Arguments
---------
dbf_path : str
... | [
"def",
"read_dbf",
"(",
"dbf_path",
",",
"index",
"=",
"None",
",",
"cols",
"=",
"False",
",",
"incl_index",
"=",
"False",
")",
":",
"db",
"=",
"ps",
".",
"open",
"(",
"dbf_path",
")",
"if",
"cols",
":",
"if",
"incl_index",
":",
"cols",
".",
"appen... | Read a dbf file as a pandas.DataFrame, optionally selecting the index
variable and which columns are to be loaded.
__author__ = "Dani Arribas-Bel <darribas@asu.edu> "
...
Arguments
---------
dbf_path : str
Path to the DBF file to be read
index : str
... | [
"Read",
"a",
"dbf",
"file",
"as",
"a",
"pandas",
".",
"DataFrame",
"optionally",
"selecting",
"the",
"index",
"variable",
"and",
"which",
"columns",
"are",
"to",
"be",
"loaded",
"."
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/read_dbf.py#L44-L84 | train |
Crunch-io/crunch-cube | src/cr/cube/min_base_size_mask.py | MinBaseSizeMask.column_mask | def column_mask(self):
"""ndarray, True where column margin <= min_base_size, same shape as slice."""
margin = compress_pruned(
self._slice.margin(
axis=0,
weighted=False,
include_transforms_for_dims=self._hs_dims,
prune=self._p... | python | def column_mask(self):
"""ndarray, True where column margin <= min_base_size, same shape as slice."""
margin = compress_pruned(
self._slice.margin(
axis=0,
weighted=False,
include_transforms_for_dims=self._hs_dims,
prune=self._p... | [
"def",
"column_mask",
"(",
"self",
")",
":",
"margin",
"=",
"compress_pruned",
"(",
"self",
".",
"_slice",
".",
"margin",
"(",
"axis",
"=",
"0",
",",
"weighted",
"=",
"False",
",",
"include_transforms_for_dims",
"=",
"self",
".",
"_hs_dims",
",",
"prune",
... | ndarray, True where column margin <= min_base_size, same shape as slice. | [
"ndarray",
"True",
"where",
"column",
"margin",
"<",
"=",
"min_base_size",
"same",
"shape",
"as",
"slice",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/min_base_size_mask.py#L28-L47 | train |
Crunch-io/crunch-cube | src/cr/cube/min_base_size_mask.py | MinBaseSizeMask.table_mask | def table_mask(self):
"""ndarray, True where table margin <= min_base_size, same shape as slice."""
margin = compress_pruned(
self._slice.margin(
axis=None,
weighted=False,
include_transforms_for_dims=self._hs_dims,
prune=self._... | python | def table_mask(self):
"""ndarray, True where table margin <= min_base_size, same shape as slice."""
margin = compress_pruned(
self._slice.margin(
axis=None,
weighted=False,
include_transforms_for_dims=self._hs_dims,
prune=self._... | [
"def",
"table_mask",
"(",
"self",
")",
":",
"margin",
"=",
"compress_pruned",
"(",
"self",
".",
"_slice",
".",
"margin",
"(",
"axis",
"=",
"None",
",",
"weighted",
"=",
"False",
",",
"include_transforms_for_dims",
"=",
"self",
".",
"_hs_dims",
",",
"prune"... | ndarray, True where table margin <= min_base_size, same shape as slice. | [
"ndarray",
"True",
"where",
"table",
"margin",
"<",
"=",
"min_base_size",
"same",
"shape",
"as",
"slice",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/min_base_size_mask.py#L72-L91 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/pairwise_significance.py | PairwiseSignificance.values | def values(self):
"""list of _ColumnPairwiseSignificance tests.
Result has as many elements as there are coliumns in the slice. Each
significance test contains `p_vals` and `t_stats` significance tests.
"""
# TODO: Figure out how to intersperse pairwise objects for columns
... | python | def values(self):
"""list of _ColumnPairwiseSignificance tests.
Result has as many elements as there are coliumns in the slice. Each
significance test contains `p_vals` and `t_stats` significance tests.
"""
# TODO: Figure out how to intersperse pairwise objects for columns
... | [
"def",
"values",
"(",
"self",
")",
":",
"return",
"[",
"_ColumnPairwiseSignificance",
"(",
"self",
".",
"_slice",
",",
"col_idx",
",",
"self",
".",
"_axis",
",",
"self",
".",
"_weighted",
",",
"self",
".",
"_alpha",
",",
"self",
".",
"_only_larger",
",",... | list of _ColumnPairwiseSignificance tests.
Result has as many elements as there are coliumns in the slice. Each
significance test contains `p_vals` and `t_stats` significance tests. | [
"list",
"of",
"_ColumnPairwiseSignificance",
"tests",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/pairwise_significance.py#L33-L52 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/pairwise_significance.py | PairwiseSignificance.pairwise_indices | def pairwise_indices(self):
"""ndarray containing tuples of pairwise indices."""
return np.array([sig.pairwise_indices for sig in self.values]).T | python | def pairwise_indices(self):
"""ndarray containing tuples of pairwise indices."""
return np.array([sig.pairwise_indices for sig in self.values]).T | [
"def",
"pairwise_indices",
"(",
"self",
")",
":",
"return",
"np",
".",
"array",
"(",
"[",
"sig",
".",
"pairwise_indices",
"for",
"sig",
"in",
"self",
".",
"values",
"]",
")",
".",
"T"
] | ndarray containing tuples of pairwise indices. | [
"ndarray",
"containing",
"tuples",
"of",
"pairwise",
"indices",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/pairwise_significance.py#L55-L57 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/pairwise_significance.py | PairwiseSignificance.summary_pairwise_indices | def summary_pairwise_indices(self):
"""ndarray containing tuples of pairwise indices for the column summary."""
summary_pairwise_indices = np.empty(
self.values[0].t_stats.shape[1], dtype=object
)
summary_pairwise_indices[:] = [
sig.summary_pairwise_indices for si... | python | def summary_pairwise_indices(self):
"""ndarray containing tuples of pairwise indices for the column summary."""
summary_pairwise_indices = np.empty(
self.values[0].t_stats.shape[1], dtype=object
)
summary_pairwise_indices[:] = [
sig.summary_pairwise_indices for si... | [
"def",
"summary_pairwise_indices",
"(",
"self",
")",
":",
"summary_pairwise_indices",
"=",
"np",
".",
"empty",
"(",
"self",
".",
"values",
"[",
"0",
"]",
".",
"t_stats",
".",
"shape",
"[",
"1",
"]",
",",
"dtype",
"=",
"object",
")",
"summary_pairwise_indic... | ndarray containing tuples of pairwise indices for the column summary. | [
"ndarray",
"containing",
"tuples",
"of",
"pairwise",
"indices",
"for",
"the",
"column",
"summary",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/pairwise_significance.py#L60-L68 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/calibration.py | Calibration.reset | def reset(self):
"""
Reset the calibration to it initial state
"""
simulation = self.survey_scenario.simulation
holder = simulation.get_holder(self.weight_name)
holder.array = numpy.array(self.initial_weight, dtype = holder.variable.dtype) | python | def reset(self):
"""
Reset the calibration to it initial state
"""
simulation = self.survey_scenario.simulation
holder = simulation.get_holder(self.weight_name)
holder.array = numpy.array(self.initial_weight, dtype = holder.variable.dtype) | [
"def",
"reset",
"(",
"self",
")",
":",
"simulation",
"=",
"self",
".",
"survey_scenario",
".",
"simulation",
"holder",
"=",
"simulation",
".",
"get_holder",
"(",
"self",
".",
"weight_name",
")",
"holder",
".",
"array",
"=",
"numpy",
".",
"array",
"(",
"s... | Reset the calibration to it initial state | [
"Reset",
"the",
"calibration",
"to",
"it",
"initial",
"state"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/calibration.py#L45-L51 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/calibration.py | Calibration._set_survey_scenario | def _set_survey_scenario(self, survey_scenario):
"""
Set survey scenario
:param survey_scenario: the survey scenario
"""
self.survey_scenario = survey_scenario
# TODO deal with baseline if reform is present
if survey_scenario.simulation is None:
... | python | def _set_survey_scenario(self, survey_scenario):
"""
Set survey scenario
:param survey_scenario: the survey scenario
"""
self.survey_scenario = survey_scenario
# TODO deal with baseline if reform is present
if survey_scenario.simulation is None:
... | [
"def",
"_set_survey_scenario",
"(",
"self",
",",
"survey_scenario",
")",
":",
"self",
".",
"survey_scenario",
"=",
"survey_scenario",
"if",
"survey_scenario",
".",
"simulation",
"is",
"None",
":",
"survey_scenario",
".",
"simulation",
"=",
"survey_scenario",
".",
... | Set survey scenario
:param survey_scenario: the survey scenario | [
"Set",
"survey",
"scenario"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/calibration.py#L53-L72 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/calibration.py | Calibration.set_parameters | def set_parameters(self, parameter, value):
"""
Set parameters value
:param parameter: the parameter to be set
:param value: the valeu used to set the parameter
"""
if parameter == 'lo':
self.parameters['lo'] = 1 / value
else:
... | python | def set_parameters(self, parameter, value):
"""
Set parameters value
:param parameter: the parameter to be set
:param value: the valeu used to set the parameter
"""
if parameter == 'lo':
self.parameters['lo'] = 1 / value
else:
... | [
"def",
"set_parameters",
"(",
"self",
",",
"parameter",
",",
"value",
")",
":",
"if",
"parameter",
"==",
"'lo'",
":",
"self",
".",
"parameters",
"[",
"'lo'",
"]",
"=",
"1",
"/",
"value",
"else",
":",
"self",
".",
"parameters",
"[",
"parameter",
"]",
... | Set parameters value
:param parameter: the parameter to be set
:param value: the valeu used to set the parameter | [
"Set",
"parameters",
"value"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/calibration.py#L74-L84 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/calibration.py | Calibration._build_calmar_data | def _build_calmar_data(self):
"""
Builds the data dictionnary used as calmar input argument
"""
# Select only filtered entities
assert self.initial_weight_name is not None
data = pd.DataFrame()
data[self.initial_weight_name] = self.initial_weight * self.filter... | python | def _build_calmar_data(self):
"""
Builds the data dictionnary used as calmar input argument
"""
# Select only filtered entities
assert self.initial_weight_name is not None
data = pd.DataFrame()
data[self.initial_weight_name] = self.initial_weight * self.filter... | [
"def",
"_build_calmar_data",
"(",
"self",
")",
":",
"assert",
"self",
".",
"initial_weight_name",
"is",
"not",
"None",
"data",
"=",
"pd",
".",
"DataFrame",
"(",
")",
"data",
"[",
"self",
".",
"initial_weight_name",
"]",
"=",
"self",
".",
"initial_weight",
... | Builds the data dictionnary used as calmar input argument | [
"Builds",
"the",
"data",
"dictionnary",
"used",
"as",
"calmar",
"input",
"argument"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/calibration.py#L131-L146 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/calibration.py | Calibration._update_weights | def _update_weights(self, margins, parameters = {}):
"""
Run calmar, stores new weights and returns adjusted margins
"""
data = self._build_calmar_data()
assert self.initial_weight_name is not None
parameters['initial_weight'] = self.initial_weight_name
val_po... | python | def _update_weights(self, margins, parameters = {}):
"""
Run calmar, stores new weights and returns adjusted margins
"""
data = self._build_calmar_data()
assert self.initial_weight_name is not None
parameters['initial_weight'] = self.initial_weight_name
val_po... | [
"def",
"_update_weights",
"(",
"self",
",",
"margins",
",",
"parameters",
"=",
"{",
"}",
")",
":",
"data",
"=",
"self",
".",
"_build_calmar_data",
"(",
")",
"assert",
"self",
".",
"initial_weight_name",
"is",
"not",
"None",
"parameters",
"[",
"'initial_weigh... | Run calmar, stores new weights and returns adjusted margins | [
"Run",
"calmar",
"stores",
"new",
"weights",
"and",
"returns",
"adjusted",
"margins"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/calibration.py#L148-L159 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/calibration.py | Calibration.set_calibrated_weights | def set_calibrated_weights(self):
"""
Modify the weights to use the calibrated weights
"""
period = self.period
survey_scenario = self.survey_scenario
assert survey_scenario.simulation is not None
for simulation in [survey_scenario.simulation, survey_scenario.... | python | def set_calibrated_weights(self):
"""
Modify the weights to use the calibrated weights
"""
period = self.period
survey_scenario = self.survey_scenario
assert survey_scenario.simulation is not None
for simulation in [survey_scenario.simulation, survey_scenario.... | [
"def",
"set_calibrated_weights",
"(",
"self",
")",
":",
"period",
"=",
"self",
".",
"period",
"survey_scenario",
"=",
"self",
".",
"survey_scenario",
"assert",
"survey_scenario",
".",
"simulation",
"is",
"not",
"None",
"for",
"simulation",
"in",
"[",
"survey_sce... | Modify the weights to use the calibrated weights | [
"Modify",
"the",
"weights",
"to",
"use",
"the",
"calibrated",
"weights"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/calibration.py#L178-L188 | train |
wooey/clinto | clinto/parsers/argparse_.py | get_parameter_action | def get_parameter_action(action):
"""
To foster a general schema that can accomodate multiple parsers, the general behavior here is described
rather than the specific language of a given parser. For instance, the 'append' action of an argument
is collapsing each argument given to a single argument. It a... | python | def get_parameter_action(action):
"""
To foster a general schema that can accomodate multiple parsers, the general behavior here is described
rather than the specific language of a given parser. For instance, the 'append' action of an argument
is collapsing each argument given to a single argument. It a... | [
"def",
"get_parameter_action",
"(",
"action",
")",
":",
"actions",
"=",
"set",
"(",
")",
"if",
"isinstance",
"(",
"action",
",",
"argparse",
".",
"_AppendAction",
")",
":",
"actions",
".",
"add",
"(",
"SPECIFY_EVERY_PARAM",
")",
"return",
"actions"
] | To foster a general schema that can accomodate multiple parsers, the general behavior here is described
rather than the specific language of a given parser. For instance, the 'append' action of an argument
is collapsing each argument given to a single argument. It also returns a set of actions as well, since
... | [
"To",
"foster",
"a",
"general",
"schema",
"that",
"can",
"accomodate",
"multiple",
"parsers",
"the",
"general",
"behavior",
"here",
"is",
"described",
"rather",
"than",
"the",
"specific",
"language",
"of",
"a",
"given",
"parser",
".",
"For",
"instance",
"the",... | f25be36710a391f1dc13214756df3be7cfa26993 | https://github.com/wooey/clinto/blob/f25be36710a391f1dc13214756df3be7cfa26993/clinto/parsers/argparse_.py#L45-L55 | train |
Crunch-io/crunch-cube | src/cr/cube/distributions/wishart.py | WishartCDF.wishart_pfaffian | def wishart_pfaffian(self):
"""ndarray of wishart pfaffian CDF, before normalization"""
return np.array(
[Pfaffian(self, val).value for i, val in np.ndenumerate(self._chisq)]
).reshape(self._chisq.shape) | python | def wishart_pfaffian(self):
"""ndarray of wishart pfaffian CDF, before normalization"""
return np.array(
[Pfaffian(self, val).value for i, val in np.ndenumerate(self._chisq)]
).reshape(self._chisq.shape) | [
"def",
"wishart_pfaffian",
"(",
"self",
")",
":",
"return",
"np",
".",
"array",
"(",
"[",
"Pfaffian",
"(",
"self",
",",
"val",
")",
".",
"value",
"for",
"i",
",",
"val",
"in",
"np",
".",
"ndenumerate",
"(",
"self",
".",
"_chisq",
")",
"]",
")",
"... | ndarray of wishart pfaffian CDF, before normalization | [
"ndarray",
"of",
"wishart",
"pfaffian",
"CDF",
"before",
"normalization"
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/distributions/wishart.py#L50-L54 | train |
Crunch-io/crunch-cube | src/cr/cube/distributions/wishart.py | WishartCDF.other_ind | def other_ind(self):
"""last row or column of square A"""
return np.full(self.n_min, self.size - 1, dtype=np.int) | python | def other_ind(self):
"""last row or column of square A"""
return np.full(self.n_min, self.size - 1, dtype=np.int) | [
"def",
"other_ind",
"(",
"self",
")",
":",
"return",
"np",
".",
"full",
"(",
"self",
".",
"n_min",
",",
"self",
".",
"size",
"-",
"1",
",",
"dtype",
"=",
"np",
".",
"int",
")"
] | last row or column of square A | [
"last",
"row",
"or",
"column",
"of",
"square",
"A"
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/distributions/wishart.py#L77-L79 | train |
Crunch-io/crunch-cube | src/cr/cube/distributions/wishart.py | WishartCDF.K | def K(self):
"""Normalizing constant for wishart CDF."""
K1 = np.float_power(pi, 0.5 * self.n_min * self.n_min)
K1 /= (
np.float_power(2, 0.5 * self.n_min * self._n_max)
* self._mgamma(0.5 * self._n_max, self.n_min)
* self._mgamma(0.5 * self.n_min, self.n_min)... | python | def K(self):
"""Normalizing constant for wishart CDF."""
K1 = np.float_power(pi, 0.5 * self.n_min * self.n_min)
K1 /= (
np.float_power(2, 0.5 * self.n_min * self._n_max)
* self._mgamma(0.5 * self._n_max, self.n_min)
* self._mgamma(0.5 * self.n_min, self.n_min)... | [
"def",
"K",
"(",
"self",
")",
":",
"K1",
"=",
"np",
".",
"float_power",
"(",
"pi",
",",
"0.5",
"*",
"self",
".",
"n_min",
"*",
"self",
".",
"n_min",
")",
"K1",
"/=",
"(",
"np",
".",
"float_power",
"(",
"2",
",",
"0.5",
"*",
"self",
".",
"n_mi... | Normalizing constant for wishart CDF. | [
"Normalizing",
"constant",
"for",
"wishart",
"CDF",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/distributions/wishart.py#L89-L103 | train |
Crunch-io/crunch-cube | src/cr/cube/distributions/wishart.py | Pfaffian.value | def value(self):
"""return float Cumulative Distribution Function.
The return value represents a floating point number of the CDF of the
largest eigenvalue of a Wishart(n, p) evaluated at chisq_val.
"""
wishart = self._wishart_cdf
# Prepare variables for integration alg... | python | def value(self):
"""return float Cumulative Distribution Function.
The return value represents a floating point number of the CDF of the
largest eigenvalue of a Wishart(n, p) evaluated at chisq_val.
"""
wishart = self._wishart_cdf
# Prepare variables for integration alg... | [
"def",
"value",
"(",
"self",
")",
":",
"wishart",
"=",
"self",
".",
"_wishart_cdf",
"A",
"=",
"self",
".",
"A",
"p",
"=",
"self",
".",
"_gammainc_a",
"g",
"=",
"gamma",
"(",
"wishart",
".",
"alpha_vec",
")",
"q_ind",
"=",
"np",
".",
"arange",
"(",
... | return float Cumulative Distribution Function.
The return value represents a floating point number of the CDF of the
largest eigenvalue of a Wishart(n, p) evaluated at chisq_val. | [
"return",
"float",
"Cumulative",
"Distribution",
"Function",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/distributions/wishart.py#L124-L151 | train |
Crunch-io/crunch-cube | src/cr/cube/distributions/wishart.py | Pfaffian.A | def A(self):
"""ndarray - a skew-symmetric matrix for integrating the target distribution"""
wishart = self._wishart_cdf
base = np.zeros([wishart.size, wishart.size])
if wishart.n_min % 2:
# If matrix has odd number of elements, we need to append a
# row and a co... | python | def A(self):
"""ndarray - a skew-symmetric matrix for integrating the target distribution"""
wishart = self._wishart_cdf
base = np.zeros([wishart.size, wishart.size])
if wishart.n_min % 2:
# If matrix has odd number of elements, we need to append a
# row and a co... | [
"def",
"A",
"(",
"self",
")",
":",
"wishart",
"=",
"self",
".",
"_wishart_cdf",
"base",
"=",
"np",
".",
"zeros",
"(",
"[",
"wishart",
".",
"size",
",",
"wishart",
".",
"size",
"]",
")",
"if",
"wishart",
".",
"n_min",
"%",
"2",
":",
"base",
"=",
... | ndarray - a skew-symmetric matrix for integrating the target distribution | [
"ndarray",
"-",
"a",
"skew",
"-",
"symmetric",
"matrix",
"for",
"integrating",
"the",
"target",
"distribution"
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/distributions/wishart.py#L154-L163 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.