repo
stringclasses 679
values | path
stringlengths 6
122
| func_name
stringlengths 2
76
| original_string
stringlengths 87
70.9k
| language
stringclasses 1
value | code
stringlengths 87
70.9k
| code_tokens
sequencelengths 20
6.91k
| docstring
stringlengths 1
21.7k
| docstring_tokens
sequencelengths 1
1.6k
| sha
stringclasses 679
values | url
stringlengths 92
213
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
xnuinside/clifier | clifier/clifier.py | Clifier.create_commands | def create_commands(self, commands, parser):
""" add commands to parser """
self.apply_defaults(commands)
def create_single_command(command):
keys = command['keys']
del command['keys']
kwargs = {}
for item in command:
kwargs[item] = command[item]
parser.add_argument(*keys, **kwargs)
if len(commands) > 1:
for command in commands:
create_single_command(command)
else:
create_single_command(commands[0]) | python | def create_commands(self, commands, parser):
""" add commands to parser """
self.apply_defaults(commands)
def create_single_command(command):
keys = command['keys']
del command['keys']
kwargs = {}
for item in command:
kwargs[item] = command[item]
parser.add_argument(*keys, **kwargs)
if len(commands) > 1:
for command in commands:
create_single_command(command)
else:
create_single_command(commands[0]) | [
"def",
"create_commands",
"(",
"self",
",",
"commands",
",",
"parser",
")",
":",
"self",
".",
"apply_defaults",
"(",
"commands",
")",
"def",
"create_single_command",
"(",
"command",
")",
":",
"keys",
"=",
"command",
"[",
"'keys'",
"]",
"del",
"command",
"[",
"'keys'",
"]",
"kwargs",
"=",
"{",
"}",
"for",
"item",
"in",
"command",
":",
"kwargs",
"[",
"item",
"]",
"=",
"command",
"[",
"item",
"]",
"parser",
".",
"add_argument",
"(",
"*",
"keys",
",",
"*",
"*",
"kwargs",
")",
"if",
"len",
"(",
"commands",
")",
">",
"1",
":",
"for",
"command",
"in",
"commands",
":",
"create_single_command",
"(",
"command",
")",
"else",
":",
"create_single_command",
"(",
"commands",
"[",
"0",
"]",
")"
] | add commands to parser | [
"add",
"commands",
"to",
"parser"
] | 3d704a30dc985bea3b876216accc53c19dc8b0df | https://github.com/xnuinside/clifier/blob/3d704a30dc985bea3b876216accc53c19dc8b0df/clifier/clifier.py#L59-L74 | valid |
xnuinside/clifier | clifier/clifier.py | Clifier.create_subparsers | def create_subparsers(self, parser):
""" get config for subparser and create commands"""
subparsers = parser.add_subparsers()
for name in self.config['subparsers']:
subparser = subparsers.add_parser(name)
self.create_commands(self.config['subparsers'][name], subparser) | python | def create_subparsers(self, parser):
""" get config for subparser and create commands"""
subparsers = parser.add_subparsers()
for name in self.config['subparsers']:
subparser = subparsers.add_parser(name)
self.create_commands(self.config['subparsers'][name], subparser) | [
"def",
"create_subparsers",
"(",
"self",
",",
"parser",
")",
":",
"subparsers",
"=",
"parser",
".",
"add_subparsers",
"(",
")",
"for",
"name",
"in",
"self",
".",
"config",
"[",
"'subparsers'",
"]",
":",
"subparser",
"=",
"subparsers",
".",
"add_parser",
"(",
"name",
")",
"self",
".",
"create_commands",
"(",
"self",
".",
"config",
"[",
"'subparsers'",
"]",
"[",
"name",
"]",
",",
"subparser",
")"
] | get config for subparser and create commands | [
"get",
"config",
"for",
"subparser",
"and",
"create",
"commands"
] | 3d704a30dc985bea3b876216accc53c19dc8b0df | https://github.com/xnuinside/clifier/blob/3d704a30dc985bea3b876216accc53c19dc8b0df/clifier/clifier.py#L77-L82 | valid |
xnuinside/clifier | clifier/clifier.py | Clifier.show_version | def show_version(self):
""" custom command line action to show version """
class ShowVersionAction(argparse.Action):
def __init__(inner_self, nargs=0, **kw):
super(ShowVersionAction, inner_self).__init__(nargs=nargs, **kw)
def __call__(inner_self, parser, args, value, option_string=None):
print("{parser_name} version: {version}".format(
parser_name=self.config.get(
"parser", {}).get("prog"),
version=self.prog_version))
return ShowVersionAction | python | def show_version(self):
""" custom command line action to show version """
class ShowVersionAction(argparse.Action):
def __init__(inner_self, nargs=0, **kw):
super(ShowVersionAction, inner_self).__init__(nargs=nargs, **kw)
def __call__(inner_self, parser, args, value, option_string=None):
print("{parser_name} version: {version}".format(
parser_name=self.config.get(
"parser", {}).get("prog"),
version=self.prog_version))
return ShowVersionAction | [
"def",
"show_version",
"(",
"self",
")",
":",
"class",
"ShowVersionAction",
"(",
"argparse",
".",
"Action",
")",
":",
"def",
"__init__",
"(",
"inner_self",
",",
"nargs",
"=",
"0",
",",
"*",
"*",
"kw",
")",
":",
"super",
"(",
"ShowVersionAction",
",",
"inner_self",
")",
".",
"__init__",
"(",
"nargs",
"=",
"nargs",
",",
"*",
"*",
"kw",
")",
"def",
"__call__",
"(",
"inner_self",
",",
"parser",
",",
"args",
",",
"value",
",",
"option_string",
"=",
"None",
")",
":",
"print",
"(",
"\"{parser_name} version: {version}\"",
".",
"format",
"(",
"parser_name",
"=",
"self",
".",
"config",
".",
"get",
"(",
"\"parser\"",
",",
"{",
"}",
")",
".",
"get",
"(",
"\"prog\"",
")",
",",
"version",
"=",
"self",
".",
"prog_version",
")",
")",
"return",
"ShowVersionAction"
] | custom command line action to show version | [
"custom",
"command",
"line",
"action",
"to",
"show",
"version"
] | 3d704a30dc985bea3b876216accc53c19dc8b0df | https://github.com/xnuinside/clifier/blob/3d704a30dc985bea3b876216accc53c19dc8b0df/clifier/clifier.py#L97-L108 | valid |
xnuinside/clifier | clifier/clifier.py | Clifier.check_path_action | def check_path_action(self):
""" custom command line action to check file exist """
class CheckPathAction(argparse.Action):
def __call__(self, parser, args, value, option_string=None):
if type(value) is list:
value = value[0]
user_value = value
if option_string == 'None':
if not os.path.isdir(value):
_current_user = os.path.expanduser("~")
if not value.startswith(_current_user) \
and not value.startswith(os.getcwd()):
if os.path.isdir(os.path.join(_current_user, value)):
value = os.path.join(_current_user, value)
elif os.path.isdir(os.path.join(os.getcwd(), value)):
value = os.path.join(os.getcwd(), value)
else:
value = None
else:
value = None
elif option_string == '--template-name':
if not os.path.isdir(value):
if not os.path.isdir(os.path.join(args.target, value)):
value = None
if not value:
logger.error("Could not to find path %s. Please provide "
"correct path to %s option",
user_value, option_string)
exit(1)
setattr(args, self.dest, value)
return CheckPathAction | python | def check_path_action(self):
""" custom command line action to check file exist """
class CheckPathAction(argparse.Action):
def __call__(self, parser, args, value, option_string=None):
if type(value) is list:
value = value[0]
user_value = value
if option_string == 'None':
if not os.path.isdir(value):
_current_user = os.path.expanduser("~")
if not value.startswith(_current_user) \
and not value.startswith(os.getcwd()):
if os.path.isdir(os.path.join(_current_user, value)):
value = os.path.join(_current_user, value)
elif os.path.isdir(os.path.join(os.getcwd(), value)):
value = os.path.join(os.getcwd(), value)
else:
value = None
else:
value = None
elif option_string == '--template-name':
if not os.path.isdir(value):
if not os.path.isdir(os.path.join(args.target, value)):
value = None
if not value:
logger.error("Could not to find path %s. Please provide "
"correct path to %s option",
user_value, option_string)
exit(1)
setattr(args, self.dest, value)
return CheckPathAction | [
"def",
"check_path_action",
"(",
"self",
")",
":",
"class",
"CheckPathAction",
"(",
"argparse",
".",
"Action",
")",
":",
"def",
"__call__",
"(",
"self",
",",
"parser",
",",
"args",
",",
"value",
",",
"option_string",
"=",
"None",
")",
":",
"if",
"type",
"(",
"value",
")",
"is",
"list",
":",
"value",
"=",
"value",
"[",
"0",
"]",
"user_value",
"=",
"value",
"if",
"option_string",
"==",
"'None'",
":",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"value",
")",
":",
"_current_user",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"\"~\"",
")",
"if",
"not",
"value",
".",
"startswith",
"(",
"_current_user",
")",
"and",
"not",
"value",
".",
"startswith",
"(",
"os",
".",
"getcwd",
"(",
")",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"os",
".",
"path",
".",
"join",
"(",
"_current_user",
",",
"value",
")",
")",
":",
"value",
"=",
"os",
".",
"path",
".",
"join",
"(",
"_current_user",
",",
"value",
")",
"elif",
"os",
".",
"path",
".",
"isdir",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"value",
")",
")",
":",
"value",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"value",
")",
"else",
":",
"value",
"=",
"None",
"else",
":",
"value",
"=",
"None",
"elif",
"option_string",
"==",
"'--template-name'",
":",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"value",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"os",
".",
"path",
".",
"join",
"(",
"args",
".",
"target",
",",
"value",
")",
")",
":",
"value",
"=",
"None",
"if",
"not",
"value",
":",
"logger",
".",
"error",
"(",
"\"Could not to find path %s. Please provide \"",
"\"correct path to %s option\"",
",",
"user_value",
",",
"option_string",
")",
"exit",
"(",
"1",
")",
"setattr",
"(",
"args",
",",
"self",
".",
"dest",
",",
"value",
")",
"return",
"CheckPathAction"
] | custom command line action to check file exist | [
"custom",
"command",
"line",
"action",
"to",
"check",
"file",
"exist"
] | 3d704a30dc985bea3b876216accc53c19dc8b0df | https://github.com/xnuinside/clifier/blob/3d704a30dc985bea3b876216accc53c19dc8b0df/clifier/clifier.py#L110-L141 | valid |
tklovett/PyShirtsIO | interactive_console.py | new_user | def new_user(yaml_path):
'''
Return the consumer and oauth tokens with three-legged OAuth process and
save in a yaml file in the user's home directory.
'''
print 'Retrieve API Key from https://www.shirts.io/accounts/api_console/'
api_key = raw_input('Shirts.io API Key: ')
tokens = {
'api_key': api_key,
}
yaml_file = open(yaml_path, 'w+')
yaml.dump(tokens, yaml_file, indent=2)
yaml_file.close()
return tokens | python | def new_user(yaml_path):
'''
Return the consumer and oauth tokens with three-legged OAuth process and
save in a yaml file in the user's home directory.
'''
print 'Retrieve API Key from https://www.shirts.io/accounts/api_console/'
api_key = raw_input('Shirts.io API Key: ')
tokens = {
'api_key': api_key,
}
yaml_file = open(yaml_path, 'w+')
yaml.dump(tokens, yaml_file, indent=2)
yaml_file.close()
return tokens | [
"def",
"new_user",
"(",
"yaml_path",
")",
":",
"print",
"'Retrieve API Key from https://www.shirts.io/accounts/api_console/'",
"api_key",
"=",
"raw_input",
"(",
"'Shirts.io API Key: '",
")",
"tokens",
"=",
"{",
"'api_key'",
":",
"api_key",
",",
"}",
"yaml_file",
"=",
"open",
"(",
"yaml_path",
",",
"'w+'",
")",
"yaml",
".",
"dump",
"(",
"tokens",
",",
"yaml_file",
",",
"indent",
"=",
"2",
")",
"yaml_file",
".",
"close",
"(",
")",
"return",
"tokens"
] | Return the consumer and oauth tokens with three-legged OAuth process and
save in a yaml file in the user's home directory. | [
"Return",
"the",
"consumer",
"and",
"oauth",
"tokens",
"with",
"three",
"-",
"legged",
"OAuth",
"process",
"and",
"save",
"in",
"a",
"yaml",
"file",
"in",
"the",
"user",
"s",
"home",
"directory",
"."
] | ff2f2d3b5e4ab2813abbce8545b27319c6af0def | https://github.com/tklovett/PyShirtsIO/blob/ff2f2d3b5e4ab2813abbce8545b27319c6af0def/interactive_console.py#L8-L25 | valid |
ibelie/typy | typy/google/protobuf/internal/python_message.py | _AddPropertiesForExtensions | def _AddPropertiesForExtensions(descriptor, cls):
"""Adds properties for all fields in this protocol message type."""
extension_dict = descriptor.extensions_by_name
for extension_name, extension_field in extension_dict.items():
constant_name = extension_name.upper() + "_FIELD_NUMBER"
setattr(cls, constant_name, extension_field.number) | python | def _AddPropertiesForExtensions(descriptor, cls):
"""Adds properties for all fields in this protocol message type."""
extension_dict = descriptor.extensions_by_name
for extension_name, extension_field in extension_dict.items():
constant_name = extension_name.upper() + "_FIELD_NUMBER"
setattr(cls, constant_name, extension_field.number) | [
"def",
"_AddPropertiesForExtensions",
"(",
"descriptor",
",",
"cls",
")",
":",
"extension_dict",
"=",
"descriptor",
".",
"extensions_by_name",
"for",
"extension_name",
",",
"extension_field",
"in",
"extension_dict",
".",
"items",
"(",
")",
":",
"constant_name",
"=",
"extension_name",
".",
"upper",
"(",
")",
"+",
"\"_FIELD_NUMBER\"",
"setattr",
"(",
"cls",
",",
"constant_name",
",",
"extension_field",
".",
"number",
")"
] | Adds properties for all fields in this protocol message type. | [
"Adds",
"properties",
"for",
"all",
"fields",
"in",
"this",
"protocol",
"message",
"type",
"."
] | 3616845fb91459aacd8df6bf82c5d91f4542bee7 | https://github.com/ibelie/typy/blob/3616845fb91459aacd8df6bf82c5d91f4542bee7/typy/google/protobuf/internal/python_message.py#L743-L748 | valid |
ibelie/typy | typy/google/protobuf/internal/python_message.py | _InternalUnpackAny | def _InternalUnpackAny(msg):
"""Unpacks Any message and returns the unpacked message.
This internal method is differnt from public Any Unpack method which takes
the target message as argument. _InternalUnpackAny method does not have
target message type and need to find the message type in descriptor pool.
Args:
msg: An Any message to be unpacked.
Returns:
The unpacked message.
"""
type_url = msg.type_url
db = symbol_database.Default()
if not type_url:
return None
# TODO(haberman): For now we just strip the hostname. Better logic will be
# required.
type_name = type_url.split("/")[-1]
descriptor = db.pool.FindMessageTypeByName(type_name)
if descriptor is None:
return None
message_class = db.GetPrototype(descriptor)
message = message_class()
message.ParseFromString(msg.value)
return message | python | def _InternalUnpackAny(msg):
"""Unpacks Any message and returns the unpacked message.
This internal method is differnt from public Any Unpack method which takes
the target message as argument. _InternalUnpackAny method does not have
target message type and need to find the message type in descriptor pool.
Args:
msg: An Any message to be unpacked.
Returns:
The unpacked message.
"""
type_url = msg.type_url
db = symbol_database.Default()
if not type_url:
return None
# TODO(haberman): For now we just strip the hostname. Better logic will be
# required.
type_name = type_url.split("/")[-1]
descriptor = db.pool.FindMessageTypeByName(type_name)
if descriptor is None:
return None
message_class = db.GetPrototype(descriptor)
message = message_class()
message.ParseFromString(msg.value)
return message | [
"def",
"_InternalUnpackAny",
"(",
"msg",
")",
":",
"type_url",
"=",
"msg",
".",
"type_url",
"db",
"=",
"symbol_database",
".",
"Default",
"(",
")",
"if",
"not",
"type_url",
":",
"return",
"None",
"# TODO(haberman): For now we just strip the hostname. Better logic will be",
"# required.",
"type_name",
"=",
"type_url",
".",
"split",
"(",
"\"/\"",
")",
"[",
"-",
"1",
"]",
"descriptor",
"=",
"db",
".",
"pool",
".",
"FindMessageTypeByName",
"(",
"type_name",
")",
"if",
"descriptor",
"is",
"None",
":",
"return",
"None",
"message_class",
"=",
"db",
".",
"GetPrototype",
"(",
"descriptor",
")",
"message",
"=",
"message_class",
"(",
")",
"message",
".",
"ParseFromString",
"(",
"msg",
".",
"value",
")",
"return",
"message"
] | Unpacks Any message and returns the unpacked message.
This internal method is differnt from public Any Unpack method which takes
the target message as argument. _InternalUnpackAny method does not have
target message type and need to find the message type in descriptor pool.
Args:
msg: An Any message to be unpacked.
Returns:
The unpacked message. | [
"Unpacks",
"Any",
"message",
"and",
"returns",
"the",
"unpacked",
"message",
"."
] | 3616845fb91459aacd8df6bf82c5d91f4542bee7 | https://github.com/ibelie/typy/blob/3616845fb91459aacd8df6bf82c5d91f4542bee7/typy/google/protobuf/internal/python_message.py#L916-L947 | valid |