id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
41,600 | jaraco/jaraco.logging | jaraco/logging.py | setup_requests_logging | def setup_requests_logging(level):
"""
Setup logging for 'requests' such that it logs details about the
connection, headers, etc.
"""
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(level)
requests_log.propagate = True
# enable debugging at httplib level
http_clie... | python | def setup_requests_logging(level):
"""
Setup logging for 'requests' such that it logs details about the
connection, headers, etc.
"""
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(level)
requests_log.propagate = True
# enable debugging at httplib level
http_clie... | [
"def",
"setup_requests_logging",
"(",
"level",
")",
":",
"requests_log",
"=",
"logging",
".",
"getLogger",
"(",
"\"requests.packages.urllib3\"",
")",
"requests_log",
".",
"setLevel",
"(",
"level",
")",
"requests_log",
".",
"propagate",
"=",
"True",
"# enable debuggi... | Setup logging for 'requests' such that it logs details about the
connection, headers, etc. | [
"Setup",
"logging",
"for",
"requests",
"such",
"that",
"it",
"logs",
"details",
"about",
"the",
"connection",
"headers",
"etc",
"."
] | 202d0d3b7c16503f9b8de83b6054f1306ae61930 | https://github.com/jaraco/jaraco.logging/blob/202d0d3b7c16503f9b8de83b6054f1306ae61930/jaraco/logging.py#L53-L63 |
41,601 | jaraco/jaraco.logging | jaraco/logging.py | TimestampFileHandler._set_period | def _set_period(self, period):
"""
Set the period for the timestamp. If period is 0 or None, no period
will be used.
"""
self._period = period
if period:
self._period_seconds = tempora.get_period_seconds(self._period)
self._date_format = tempora.get_date_format_string(
self._period_secon... | python | def _set_period(self, period):
"""
Set the period for the timestamp. If period is 0 or None, no period
will be used.
"""
self._period = period
if period:
self._period_seconds = tempora.get_period_seconds(self._period)
self._date_format = tempora.get_date_format_string(
self._period_secon... | [
"def",
"_set_period",
"(",
"self",
",",
"period",
")",
":",
"self",
".",
"_period",
"=",
"period",
"if",
"period",
":",
"self",
".",
"_period_seconds",
"=",
"tempora",
".",
"get_period_seconds",
"(",
"self",
".",
"_period",
")",
"self",
".",
"_date_format"... | Set the period for the timestamp. If period is 0 or None, no period
will be used. | [
"Set",
"the",
"period",
"for",
"the",
"timestamp",
".",
"If",
"period",
"is",
"0",
"or",
"None",
"no",
"period",
"will",
"be",
"used",
"."
] | 202d0d3b7c16503f9b8de83b6054f1306ae61930 | https://github.com/jaraco/jaraco.logging/blob/202d0d3b7c16503f9b8de83b6054f1306ae61930/jaraco/logging.py#L83-L95 |
41,602 | jaraco/jaraco.logging | jaraco/logging.py | TimestampFileHandler.get_filename | def get_filename(self, t):
"""
Return the appropriate filename for the given time
based on the defined period.
"""
root, ext = os.path.splitext(self.base_filename)
# remove seconds not significant to the period
if self._period_seconds:
t -= t % self._period_seconds
# convert it to a datetime... | python | def get_filename(self, t):
"""
Return the appropriate filename for the given time
based on the defined period.
"""
root, ext = os.path.splitext(self.base_filename)
# remove seconds not significant to the period
if self._period_seconds:
t -= t % self._period_seconds
# convert it to a datetime... | [
"def",
"get_filename",
"(",
"self",
",",
"t",
")",
":",
"root",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"self",
".",
"base_filename",
")",
"# remove seconds not significant to the period\r",
"if",
"self",
".",
"_period_seconds",
":",
"t",
"... | Return the appropriate filename for the given time
based on the defined period. | [
"Return",
"the",
"appropriate",
"filename",
"for",
"the",
"given",
"time",
"based",
"on",
"the",
"defined",
"period",
"."
] | 202d0d3b7c16503f9b8de83b6054f1306ae61930 | https://github.com/jaraco/jaraco.logging/blob/202d0d3b7c16503f9b8de83b6054f1306ae61930/jaraco/logging.py#L110-L133 |
41,603 | jaraco/jaraco.logging | jaraco/logging.py | TimestampFileHandler.emit | def emit(self, record):
"""
Emit a record.
Output the record to the file, ensuring that the currently-
opened file has the correct date.
"""
now = time.time()
current_name = self.get_filename(now)
try:
if not self.stream.name == current_name:
self._use_file(current_name)
except Att... | python | def emit(self, record):
"""
Emit a record.
Output the record to the file, ensuring that the currently-
opened file has the correct date.
"""
now = time.time()
current_name = self.get_filename(now)
try:
if not self.stream.name == current_name:
self._use_file(current_name)
except Att... | [
"def",
"emit",
"(",
"self",
",",
"record",
")",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"current_name",
"=",
"self",
".",
"get_filename",
"(",
"now",
")",
"try",
":",
"if",
"not",
"self",
".",
"stream",
".",
"name",
"==",
"current_name",
":... | Emit a record.
Output the record to the file, ensuring that the currently-
opened file has the correct date. | [
"Emit",
"a",
"record",
".",
"Output",
"the",
"record",
"to",
"the",
"file",
"ensuring",
"that",
"the",
"currently",
"-",
"opened",
"file",
"has",
"the",
"correct",
"date",
"."
] | 202d0d3b7c16503f9b8de83b6054f1306ae61930 | https://github.com/jaraco/jaraco.logging/blob/202d0d3b7c16503f9b8de83b6054f1306ae61930/jaraco/logging.py#L135-L150 |
41,604 | silver-castle/mach9 | mach9/static.py | register | def register(app, uri, file_or_directory, pattern,
use_modified_since, use_content_range):
# TODO: Though mach9 is not a file server, I feel like we should at least
# make a good effort here. Modified-since is nice, but we could
# also look into etags, expires, and caching
"""
... | python | def register(app, uri, file_or_directory, pattern,
use_modified_since, use_content_range):
# TODO: Though mach9 is not a file server, I feel like we should at least
# make a good effort here. Modified-since is nice, but we could
# also look into etags, expires, and caching
"""
... | [
"def",
"register",
"(",
"app",
",",
"uri",
",",
"file_or_directory",
",",
"pattern",
",",
"use_modified_since",
",",
"use_content_range",
")",
":",
"# TODO: Though mach9 is not a file server, I feel like we should at least",
"# make a good effort here. Modified-since is nice... | Register a static directory handler with Mach9 by adding a route to the
router and registering a handler.
:param app: Mach9
:param file_or_directory: File or directory path to serve from
:param uri: URL to serve from
:param pattern: regular expression used to match files in the URL
:param use_m... | [
"Register",
"a",
"static",
"directory",
"handler",
"with",
"Mach9",
"by",
"adding",
"a",
"route",
"to",
"the",
"router",
"and",
"registering",
"a",
"handler",
"."
] | 7a623aab3c70d89d36ade6901b6307e115400c5e | https://github.com/silver-castle/mach9/blob/7a623aab3c70d89d36ade6901b6307e115400c5e/mach9/static.py#L19-L104 |
41,605 | pyQode/pyqode-uic | pyqode_uic.py | fix_imports | def fix_imports(script):
"""
Replace "from PyQt5 import" by "from pyqode.qt import".
:param script: script path
"""
with open(script, 'r') as f_script:
lines = f_script.read().splitlines()
new_lines = []
for l in lines:
if l.startswith("import "):
l = "from . " +... | python | def fix_imports(script):
"""
Replace "from PyQt5 import" by "from pyqode.qt import".
:param script: script path
"""
with open(script, 'r') as f_script:
lines = f_script.read().splitlines()
new_lines = []
for l in lines:
if l.startswith("import "):
l = "from . " +... | [
"def",
"fix_imports",
"(",
"script",
")",
":",
"with",
"open",
"(",
"script",
",",
"'r'",
")",
"as",
"f_script",
":",
"lines",
"=",
"f_script",
".",
"read",
"(",
")",
".",
"splitlines",
"(",
")",
"new_lines",
"=",
"[",
"]",
"for",
"l",
"in",
"lines... | Replace "from PyQt5 import" by "from pyqode.qt import".
:param script: script path | [
"Replace",
"from",
"PyQt5",
"import",
"by",
"from",
"pyqode",
".",
"qt",
"import",
"."
] | e8b7a1e275dbb5d76031f197d93ede1ea505fdcb | https://github.com/pyQode/pyqode-uic/blob/e8b7a1e275dbb5d76031f197d93ede1ea505fdcb/pyqode_uic.py#L17-L33 |
41,606 | expert360/cfn-params | cfnparams/params.py | PythonParams.eval_py | def eval_py(self, _globals, _locals):
"""
Evaluates a file containing a Python params dictionary.
"""
try:
params = eval(self.script, _globals, _locals)
except NameError as e:
raise Exception(
'Failed to evaluate parameters: {}'
... | python | def eval_py(self, _globals, _locals):
"""
Evaluates a file containing a Python params dictionary.
"""
try:
params = eval(self.script, _globals, _locals)
except NameError as e:
raise Exception(
'Failed to evaluate parameters: {}'
... | [
"def",
"eval_py",
"(",
"self",
",",
"_globals",
",",
"_locals",
")",
":",
"try",
":",
"params",
"=",
"eval",
"(",
"self",
".",
"script",
",",
"_globals",
",",
"_locals",
")",
"except",
"NameError",
"as",
"e",
":",
"raise",
"Exception",
"(",
"'Failed to... | Evaluates a file containing a Python params dictionary. | [
"Evaluates",
"a",
"file",
"containing",
"a",
"Python",
"params",
"dictionary",
"."
] | f6d9d796b8ce346e9fd916e26ed08958e5356e31 | https://github.com/expert360/cfn-params/blob/f6d9d796b8ce346e9fd916e26ed08958e5356e31/cfnparams/params.py#L66-L80 |
41,607 | expert360/cfn-params | cfnparams/params.py | ParamsFactory.new | def new(cls, arg):
"""
Creates a new Parameter object from the given ParameterArgument.
"""
content = None
if arg.kind == 'file':
if os.path.exists(arg.value):
with open(arg.value, 'r') as f:
content = f.read()
else:
... | python | def new(cls, arg):
"""
Creates a new Parameter object from the given ParameterArgument.
"""
content = None
if arg.kind == 'file':
if os.path.exists(arg.value):
with open(arg.value, 'r') as f:
content = f.read()
else:
... | [
"def",
"new",
"(",
"cls",
",",
"arg",
")",
":",
"content",
"=",
"None",
"if",
"arg",
".",
"kind",
"==",
"'file'",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"arg",
".",
"value",
")",
":",
"with",
"open",
"(",
"arg",
".",
"value",
",",
... | Creates a new Parameter object from the given ParameterArgument. | [
"Creates",
"a",
"new",
"Parameter",
"object",
"from",
"the",
"given",
"ParameterArgument",
"."
] | f6d9d796b8ce346e9fd916e26ed08958e5356e31 | https://github.com/expert360/cfn-params/blob/f6d9d796b8ce346e9fd916e26ed08958e5356e31/cfnparams/params.py#L91-L111 |
41,608 | cstatz/maui | maui/mesh/rectilinear.py | RectilinearMesh.minimum_pitch | def minimum_pitch(self):
""" Returns the minimal pitch between two neighboring nodes of the mesh in each direction.
:return: Minimal pitch in each direction.
"""
pitch = self.pitch
minimal_pitch = []
for p in pitch:
minimal_pitch.append(min(p))
retu... | python | def minimum_pitch(self):
""" Returns the minimal pitch between two neighboring nodes of the mesh in each direction.
:return: Minimal pitch in each direction.
"""
pitch = self.pitch
minimal_pitch = []
for p in pitch:
minimal_pitch.append(min(p))
retu... | [
"def",
"minimum_pitch",
"(",
"self",
")",
":",
"pitch",
"=",
"self",
".",
"pitch",
"minimal_pitch",
"=",
"[",
"]",
"for",
"p",
"in",
"pitch",
":",
"minimal_pitch",
".",
"append",
"(",
"min",
"(",
"p",
")",
")",
"return",
"min",
"(",
"minimal_pitch",
... | Returns the minimal pitch between two neighboring nodes of the mesh in each direction.
:return: Minimal pitch in each direction. | [
"Returns",
"the",
"minimal",
"pitch",
"between",
"two",
"neighboring",
"nodes",
"of",
"the",
"mesh",
"in",
"each",
"direction",
"."
] | db99986e93699ee20c5cffdd5b4ee446f8607c5d | https://github.com/cstatz/maui/blob/db99986e93699ee20c5cffdd5b4ee446f8607c5d/maui/mesh/rectilinear.py#L154-L165 |
41,609 | cstatz/maui | maui/mesh/rectilinear.py | RectilinearMesh.surrounding_nodes | def surrounding_nodes(self, position):
""" Returns nearest node indices and direction of opposite node.
:param position: Position inside the mesh to search nearest node for as (x,y,z)
:return: Nearest node indices and direction of opposite node.
"""
n_node_index, n_node_positio... | python | def surrounding_nodes(self, position):
""" Returns nearest node indices and direction of opposite node.
:param position: Position inside the mesh to search nearest node for as (x,y,z)
:return: Nearest node indices and direction of opposite node.
"""
n_node_index, n_node_positio... | [
"def",
"surrounding_nodes",
"(",
"self",
",",
"position",
")",
":",
"n_node_index",
",",
"n_node_position",
",",
"n_node_error",
"=",
"self",
".",
"nearest_node",
"(",
"position",
")",
"if",
"n_node_error",
"==",
"0.0",
":",
"index_mod",
"=",
"[",
"]",
"for"... | Returns nearest node indices and direction of opposite node.
:param position: Position inside the mesh to search nearest node for as (x,y,z)
:return: Nearest node indices and direction of opposite node. | [
"Returns",
"nearest",
"node",
"indices",
"and",
"direction",
"of",
"opposite",
"node",
"."
] | db99986e93699ee20c5cffdd5b4ee446f8607c5d | https://github.com/cstatz/maui/blob/db99986e93699ee20c5cffdd5b4ee446f8607c5d/maui/mesh/rectilinear.py#L181-L216 |
41,610 | MisanthropicBit/colorise | colorise/ColorFormatParser.py | ColorFormatParser.tokenize | def tokenize(self, string):
"""Tokenize a string and return an iterator over its tokens."""
it = colorise.compat.ifilter(None, self._pattern.finditer(string))
try:
t = colorise.compat.next(it)
except StopIteration:
yield string, False
return
... | python | def tokenize(self, string):
"""Tokenize a string and return an iterator over its tokens."""
it = colorise.compat.ifilter(None, self._pattern.finditer(string))
try:
t = colorise.compat.next(it)
except StopIteration:
yield string, False
return
... | [
"def",
"tokenize",
"(",
"self",
",",
"string",
")",
":",
"it",
"=",
"colorise",
".",
"compat",
".",
"ifilter",
"(",
"None",
",",
"self",
".",
"_pattern",
".",
"finditer",
"(",
"string",
")",
")",
"try",
":",
"t",
"=",
"colorise",
".",
"compat",
"."... | Tokenize a string and return an iterator over its tokens. | [
"Tokenize",
"a",
"string",
"and",
"return",
"an",
"iterator",
"over",
"its",
"tokens",
"."
] | e630df74b8b27680a43c370ddbe98766be50158c | https://github.com/MisanthropicBit/colorise/blob/e630df74b8b27680a43c370ddbe98766be50158c/colorise/ColorFormatParser.py#L35-L83 |
41,611 | MisanthropicBit/colorise | colorise/ColorFormatParser.py | ColorFormatParser.parse | def parse(self, format_string):
"""Parse color syntax from a formatted string."""
txt, state = '', 0
colorstack = [(None, None)]
itokens = self.tokenize(format_string)
for token, escaped in itokens:
if token == self._START_TOKEN and not escaped:
if tx... | python | def parse(self, format_string):
"""Parse color syntax from a formatted string."""
txt, state = '', 0
colorstack = [(None, None)]
itokens = self.tokenize(format_string)
for token, escaped in itokens:
if token == self._START_TOKEN and not escaped:
if tx... | [
"def",
"parse",
"(",
"self",
",",
"format_string",
")",
":",
"txt",
",",
"state",
"=",
"''",
",",
"0",
"colorstack",
"=",
"[",
"(",
"None",
",",
"None",
")",
"]",
"itokens",
"=",
"self",
".",
"tokenize",
"(",
"format_string",
")",
"for",
"token",
"... | Parse color syntax from a formatted string. | [
"Parse",
"color",
"syntax",
"from",
"a",
"formatted",
"string",
"."
] | e630df74b8b27680a43c370ddbe98766be50158c | https://github.com/MisanthropicBit/colorise/blob/e630df74b8b27680a43c370ddbe98766be50158c/colorise/ColorFormatParser.py#L85-L130 |
41,612 | sherlocke/pywatson | pywatson/answer/evidence.py | Evidence.from_mapping | def from_mapping(cls, evidence_mapping):
"""Create an Evidence instance from the given mapping
:param evidence_mapping: a mapping (e.g. dict) of values provided by Watson
:return: a new Evidence
"""
return cls(metadata_map=MetadataMap.from_mapping(evidence_mapping['metadataMap']... | python | def from_mapping(cls, evidence_mapping):
"""Create an Evidence instance from the given mapping
:param evidence_mapping: a mapping (e.g. dict) of values provided by Watson
:return: a new Evidence
"""
return cls(metadata_map=MetadataMap.from_mapping(evidence_mapping['metadataMap']... | [
"def",
"from_mapping",
"(",
"cls",
",",
"evidence_mapping",
")",
":",
"return",
"cls",
"(",
"metadata_map",
"=",
"MetadataMap",
".",
"from_mapping",
"(",
"evidence_mapping",
"[",
"'metadataMap'",
"]",
")",
",",
"copyright",
"=",
"evidence_mapping",
"[",
"'copyri... | Create an Evidence instance from the given mapping
:param evidence_mapping: a mapping (e.g. dict) of values provided by Watson
:return: a new Evidence | [
"Create",
"an",
"Evidence",
"instance",
"from",
"the",
"given",
"mapping"
] | ab15d1ca3c01a185136b420d443f712dfa865485 | https://github.com/sherlocke/pywatson/blob/ab15d1ca3c01a185136b420d443f712dfa865485/pywatson/answer/evidence.py#L17-L30 |
41,613 | letuananh/puchikarui | puchikarui/puchikarui.py | to_obj | def to_obj(cls, obj_data=None, *fields, **field_map):
''' prioritize obj_dict when there are conficts '''
obj_dict = obj_data.__dict__ if hasattr(obj_data, '__dict__') else obj_data
if not fields:
fields = obj_dict.keys()
obj = cls()
update_obj(obj_dict, obj, *fields, **field_map)
return... | python | def to_obj(cls, obj_data=None, *fields, **field_map):
''' prioritize obj_dict when there are conficts '''
obj_dict = obj_data.__dict__ if hasattr(obj_data, '__dict__') else obj_data
if not fields:
fields = obj_dict.keys()
obj = cls()
update_obj(obj_dict, obj, *fields, **field_map)
return... | [
"def",
"to_obj",
"(",
"cls",
",",
"obj_data",
"=",
"None",
",",
"*",
"fields",
",",
"*",
"*",
"field_map",
")",
":",
"obj_dict",
"=",
"obj_data",
".",
"__dict__",
"if",
"hasattr",
"(",
"obj_data",
",",
"'__dict__'",
")",
"else",
"obj_data",
"if",
"not"... | prioritize obj_dict when there are conficts | [
"prioritize",
"obj_dict",
"when",
"there",
"are",
"conficts"
] | f6dcc5e353354aab6cb24701910ee2ee5368c9cd | https://github.com/letuananh/puchikarui/blob/f6dcc5e353354aab6cb24701910ee2ee5368c9cd/puchikarui/puchikarui.py#L62-L69 |
41,614 | letuananh/puchikarui | puchikarui/puchikarui.py | with_ctx | def with_ctx(func=None):
''' Auto create a new context if not available '''
if not func:
return functools.partial(with_ctx)
@functools.wraps(func)
def func_with_context(_obj, *args, **kwargs):
if 'ctx' not in kwargs or kwargs['ctx'] is None:
# if context is empty, ensure con... | python | def with_ctx(func=None):
''' Auto create a new context if not available '''
if not func:
return functools.partial(with_ctx)
@functools.wraps(func)
def func_with_context(_obj, *args, **kwargs):
if 'ctx' not in kwargs or kwargs['ctx'] is None:
# if context is empty, ensure con... | [
"def",
"with_ctx",
"(",
"func",
"=",
"None",
")",
":",
"if",
"not",
"func",
":",
"return",
"functools",
".",
"partial",
"(",
"with_ctx",
")",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"func_with_context",
"(",
"_obj",
",",
"*",
"args",
... | Auto create a new context if not available | [
"Auto",
"create",
"a",
"new",
"context",
"if",
"not",
"available"
] | f6dcc5e353354aab6cb24701910ee2ee5368c9cd | https://github.com/letuananh/puchikarui/blob/f6dcc5e353354aab6cb24701910ee2ee5368c9cd/puchikarui/puchikarui.py#L581-L597 |
41,615 | letuananh/puchikarui | puchikarui/puchikarui.py | DataSource.open | def open(self, auto_commit=None, schema=None):
''' Create a context to execute queries '''
if schema is None:
schema = self.schema
ac = auto_commit if auto_commit is not None else schema.auto_commit
exe = ExecutionContext(self.path, schema=schema, auto_commit=ac)
# se... | python | def open(self, auto_commit=None, schema=None):
''' Create a context to execute queries '''
if schema is None:
schema = self.schema
ac = auto_commit if auto_commit is not None else schema.auto_commit
exe = ExecutionContext(self.path, schema=schema, auto_commit=ac)
# se... | [
"def",
"open",
"(",
"self",
",",
"auto_commit",
"=",
"None",
",",
"schema",
"=",
"None",
")",
":",
"if",
"schema",
"is",
"None",
":",
"schema",
"=",
"self",
".",
"schema",
"ac",
"=",
"auto_commit",
"if",
"auto_commit",
"is",
"not",
"None",
"else",
"s... | Create a context to execute queries | [
"Create",
"a",
"context",
"to",
"execute",
"queries"
] | f6dcc5e353354aab6cb24701910ee2ee5368c9cd | https://github.com/letuananh/puchikarui/blob/f6dcc5e353354aab6cb24701910ee2ee5368c9cd/puchikarui/puchikarui.py#L254-L272 |
41,616 | letuananh/puchikarui | puchikarui/puchikarui.py | QueryBuilder.build_insert | def build_insert(self, table, values, columns=None):
''' Insert an active record into DB and return lastrowid if available '''
if not columns:
columns = table.columns
if len(values) < len(columns):
column_names = ','.join(columns[-len(values):])
else:
... | python | def build_insert(self, table, values, columns=None):
''' Insert an active record into DB and return lastrowid if available '''
if not columns:
columns = table.columns
if len(values) < len(columns):
column_names = ','.join(columns[-len(values):])
else:
... | [
"def",
"build_insert",
"(",
"self",
",",
"table",
",",
"values",
",",
"columns",
"=",
"None",
")",
":",
"if",
"not",
"columns",
":",
"columns",
"=",
"table",
".",
"columns",
"if",
"len",
"(",
"values",
")",
"<",
"len",
"(",
"columns",
")",
":",
"co... | Insert an active record into DB and return lastrowid if available | [
"Insert",
"an",
"active",
"record",
"into",
"DB",
"and",
"return",
"lastrowid",
"if",
"available"
] | f6dcc5e353354aab6cb24701910ee2ee5368c9cd | https://github.com/letuananh/puchikarui/blob/f6dcc5e353354aab6cb24701910ee2ee5368c9cd/puchikarui/puchikarui.py#L325-L334 |
41,617 | letuananh/puchikarui | puchikarui/puchikarui.py | ExecutionContext.select_record | def select_record(self, table, where=None, values=None, orderby=None, limit=None, columns=None):
''' Support these keywords where, values, orderby, limit and columns'''
query = self.schema.query_builder.build_select(table, where, orderby, limit, columns)
return table.to_table(self.execute(query,... | python | def select_record(self, table, where=None, values=None, orderby=None, limit=None, columns=None):
''' Support these keywords where, values, orderby, limit and columns'''
query = self.schema.query_builder.build_select(table, where, orderby, limit, columns)
return table.to_table(self.execute(query,... | [
"def",
"select_record",
"(",
"self",
",",
"table",
",",
"where",
"=",
"None",
",",
"values",
"=",
"None",
",",
"orderby",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"columns",
"=",
"None",
")",
":",
"query",
"=",
"self",
".",
"schema",
".",
"quer... | Support these keywords where, values, orderby, limit and columns | [
"Support",
"these",
"keywords",
"where",
"values",
"orderby",
"limit",
"and",
"columns"
] | f6dcc5e353354aab6cb24701910ee2ee5368c9cd | https://github.com/letuananh/puchikarui/blob/f6dcc5e353354aab6cb24701910ee2ee5368c9cd/puchikarui/puchikarui.py#L422-L425 |
41,618 | israel-lugo/capidup | capidup/finddups.py | should_be_excluded | def should_be_excluded(name, exclude_patterns):
"""Check if a name should be excluded.
Returns True if name matches at least one of the exclude patterns in
the exclude_patterns list.
"""
for pattern in exclude_patterns:
if fnmatch.fnmatch(name, pattern):
return True
return ... | python | def should_be_excluded(name, exclude_patterns):
"""Check if a name should be excluded.
Returns True if name matches at least one of the exclude patterns in
the exclude_patterns list.
"""
for pattern in exclude_patterns:
if fnmatch.fnmatch(name, pattern):
return True
return ... | [
"def",
"should_be_excluded",
"(",
"name",
",",
"exclude_patterns",
")",
":",
"for",
"pattern",
"in",
"exclude_patterns",
":",
"if",
"fnmatch",
".",
"fnmatch",
"(",
"name",
",",
"pattern",
")",
":",
"return",
"True",
"return",
"False"
] | Check if a name should be excluded.
Returns True if name matches at least one of the exclude patterns in
the exclude_patterns list. | [
"Check",
"if",
"a",
"name",
"should",
"be",
"excluded",
"."
] | 7524d04f6c7ca1e32b695e62d9894db2dc0e8705 | https://github.com/israel-lugo/capidup/blob/7524d04f6c7ca1e32b695e62d9894db2dc0e8705/capidup/finddups.py#L85-L95 |
41,619 | israel-lugo/capidup | capidup/finddups.py | filter_visited | def filter_visited(curr_dir, subdirs, already_visited, follow_dirlinks, on_error):
"""Filter subdirs that have already been visited.
This is used to avoid loops in the search performed by os.walk() in
index_files_by_size.
curr_dir is the path of the current directory, as returned by os.walk().
su... | python | def filter_visited(curr_dir, subdirs, already_visited, follow_dirlinks, on_error):
"""Filter subdirs that have already been visited.
This is used to avoid loops in the search performed by os.walk() in
index_files_by_size.
curr_dir is the path of the current directory, as returned by os.walk().
su... | [
"def",
"filter_visited",
"(",
"curr_dir",
",",
"subdirs",
",",
"already_visited",
",",
"follow_dirlinks",
",",
"on_error",
")",
":",
"filtered",
"=",
"[",
"]",
"to_visit",
"=",
"set",
"(",
")",
"_already_visited",
"=",
"already_visited",
".",
"copy",
"(",
")... | Filter subdirs that have already been visited.
This is used to avoid loops in the search performed by os.walk() in
index_files_by_size.
curr_dir is the path of the current directory, as returned by os.walk().
subdirs is the list of subdirectories for the current directory, as
returned by os.walk(... | [
"Filter",
"subdirs",
"that",
"have",
"already",
"been",
"visited",
"."
] | 7524d04f6c7ca1e32b695e62d9894db2dc0e8705 | https://github.com/israel-lugo/capidup/blob/7524d04f6c7ca1e32b695e62d9894db2dc0e8705/capidup/finddups.py#L113-L165 |
41,620 | israel-lugo/capidup | capidup/finddups.py | index_files_by_size | def index_files_by_size(root, files_by_size, exclude_dirs, exclude_files,
follow_dirlinks):
"""Recursively index files under a root directory.
Each regular file is added *in-place* to the files_by_size dictionary,
according to the file size. This is a (possibly empty) dictionary of
lists of fil... | python | def index_files_by_size(root, files_by_size, exclude_dirs, exclude_files,
follow_dirlinks):
"""Recursively index files under a root directory.
Each regular file is added *in-place* to the files_by_size dictionary,
according to the file size. This is a (possibly empty) dictionary of
lists of fil... | [
"def",
"index_files_by_size",
"(",
"root",
",",
"files_by_size",
",",
"exclude_dirs",
",",
"exclude_files",
",",
"follow_dirlinks",
")",
":",
"# encapsulate the value in a list, so we can modify it by reference",
"# inside the auxiliary function",
"errors",
"=",
"[",
"]",
"al... | Recursively index files under a root directory.
Each regular file is added *in-place* to the files_by_size dictionary,
according to the file size. This is a (possibly empty) dictionary of
lists of filenames, indexed by file size.
exclude_dirs is a list of glob patterns to exclude directories.
excl... | [
"Recursively",
"index",
"files",
"under",
"a",
"root",
"directory",
"."
] | 7524d04f6c7ca1e32b695e62d9894db2dc0e8705 | https://github.com/israel-lugo/capidup/blob/7524d04f6c7ca1e32b695e62d9894db2dc0e8705/capidup/finddups.py#L168-L245 |
41,621 | israel-lugo/capidup | capidup/finddups.py | calculate_md5 | def calculate_md5(filename, length):
"""Calculate the MD5 hash of a file, up to length bytes.
Returns the MD5 in its binary form, as an 8-byte string. Raises IOError
or OSError in case of error.
"""
assert length >= 0
# shortcut: MD5 of an empty string is 'd41d8cd98f00b204e9800998ecf8427e',
... | python | def calculate_md5(filename, length):
"""Calculate the MD5 hash of a file, up to length bytes.
Returns the MD5 in its binary form, as an 8-byte string. Raises IOError
or OSError in case of error.
"""
assert length >= 0
# shortcut: MD5 of an empty string is 'd41d8cd98f00b204e9800998ecf8427e',
... | [
"def",
"calculate_md5",
"(",
"filename",
",",
"length",
")",
":",
"assert",
"length",
">=",
"0",
"# shortcut: MD5 of an empty string is 'd41d8cd98f00b204e9800998ecf8427e',",
"# represented here in binary",
"if",
"length",
"==",
"0",
":",
"return",
"'\\xd4\\x1d\\x8c\\xd9\\x8f\... | Calculate the MD5 hash of a file, up to length bytes.
Returns the MD5 in its binary form, as an 8-byte string. Raises IOError
or OSError in case of error. | [
"Calculate",
"the",
"MD5",
"hash",
"of",
"a",
"file",
"up",
"to",
"length",
"bytes",
"."
] | 7524d04f6c7ca1e32b695e62d9894db2dc0e8705 | https://github.com/israel-lugo/capidup/blob/7524d04f6c7ca1e32b695e62d9894db2dc0e8705/capidup/finddups.py#L249-L289 |
41,622 | israel-lugo/capidup | capidup/finddups.py | find_duplicates | def find_duplicates(filenames, max_size):
"""Find duplicates in a list of files, comparing up to `max_size` bytes.
Returns a 2-tuple of two values: ``(duplicate_groups, errors)``.
`duplicate_groups` is a (possibly empty) list of lists: the names of
files that have at least two copies, grouped together... | python | def find_duplicates(filenames, max_size):
"""Find duplicates in a list of files, comparing up to `max_size` bytes.
Returns a 2-tuple of two values: ``(duplicate_groups, errors)``.
`duplicate_groups` is a (possibly empty) list of lists: the names of
files that have at least two copies, grouped together... | [
"def",
"find_duplicates",
"(",
"filenames",
",",
"max_size",
")",
":",
"errors",
"=",
"[",
"]",
"# shortcut: can't have duplicates if there aren't at least 2 files",
"if",
"len",
"(",
"filenames",
")",
"<",
"2",
":",
"return",
"[",
"]",
",",
"errors",
"# shortcut:... | Find duplicates in a list of files, comparing up to `max_size` bytes.
Returns a 2-tuple of two values: ``(duplicate_groups, errors)``.
`duplicate_groups` is a (possibly empty) list of lists: the names of
files that have at least two copies, grouped together.
`errors` is a list of error messages that ... | [
"Find",
"duplicates",
"in",
"a",
"list",
"of",
"files",
"comparing",
"up",
"to",
"max_size",
"bytes",
"."
] | 7524d04f6c7ca1e32b695e62d9894db2dc0e8705 | https://github.com/israel-lugo/capidup/blob/7524d04f6c7ca1e32b695e62d9894db2dc0e8705/capidup/finddups.py#L293-L350 |
41,623 | israel-lugo/capidup | capidup/finddups.py | find_duplicates_in_dirs | def find_duplicates_in_dirs(directories, exclude_dirs=None, exclude_files=None,
follow_dirlinks=False):
"""Recursively scan a list of directories, looking for duplicate files.
`exclude_dirs`, if provided, should be a list of glob patterns.
Subdirectories whose names match these patterns are exclude... | python | def find_duplicates_in_dirs(directories, exclude_dirs=None, exclude_files=None,
follow_dirlinks=False):
"""Recursively scan a list of directories, looking for duplicate files.
`exclude_dirs`, if provided, should be a list of glob patterns.
Subdirectories whose names match these patterns are exclude... | [
"def",
"find_duplicates_in_dirs",
"(",
"directories",
",",
"exclude_dirs",
"=",
"None",
",",
"exclude_files",
"=",
"None",
",",
"follow_dirlinks",
"=",
"False",
")",
":",
"if",
"exclude_dirs",
"is",
"None",
":",
"exclude_dirs",
"=",
"[",
"]",
"if",
"exclude_fi... | Recursively scan a list of directories, looking for duplicate files.
`exclude_dirs`, if provided, should be a list of glob patterns.
Subdirectories whose names match these patterns are excluded from the
scan.
`exclude_files`, if provided, should be a list of glob patterns. Files
whose names match ... | [
"Recursively",
"scan",
"a",
"list",
"of",
"directories",
"looking",
"for",
"duplicate",
"files",
"."
] | 7524d04f6c7ca1e32b695e62d9894db2dc0e8705 | https://github.com/israel-lugo/capidup/blob/7524d04f6c7ca1e32b695e62d9894db2dc0e8705/capidup/finddups.py#L355-L438 |
41,624 | timothydmorton/orbitutils | orbitutils/utils.py | semimajor | def semimajor(P,M):
"""P, M can be ``Quantity`` objects; otherwise default to day, M_sun
"""
if type(P) != Quantity:
P = P*u.day
if type(M) != Quantity:
M = M*u.M_sun
a = ((P/2/np.pi)**2*const.G*M)**(1./3)
return a.to(u.AU) | python | def semimajor(P,M):
"""P, M can be ``Quantity`` objects; otherwise default to day, M_sun
"""
if type(P) != Quantity:
P = P*u.day
if type(M) != Quantity:
M = M*u.M_sun
a = ((P/2/np.pi)**2*const.G*M)**(1./3)
return a.to(u.AU) | [
"def",
"semimajor",
"(",
"P",
",",
"M",
")",
":",
"if",
"type",
"(",
"P",
")",
"!=",
"Quantity",
":",
"P",
"=",
"P",
"*",
"u",
".",
"day",
"if",
"type",
"(",
"M",
")",
"!=",
"Quantity",
":",
"M",
"=",
"M",
"*",
"u",
".",
"M_sun",
"a",
"="... | P, M can be ``Quantity`` objects; otherwise default to day, M_sun | [
"P",
"M",
"can",
"be",
"Quantity",
"objects",
";",
"otherwise",
"default",
"to",
"day",
"M_sun"
] | 949c6b901e519458d80b8d7427916c0698e4013e | https://github.com/timothydmorton/orbitutils/blob/949c6b901e519458d80b8d7427916c0698e4013e/orbitutils/utils.py#L15-L23 |
41,625 | timothydmorton/orbitutils | orbitutils/utils.py | random_spherepos | def random_spherepos(n):
"""returns SkyCoord object with n positions randomly oriented on the unit sphere
Parameters
----------
n : int
number of positions desired
Returns
-------
c : ``SkyCoord`` object with random positions
"""
signs = np.sign(rand.uniform(-1,1,size=n))
... | python | def random_spherepos(n):
"""returns SkyCoord object with n positions randomly oriented on the unit sphere
Parameters
----------
n : int
number of positions desired
Returns
-------
c : ``SkyCoord`` object with random positions
"""
signs = np.sign(rand.uniform(-1,1,size=n))
... | [
"def",
"random_spherepos",
"(",
"n",
")",
":",
"signs",
"=",
"np",
".",
"sign",
"(",
"rand",
".",
"uniform",
"(",
"-",
"1",
",",
"1",
",",
"size",
"=",
"n",
")",
")",
"thetas",
"=",
"Angle",
"(",
"np",
".",
"arccos",
"(",
"rand",
".",
"uniform"... | returns SkyCoord object with n positions randomly oriented on the unit sphere
Parameters
----------
n : int
number of positions desired
Returns
-------
c : ``SkyCoord`` object with random positions | [
"returns",
"SkyCoord",
"object",
"with",
"n",
"positions",
"randomly",
"oriented",
"on",
"the",
"unit",
"sphere"
] | 949c6b901e519458d80b8d7427916c0698e4013e | https://github.com/timothydmorton/orbitutils/blob/949c6b901e519458d80b8d7427916c0698e4013e/orbitutils/utils.py#L25-L41 |
41,626 | sherlocke/pywatson | pywatson/util/dictable.py | Dictable.to_dict | def to_dict(self):
"""
Return a dict of all instance variables with truthy values,
with key names camelized
"""
return {
inflection.camelize(k, False): v
for k, v in self.__dict__.items()
if v
} | python | def to_dict(self):
"""
Return a dict of all instance variables with truthy values,
with key names camelized
"""
return {
inflection.camelize(k, False): v
for k, v in self.__dict__.items()
if v
} | [
"def",
"to_dict",
"(",
"self",
")",
":",
"return",
"{",
"inflection",
".",
"camelize",
"(",
"k",
",",
"False",
")",
":",
"v",
"for",
"k",
",",
"v",
"in",
"self",
".",
"__dict__",
".",
"items",
"(",
")",
"if",
"v",
"}"
] | Return a dict of all instance variables with truthy values,
with key names camelized | [
"Return",
"a",
"dict",
"of",
"all",
"instance",
"variables",
"with",
"truthy",
"values",
"with",
"key",
"names",
"camelized"
] | ab15d1ca3c01a185136b420d443f712dfa865485 | https://github.com/sherlocke/pywatson/blob/ab15d1ca3c01a185136b420d443f712dfa865485/pywatson/util/dictable.py#L7-L16 |
41,627 | hyde/fswrap | fswrap.py | FS.depth | def depth(self):
"""
Returns the number of ancestors of this directory.
"""
return len(self.path.rstrip(os.sep).split(os.sep)) | python | def depth(self):
"""
Returns the number of ancestors of this directory.
"""
return len(self.path.rstrip(os.sep).split(os.sep)) | [
"def",
"depth",
"(",
"self",
")",
":",
"return",
"len",
"(",
"self",
".",
"path",
".",
"rstrip",
"(",
"os",
".",
"sep",
")",
".",
"split",
"(",
"os",
".",
"sep",
")",
")"
] | Returns the number of ancestors of this directory. | [
"Returns",
"the",
"number",
"of",
"ancestors",
"of",
"this",
"directory",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L101-L105 |
41,628 | hyde/fswrap | fswrap.py | FS.ancestors | def ancestors(self, stop=None):
"""
Generates the parents until stop or the absolute
root directory is reached.
"""
folder = self
while folder.parent != stop:
if folder.parent == folder:
return
yield folder.parent
folder... | python | def ancestors(self, stop=None):
"""
Generates the parents until stop or the absolute
root directory is reached.
"""
folder = self
while folder.parent != stop:
if folder.parent == folder:
return
yield folder.parent
folder... | [
"def",
"ancestors",
"(",
"self",
",",
"stop",
"=",
"None",
")",
":",
"folder",
"=",
"self",
"while",
"folder",
".",
"parent",
"!=",
"stop",
":",
"if",
"folder",
".",
"parent",
"==",
"folder",
":",
"return",
"yield",
"folder",
".",
"parent",
"folder",
... | Generates the parents until stop or the absolute
root directory is reached. | [
"Generates",
"the",
"parents",
"until",
"stop",
"or",
"the",
"absolute",
"root",
"directory",
"is",
"reached",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L107-L117 |
41,629 | hyde/fswrap | fswrap.py | FS.is_descendant_of | def is_descendant_of(self, ancestor):
"""
Checks if this folder is inside the given ancestor.
"""
stop = Folder(ancestor)
for folder in self.ancestors():
if folder == stop:
return True
if stop.depth > folder.depth:
return Fa... | python | def is_descendant_of(self, ancestor):
"""
Checks if this folder is inside the given ancestor.
"""
stop = Folder(ancestor)
for folder in self.ancestors():
if folder == stop:
return True
if stop.depth > folder.depth:
return Fa... | [
"def",
"is_descendant_of",
"(",
"self",
",",
"ancestor",
")",
":",
"stop",
"=",
"Folder",
"(",
"ancestor",
")",
"for",
"folder",
"in",
"self",
".",
"ancestors",
"(",
")",
":",
"if",
"folder",
"==",
"stop",
":",
"return",
"True",
"if",
"stop",
".",
"d... | Checks if this folder is inside the given ancestor. | [
"Checks",
"if",
"this",
"folder",
"is",
"inside",
"the",
"given",
"ancestor",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L119-L129 |
41,630 | hyde/fswrap | fswrap.py | FS.get_relative_path | def get_relative_path(self, root):
"""
Gets the fragment of the current path starting at root.
"""
if self.path == root:
return ''
ancestors = self.ancestors(stop=root)
return functools.reduce(lambda f, p: Folder(p.name).child(f),
... | python | def get_relative_path(self, root):
"""
Gets the fragment of the current path starting at root.
"""
if self.path == root:
return ''
ancestors = self.ancestors(stop=root)
return functools.reduce(lambda f, p: Folder(p.name).child(f),
... | [
"def",
"get_relative_path",
"(",
"self",
",",
"root",
")",
":",
"if",
"self",
".",
"path",
"==",
"root",
":",
"return",
"''",
"ancestors",
"=",
"self",
".",
"ancestors",
"(",
"stop",
"=",
"root",
")",
"return",
"functools",
".",
"reduce",
"(",
"lambda"... | Gets the fragment of the current path starting at root. | [
"Gets",
"the",
"fragment",
"of",
"the",
"current",
"path",
"starting",
"at",
"root",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L131-L140 |
41,631 | hyde/fswrap | fswrap.py | FS.get_mirror | def get_mirror(self, target_root, source_root=None):
"""
Returns a File or Folder object that reperesents if the entire
fragment of this directory starting with `source_root` were copied
to `target_root`.
>>> Folder('/usr/local/hyde/stuff').get_mirror('/usr/tmp',
... | python | def get_mirror(self, target_root, source_root=None):
"""
Returns a File or Folder object that reperesents if the entire
fragment of this directory starting with `source_root` were copied
to `target_root`.
>>> Folder('/usr/local/hyde/stuff').get_mirror('/usr/tmp',
... | [
"def",
"get_mirror",
"(",
"self",
",",
"target_root",
",",
"source_root",
"=",
"None",
")",
":",
"fragment",
"=",
"self",
".",
"get_relative_path",
"(",
"source_root",
"if",
"source_root",
"else",
"self",
".",
"parent",
")",
"return",
"Folder",
"(",
"target_... | Returns a File or Folder object that reperesents if the entire
fragment of this directory starting with `source_root` were copied
to `target_root`.
>>> Folder('/usr/local/hyde/stuff').get_mirror('/usr/tmp',
source_root='/usr/local/hyde')
F... | [
"Returns",
"a",
"File",
"or",
"Folder",
"object",
"that",
"reperesents",
"if",
"the",
"entire",
"fragment",
"of",
"this",
"directory",
"starting",
"with",
"source_root",
"were",
"copied",
"to",
"target_root",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L142-L154 |
41,632 | hyde/fswrap | fswrap.py | FS.file_or_folder | def file_or_folder(path):
"""
Returns a File or Folder object that would represent the given path.
"""
target = unicode(path)
return Folder(target) if os.path.isdir(target) else File(target) | python | def file_or_folder(path):
"""
Returns a File or Folder object that would represent the given path.
"""
target = unicode(path)
return Folder(target) if os.path.isdir(target) else File(target) | [
"def",
"file_or_folder",
"(",
"path",
")",
":",
"target",
"=",
"unicode",
"(",
"path",
")",
"return",
"Folder",
"(",
"target",
")",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"target",
")",
"else",
"File",
"(",
"target",
")"
] | Returns a File or Folder object that would represent the given path. | [
"Returns",
"a",
"File",
"or",
"Folder",
"object",
"that",
"would",
"represent",
"the",
"given",
"path",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L157-L162 |
41,633 | hyde/fswrap | fswrap.py | File.is_binary | def is_binary(self):
"""Return true if this is a binary file."""
with open(self.path, 'rb') as fin:
CHUNKSIZE = 1024
while 1:
chunk = fin.read(CHUNKSIZE)
if b'\0' in chunk:
return True
if len(chunk) < CHUNKSIZE:
... | python | def is_binary(self):
"""Return true if this is a binary file."""
with open(self.path, 'rb') as fin:
CHUNKSIZE = 1024
while 1:
chunk = fin.read(CHUNKSIZE)
if b'\0' in chunk:
return True
if len(chunk) < CHUNKSIZE:
... | [
"def",
"is_binary",
"(",
"self",
")",
":",
"with",
"open",
"(",
"self",
".",
"path",
",",
"'rb'",
")",
"as",
"fin",
":",
"CHUNKSIZE",
"=",
"1024",
"while",
"1",
":",
"chunk",
"=",
"fin",
".",
"read",
"(",
"CHUNKSIZE",
")",
"if",
"b'\\0'",
"in",
"... | Return true if this is a binary file. | [
"Return",
"true",
"if",
"this",
"is",
"a",
"binary",
"file",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L224-L234 |
41,634 | hyde/fswrap | fswrap.py | File.make_temp | def make_temp(text):
"""
Creates a temprorary file and writes the `text` into it
"""
import tempfile
(handle, path) = tempfile.mkstemp(text=True)
os.close(handle)
afile = File(path)
afile.write(text)
return afile | python | def make_temp(text):
"""
Creates a temprorary file and writes the `text` into it
"""
import tempfile
(handle, path) = tempfile.mkstemp(text=True)
os.close(handle)
afile = File(path)
afile.write(text)
return afile | [
"def",
"make_temp",
"(",
"text",
")",
":",
"import",
"tempfile",
"(",
"handle",
",",
"path",
")",
"=",
"tempfile",
".",
"mkstemp",
"(",
"text",
"=",
"True",
")",
"os",
".",
"close",
"(",
"handle",
")",
"afile",
"=",
"File",
"(",
"path",
")",
"afile... | Creates a temprorary file and writes the `text` into it | [
"Creates",
"a",
"temprorary",
"file",
"and",
"writes",
"the",
"text",
"into",
"it"
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L271-L280 |
41,635 | hyde/fswrap | fswrap.py | File.read_all | def read_all(self, encoding='utf-8'):
"""
Reads from the file and returns the content as a string.
"""
logger.info("Reading everything from %s" % self)
with codecs.open(self.path, 'r', encoding) as fin:
read_text = fin.read()
return read_text | python | def read_all(self, encoding='utf-8'):
"""
Reads from the file and returns the content as a string.
"""
logger.info("Reading everything from %s" % self)
with codecs.open(self.path, 'r', encoding) as fin:
read_text = fin.read()
return read_text | [
"def",
"read_all",
"(",
"self",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"logger",
".",
"info",
"(",
"\"Reading everything from %s\"",
"%",
"self",
")",
"with",
"codecs",
".",
"open",
"(",
"self",
".",
"path",
",",
"'r'",
",",
"encoding",
")",
"as",
... | Reads from the file and returns the content as a string. | [
"Reads",
"from",
"the",
"file",
"and",
"returns",
"the",
"content",
"as",
"a",
"string",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L282-L289 |
41,636 | hyde/fswrap | fswrap.py | File.write | def write(self, text, encoding="utf-8"):
"""
Writes the given text to the file using the given encoding.
"""
logger.info("Writing to %s" % self)
with codecs.open(self.path, 'w', encoding) as fout:
fout.write(text) | python | def write(self, text, encoding="utf-8"):
"""
Writes the given text to the file using the given encoding.
"""
logger.info("Writing to %s" % self)
with codecs.open(self.path, 'w', encoding) as fout:
fout.write(text) | [
"def",
"write",
"(",
"self",
",",
"text",
",",
"encoding",
"=",
"\"utf-8\"",
")",
":",
"logger",
".",
"info",
"(",
"\"Writing to %s\"",
"%",
"self",
")",
"with",
"codecs",
".",
"open",
"(",
"self",
".",
"path",
",",
"'w'",
",",
"encoding",
")",
"as",... | Writes the given text to the file using the given encoding. | [
"Writes",
"the",
"given",
"text",
"to",
"the",
"file",
"using",
"the",
"given",
"encoding",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L291-L297 |
41,637 | hyde/fswrap | fswrap.py | File.copy_to | def copy_to(self, destination):
"""
Copies the file to the given destination. Returns a File
object that represents the target file. `destination` must
be a File or Folder object.
"""
target = self.__get_destination__(destination)
logger.info("Copying %s to %s" % ... | python | def copy_to(self, destination):
"""
Copies the file to the given destination. Returns a File
object that represents the target file. `destination` must
be a File or Folder object.
"""
target = self.__get_destination__(destination)
logger.info("Copying %s to %s" % ... | [
"def",
"copy_to",
"(",
"self",
",",
"destination",
")",
":",
"target",
"=",
"self",
".",
"__get_destination__",
"(",
"destination",
")",
"logger",
".",
"info",
"(",
"\"Copying %s to %s\"",
"%",
"(",
"self",
",",
"target",
")",
")",
"shutil",
".",
"copy",
... | Copies the file to the given destination. Returns a File
object that represents the target file. `destination` must
be a File or Folder object. | [
"Copies",
"the",
"file",
"to",
"the",
"given",
"destination",
".",
"Returns",
"a",
"File",
"object",
"that",
"represents",
"the",
"target",
"file",
".",
"destination",
"must",
"be",
"a",
"File",
"or",
"Folder",
"object",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L299-L308 |
41,638 | hyde/fswrap | fswrap.py | File.etag | def etag(self):
"""
Generates etag from file contents.
"""
CHUNKSIZE = 1024 * 64
from hashlib import md5
hash = md5()
with open(self.path) as fin:
chunk = fin.read(CHUNKSIZE)
while chunk:
hash_update(hash, chunk)
... | python | def etag(self):
"""
Generates etag from file contents.
"""
CHUNKSIZE = 1024 * 64
from hashlib import md5
hash = md5()
with open(self.path) as fin:
chunk = fin.read(CHUNKSIZE)
while chunk:
hash_update(hash, chunk)
... | [
"def",
"etag",
"(",
"self",
")",
":",
"CHUNKSIZE",
"=",
"1024",
"*",
"64",
"from",
"hashlib",
"import",
"md5",
"hash",
"=",
"md5",
"(",
")",
"with",
"open",
"(",
"self",
".",
"path",
")",
"as",
"fin",
":",
"chunk",
"=",
"fin",
".",
"read",
"(",
... | Generates etag from file contents. | [
"Generates",
"etag",
"from",
"file",
"contents",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L318-L330 |
41,639 | hyde/fswrap | fswrap.py | Folder.child_folder | def child_folder(self, fragment):
"""
Returns a folder object by combining the fragment to this folder's path
"""
return Folder(os.path.join(self.path, Folder(fragment).path)) | python | def child_folder(self, fragment):
"""
Returns a folder object by combining the fragment to this folder's path
"""
return Folder(os.path.join(self.path, Folder(fragment).path)) | [
"def",
"child_folder",
"(",
"self",
",",
"fragment",
")",
":",
"return",
"Folder",
"(",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"path",
",",
"Folder",
"(",
"fragment",
")",
".",
"path",
")",
")"
] | Returns a folder object by combining the fragment to this folder's path | [
"Returns",
"a",
"folder",
"object",
"by",
"combining",
"the",
"fragment",
"to",
"this",
"folder",
"s",
"path"
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L531-L535 |
41,640 | hyde/fswrap | fswrap.py | Folder.child | def child(self, fragment):
"""
Returns a path of a child item represented by `fragment`.
"""
return os.path.join(self.path, FS(fragment).path) | python | def child(self, fragment):
"""
Returns a path of a child item represented by `fragment`.
"""
return os.path.join(self.path, FS(fragment).path) | [
"def",
"child",
"(",
"self",
",",
"fragment",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"path",
",",
"FS",
"(",
"fragment",
")",
".",
"path",
")"
] | Returns a path of a child item represented by `fragment`. | [
"Returns",
"a",
"path",
"of",
"a",
"child",
"item",
"represented",
"by",
"fragment",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L543-L547 |
41,641 | hyde/fswrap | fswrap.py | Folder.make | def make(self):
"""
Creates this directory and any of the missing directories in the path.
Any errors that may occur are eaten.
"""
try:
if not self.exists:
logger.info("Creating %s" % self.path)
os.makedirs(self.path)
except os... | python | def make(self):
"""
Creates this directory and any of the missing directories in the path.
Any errors that may occur are eaten.
"""
try:
if not self.exists:
logger.info("Creating %s" % self.path)
os.makedirs(self.path)
except os... | [
"def",
"make",
"(",
"self",
")",
":",
"try",
":",
"if",
"not",
"self",
".",
"exists",
":",
"logger",
".",
"info",
"(",
"\"Creating %s\"",
"%",
"self",
".",
"path",
")",
"os",
".",
"makedirs",
"(",
"self",
".",
"path",
")",
"except",
"os",
".",
"e... | Creates this directory and any of the missing directories in the path.
Any errors that may occur are eaten. | [
"Creates",
"this",
"directory",
"and",
"any",
"of",
"the",
"missing",
"directories",
"in",
"the",
"path",
".",
"Any",
"errors",
"that",
"may",
"occur",
"are",
"eaten",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L549-L560 |
41,642 | hyde/fswrap | fswrap.py | Folder.delete | def delete(self):
"""
Deletes the directory if it exists.
"""
if self.exists:
logger.info("Deleting %s" % self.path)
shutil.rmtree(self.path) | python | def delete(self):
"""
Deletes the directory if it exists.
"""
if self.exists:
logger.info("Deleting %s" % self.path)
shutil.rmtree(self.path) | [
"def",
"delete",
"(",
"self",
")",
":",
"if",
"self",
".",
"exists",
":",
"logger",
".",
"info",
"(",
"\"Deleting %s\"",
"%",
"self",
".",
"path",
")",
"shutil",
".",
"rmtree",
"(",
"self",
".",
"path",
")"
] | Deletes the directory if it exists. | [
"Deletes",
"the",
"directory",
"if",
"it",
"exists",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L578-L584 |
41,643 | hyde/fswrap | fswrap.py | Folder._create_target_tree | def _create_target_tree(self, target):
"""
There is a bug in dir_util that makes `copy_tree` crash if a folder in
the tree has been deleted before and readded now. To workaround the
bug, we first walk the tree and create directories that are needed.
"""
source = self
... | python | def _create_target_tree(self, target):
"""
There is a bug in dir_util that makes `copy_tree` crash if a folder in
the tree has been deleted before and readded now. To workaround the
bug, we first walk the tree and create directories that are needed.
"""
source = self
... | [
"def",
"_create_target_tree",
"(",
"self",
",",
"target",
")",
":",
"source",
"=",
"self",
"with",
"source",
".",
"walker",
"as",
"walker",
":",
"@",
"walker",
".",
"folder_visitor",
"def",
"visit_folder",
"(",
"folder",
")",
":",
"\"\"\"\n Crea... | There is a bug in dir_util that makes `copy_tree` crash if a folder in
the tree has been deleted before and readded now. To workaround the
bug, we first walk the tree and create directories that are needed. | [
"There",
"is",
"a",
"bug",
"in",
"dir_util",
"that",
"makes",
"copy_tree",
"crash",
"if",
"a",
"folder",
"in",
"the",
"tree",
"has",
"been",
"deleted",
"before",
"and",
"readded",
"now",
".",
"To",
"workaround",
"the",
"bug",
"we",
"first",
"walk",
"the"... | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L616-L631 |
41,644 | hyde/fswrap | fswrap.py | Folder.copy_contents_to | def copy_contents_to(self, destination):
"""
Copies the contents of this directory to the given destination.
Returns a Folder object that represents the moved directory.
"""
logger.info("Copying contents of %s to %s" % (self, destination))
target = Folder(destination)
... | python | def copy_contents_to(self, destination):
"""
Copies the contents of this directory to the given destination.
Returns a Folder object that represents the moved directory.
"""
logger.info("Copying contents of %s to %s" % (self, destination))
target = Folder(destination)
... | [
"def",
"copy_contents_to",
"(",
"self",
",",
"destination",
")",
":",
"logger",
".",
"info",
"(",
"\"Copying contents of %s to %s\"",
"%",
"(",
"self",
",",
"destination",
")",
")",
"target",
"=",
"Folder",
"(",
"destination",
")",
"target",
".",
"make",
"("... | Copies the contents of this directory to the given destination.
Returns a Folder object that represents the moved directory. | [
"Copies",
"the",
"contents",
"of",
"this",
"directory",
"to",
"the",
"given",
"destination",
".",
"Returns",
"a",
"Folder",
"object",
"that",
"represents",
"the",
"moved",
"directory",
"."
] | 41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2 | https://github.com/hyde/fswrap/blob/41e4ad6f7e9ba73eabe61bd97847cd284e3edbd2/fswrap.py#L633-L643 |
41,645 | AtomHash/evernode | evernode/classes/cron.py | Cron.__start | def __start(self):
""" Start a new thread to process Cron """
thread = Thread(target=self.__loop, args=())
thread.daemon = True # daemonize thread
thread.start()
self.__enabled = True | python | def __start(self):
""" Start a new thread to process Cron """
thread = Thread(target=self.__loop, args=())
thread.daemon = True # daemonize thread
thread.start()
self.__enabled = True | [
"def",
"__start",
"(",
"self",
")",
":",
"thread",
"=",
"Thread",
"(",
"target",
"=",
"self",
".",
"__loop",
",",
"args",
"=",
"(",
")",
")",
"thread",
".",
"daemon",
"=",
"True",
"# daemonize thread",
"thread",
".",
"start",
"(",
")",
"self",
".",
... | Start a new thread to process Cron | [
"Start",
"a",
"new",
"thread",
"to",
"process",
"Cron"
] | b2fb91555fb937a3f3eba41db56dee26f9b034be | https://github.com/AtomHash/evernode/blob/b2fb91555fb937a3f3eba41db56dee26f9b034be/evernode/classes/cron.py#L39-L44 |
41,646 | thomasw/querylist | querylist/dict.py | BetterDict.__dict_to_BetterDict | def __dict_to_BetterDict(self, attr):
"""Convert the passed attr to a BetterDict if the value is a dict
Returns: The new value of the passed attribute."""
if type(self[attr]) == dict:
self[attr] = BetterDict(self[attr])
return self[attr] | python | def __dict_to_BetterDict(self, attr):
"""Convert the passed attr to a BetterDict if the value is a dict
Returns: The new value of the passed attribute."""
if type(self[attr]) == dict:
self[attr] = BetterDict(self[attr])
return self[attr] | [
"def",
"__dict_to_BetterDict",
"(",
"self",
",",
"attr",
")",
":",
"if",
"type",
"(",
"self",
"[",
"attr",
"]",
")",
"==",
"dict",
":",
"self",
"[",
"attr",
"]",
"=",
"BetterDict",
"(",
"self",
"[",
"attr",
"]",
")",
"return",
"self",
"[",
"attr",
... | Convert the passed attr to a BetterDict if the value is a dict
Returns: The new value of the passed attribute. | [
"Convert",
"the",
"passed",
"attr",
"to",
"a",
"BetterDict",
"if",
"the",
"value",
"is",
"a",
"dict"
] | 4304023ef3330238ef3abccaa530ee97011fba2d | https://github.com/thomasw/querylist/blob/4304023ef3330238ef3abccaa530ee97011fba2d/querylist/dict.py#L8-L15 |
41,647 | thomasw/querylist | querylist/dict.py | BetterDict._bd_ | def _bd_(self):
"""Property that allows dot lookups of otherwise hidden attributes."""
if not getattr(self, '__bd__', False):
self.__bd = BetterDictLookUp(self)
return self.__bd | python | def _bd_(self):
"""Property that allows dot lookups of otherwise hidden attributes."""
if not getattr(self, '__bd__', False):
self.__bd = BetterDictLookUp(self)
return self.__bd | [
"def",
"_bd_",
"(",
"self",
")",
":",
"if",
"not",
"getattr",
"(",
"self",
",",
"'__bd__'",
",",
"False",
")",
":",
"self",
".",
"__bd",
"=",
"BetterDictLookUp",
"(",
"self",
")",
"return",
"self",
".",
"__bd"
] | Property that allows dot lookups of otherwise hidden attributes. | [
"Property",
"that",
"allows",
"dot",
"lookups",
"of",
"otherwise",
"hidden",
"attributes",
"."
] | 4304023ef3330238ef3abccaa530ee97011fba2d | https://github.com/thomasw/querylist/blob/4304023ef3330238ef3abccaa530ee97011fba2d/querylist/dict.py#L27-L32 |
41,648 | tBaxter/activity-monitor | activity_monitor/signals.py | create_or_update | def create_or_update(sender, **kwargs):
"""
Create or update an Activity Monitor item from some instance.
"""
now = datetime.datetime.now()
# I can't explain why this import fails unless it's here.
from activity_monitor.models import Activity
instance = kwargs['instance']
# Find this o... | python | def create_or_update(sender, **kwargs):
"""
Create or update an Activity Monitor item from some instance.
"""
now = datetime.datetime.now()
# I can't explain why this import fails unless it's here.
from activity_monitor.models import Activity
instance = kwargs['instance']
# Find this o... | [
"def",
"create_or_update",
"(",
"sender",
",",
"*",
"*",
"kwargs",
")",
":",
"now",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"# I can't explain why this import fails unless it's here.",
"from",
"activity_monitor",
".",
"models",
"import",
"Activity",
... | Create or update an Activity Monitor item from some instance. | [
"Create",
"or",
"update",
"an",
"Activity",
"Monitor",
"item",
"from",
"some",
"instance",
"."
] | be6c6edc7c6b4141923b47376502cde0f785eb68 | https://github.com/tBaxter/activity-monitor/blob/be6c6edc7c6b4141923b47376502cde0f785eb68/activity_monitor/signals.py#L7-L119 |
41,649 | MisanthropicBit/colorise | examples/highlight_differences.py | highlight_differences | def highlight_differences(s1, s2, color):
"""Highlight the characters in s2 that differ from those in s1."""
ls1, ls2 = len(s1), len(s2)
diff_indices = [i for i, (a, b) in enumerate(zip(s1, s2)) if a != b]
print(s1)
if ls2 > ls1:
colorise.cprint('_' * (ls2-ls1), fg=color)
else:
... | python | def highlight_differences(s1, s2, color):
"""Highlight the characters in s2 that differ from those in s1."""
ls1, ls2 = len(s1), len(s2)
diff_indices = [i for i, (a, b) in enumerate(zip(s1, s2)) if a != b]
print(s1)
if ls2 > ls1:
colorise.cprint('_' * (ls2-ls1), fg=color)
else:
... | [
"def",
"highlight_differences",
"(",
"s1",
",",
"s2",
",",
"color",
")",
":",
"ls1",
",",
"ls2",
"=",
"len",
"(",
"s1",
")",
",",
"len",
"(",
"s2",
")",
"diff_indices",
"=",
"[",
"i",
"for",
"i",
",",
"(",
"a",
",",
"b",
")",
"in",
"enumerate",... | Highlight the characters in s2 that differ from those in s1. | [
"Highlight",
"the",
"characters",
"in",
"s2",
"that",
"differ",
"from",
"those",
"in",
"s1",
"."
] | e630df74b8b27680a43c370ddbe98766be50158c | https://github.com/MisanthropicBit/colorise/blob/e630df74b8b27680a43c370ddbe98766be50158c/examples/highlight_differences.py#L13-L31 |
41,650 | lsst-sqre/lander | lander/renderer.py | create_jinja_env | def create_jinja_env():
"""Create a Jinja2 `~jinja2.Environment`.
Returns
-------
env : `jinja2.Environment`
Jinja2 template rendering environment, configured to use templates in
``templates/``.
"""
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
env = ji... | python | def create_jinja_env():
"""Create a Jinja2 `~jinja2.Environment`.
Returns
-------
env : `jinja2.Environment`
Jinja2 template rendering environment, configured to use templates in
``templates/``.
"""
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
env = ji... | [
"def",
"create_jinja_env",
"(",
")",
":",
"template_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
",",
"'templates'",
")",
"env",
"=",
"jinja2",
".",
"Environment",
"(",
"loader",
"=",
"jinja2"... | Create a Jinja2 `~jinja2.Environment`.
Returns
-------
env : `jinja2.Environment`
Jinja2 template rendering environment, configured to use templates in
``templates/``. | [
"Create",
"a",
"Jinja2",
"~jinja2",
".",
"Environment",
"."
] | 5e4f6123e48b451ba21963724ace0dc59798618e | https://github.com/lsst-sqre/lander/blob/5e4f6123e48b451ba21963724ace0dc59798618e/lander/renderer.py#L9-L25 |
41,651 | lsst-sqre/lander | lander/renderer.py | render_homepage | def render_homepage(config, env):
"""Render the homepage.jinja template."""
template = env.get_template('homepage.jinja')
rendered_page = template.render(
config=config)
return rendered_page | python | def render_homepage(config, env):
"""Render the homepage.jinja template."""
template = env.get_template('homepage.jinja')
rendered_page = template.render(
config=config)
return rendered_page | [
"def",
"render_homepage",
"(",
"config",
",",
"env",
")",
":",
"template",
"=",
"env",
".",
"get_template",
"(",
"'homepage.jinja'",
")",
"rendered_page",
"=",
"template",
".",
"render",
"(",
"config",
"=",
"config",
")",
"return",
"rendered_page"
] | Render the homepage.jinja template. | [
"Render",
"the",
"homepage",
".",
"jinja",
"template",
"."
] | 5e4f6123e48b451ba21963724ace0dc59798618e | https://github.com/lsst-sqre/lander/blob/5e4f6123e48b451ba21963724ace0dc59798618e/lander/renderer.py#L28-L33 |
41,652 | brews/snakebacon | snakebacon/mcmcbackends/bacon/utils.py | d_cal | def d_cal(calibcurve, rcmean, w2, cutoff=0.0001, normal_distr=False, t_a=3, t_b=4):
"""Get calendar date probabilities
Parameters
----------
calibcurve : CalibCurve
Calibration curve.
rcmean : scalar
Reservoir-adjusted age.
w2 : scalar
r'$w^2_j(\theta)$' from pg 461 & 46... | python | def d_cal(calibcurve, rcmean, w2, cutoff=0.0001, normal_distr=False, t_a=3, t_b=4):
"""Get calendar date probabilities
Parameters
----------
calibcurve : CalibCurve
Calibration curve.
rcmean : scalar
Reservoir-adjusted age.
w2 : scalar
r'$w^2_j(\theta)$' from pg 461 & 46... | [
"def",
"d_cal",
"(",
"calibcurve",
",",
"rcmean",
",",
"w2",
",",
"cutoff",
"=",
"0.0001",
",",
"normal_distr",
"=",
"False",
",",
"t_a",
"=",
"3",
",",
"t_b",
"=",
"4",
")",
":",
"assert",
"t_b",
"-",
"1",
"==",
"t_a",
"if",
"normal_distr",
":",
... | Get calendar date probabilities
Parameters
----------
calibcurve : CalibCurve
Calibration curve.
rcmean : scalar
Reservoir-adjusted age.
w2 : scalar
r'$w^2_j(\theta)$' from pg 461 & 463 of Blaauw and Christen 2011.
cutoff : scalar, optional
Unknown.
normal_di... | [
"Get",
"calendar",
"date",
"probabilities"
] | f5363d0d1225912adc30031bf2c13b54000de8f2 | https://github.com/brews/snakebacon/blob/f5363d0d1225912adc30031bf2c13b54000de8f2/snakebacon/mcmcbackends/bacon/utils.py#L5-L49 |
41,653 | brews/snakebacon | snakebacon/mcmcbackends/bacon/utils.py | calibrate_dates | def calibrate_dates(chron, calib_curve, d_r, d_std, cutoff=0.0001, normal_distr=False, t_a=[3], t_b=[4]):
"""Get density of calendar dates for chron date segment in core
Parameters
----------
chron : DatedProxy-like
calib_curve : CalibCurve or list of CalibCurves
d_r : scalar or ndarray
... | python | def calibrate_dates(chron, calib_curve, d_r, d_std, cutoff=0.0001, normal_distr=False, t_a=[3], t_b=[4]):
"""Get density of calendar dates for chron date segment in core
Parameters
----------
chron : DatedProxy-like
calib_curve : CalibCurve or list of CalibCurves
d_r : scalar or ndarray
... | [
"def",
"calibrate_dates",
"(",
"chron",
",",
"calib_curve",
",",
"d_r",
",",
"d_std",
",",
"cutoff",
"=",
"0.0001",
",",
"normal_distr",
"=",
"False",
",",
"t_a",
"=",
"[",
"3",
"]",
",",
"t_b",
"=",
"[",
"4",
"]",
")",
":",
"# Python version of .bacon... | Get density of calendar dates for chron date segment in core
Parameters
----------
chron : DatedProxy-like
calib_curve : CalibCurve or list of CalibCurves
d_r : scalar or ndarray
Carbon reservoir offset.
d_std : scalar or ndarray
Carbon reservoir offset error standard deviation.... | [
"Get",
"density",
"of",
"calendar",
"dates",
"for",
"chron",
"date",
"segment",
"in",
"core"
] | f5363d0d1225912adc30031bf2c13b54000de8f2 | https://github.com/brews/snakebacon/blob/f5363d0d1225912adc30031bf2c13b54000de8f2/snakebacon/mcmcbackends/bacon/utils.py#L52-L123 |
41,654 | inveniosoftware-attic/invenio-client | invenio_client/connector.py | InvenioConnector._init_browser | def _init_browser(self):
"""Overide in appropriate way to prepare a logged in browser."""
self.browser = splinter.Browser('phantomjs')
self.browser.visit(self.server_url + "/youraccount/login")
try:
self.browser.fill('nickname', self.user)
self.browser.fill('passw... | python | def _init_browser(self):
"""Overide in appropriate way to prepare a logged in browser."""
self.browser = splinter.Browser('phantomjs')
self.browser.visit(self.server_url + "/youraccount/login")
try:
self.browser.fill('nickname', self.user)
self.browser.fill('passw... | [
"def",
"_init_browser",
"(",
"self",
")",
":",
"self",
".",
"browser",
"=",
"splinter",
".",
"Browser",
"(",
"'phantomjs'",
")",
"self",
".",
"browser",
".",
"visit",
"(",
"self",
".",
"server_url",
"+",
"\"/youraccount/login\"",
")",
"try",
":",
"self",
... | Overide in appropriate way to prepare a logged in browser. | [
"Overide",
"in",
"appropriate",
"way",
"to",
"prepare",
"a",
"logged",
"in",
"browser",
"."
] | 3f9ddb6f3b3ce3a21d399d1098d6769bf05cdd6c | https://github.com/inveniosoftware-attic/invenio-client/blob/3f9ddb6f3b3ce3a21d399d1098d6769bf05cdd6c/invenio_client/connector.py#L141-L152 |
41,655 | inveniosoftware-attic/invenio-client | invenio_client/connector.py | InvenioConnector.upload_marcxml | def upload_marcxml(self, marcxml, mode):
"""Upload a record to the server.
:param marcxml: the XML to upload.
:param mode: the mode to use for the upload.
- "-i" insert new records
- "-r" replace existing records
- "-c" correct fields of records
-... | python | def upload_marcxml(self, marcxml, mode):
"""Upload a record to the server.
:param marcxml: the XML to upload.
:param mode: the mode to use for the upload.
- "-i" insert new records
- "-r" replace existing records
- "-c" correct fields of records
-... | [
"def",
"upload_marcxml",
"(",
"self",
",",
"marcxml",
",",
"mode",
")",
":",
"if",
"mode",
"not",
"in",
"[",
"\"-i\"",
",",
"\"-r\"",
",",
"\"-c\"",
",",
"\"-a\"",
",",
"\"-ir\"",
"]",
":",
"raise",
"NameError",
"(",
"\"Incorrect mode \"",
"+",
"str",
... | Upload a record to the server.
:param marcxml: the XML to upload.
:param mode: the mode to use for the upload.
- "-i" insert new records
- "-r" replace existing records
- "-c" correct fields of records
- "-a" append fields to records
- "-ir" i... | [
"Upload",
"a",
"record",
"to",
"the",
"server",
"."
] | 3f9ddb6f3b3ce3a21d399d1098d6769bf05cdd6c | https://github.com/inveniosoftware-attic/invenio-client/blob/3f9ddb6f3b3ce3a21d399d1098d6769bf05cdd6c/invenio_client/connector.py#L298-L314 |
41,656 | inveniosoftware-attic/invenio-client | invenio_client/connector.py | Record.url | def url(self):
"""
Returns the URL to this record.
Returns None if not known
"""
if self.server_url is not None and \
self.recid is not None:
return '/'.join(
[self.server_url, CFG_SITE_RECORD, str(self.recid)])
else:
... | python | def url(self):
"""
Returns the URL to this record.
Returns None if not known
"""
if self.server_url is not None and \
self.recid is not None:
return '/'.join(
[self.server_url, CFG_SITE_RECORD, str(self.recid)])
else:
... | [
"def",
"url",
"(",
"self",
")",
":",
"if",
"self",
".",
"server_url",
"is",
"not",
"None",
"and",
"self",
".",
"recid",
"is",
"not",
"None",
":",
"return",
"'/'",
".",
"join",
"(",
"[",
"self",
".",
"server_url",
",",
"CFG_SITE_RECORD",
",",
"str",
... | Returns the URL to this record.
Returns None if not known | [
"Returns",
"the",
"URL",
"to",
"this",
"record",
".",
"Returns",
"None",
"if",
"not",
"known"
] | 3f9ddb6f3b3ce3a21d399d1098d6769bf05cdd6c | https://github.com/inveniosoftware-attic/invenio-client/blob/3f9ddb6f3b3ce3a21d399d1098d6769bf05cdd6c/invenio_client/connector.py#L399-L409 |
41,657 | MKLab-ITI/reveal-user-annotation | reveal_user_annotation/twitter/clean_twitter_list.py | clean_list_of_twitter_list | def clean_list_of_twitter_list(list_of_twitter_lists,
sent_tokenize, _treebank_word_tokenize,
tagger, lemmatizer, lemmatize, stopset,
first_cap_re, all_cap_re, digits_punctuation_whitespace_re,
po... | python | def clean_list_of_twitter_list(list_of_twitter_lists,
sent_tokenize, _treebank_word_tokenize,
tagger, lemmatizer, lemmatize, stopset,
first_cap_re, all_cap_re, digits_punctuation_whitespace_re,
po... | [
"def",
"clean_list_of_twitter_list",
"(",
"list_of_twitter_lists",
",",
"sent_tokenize",
",",
"_treebank_word_tokenize",
",",
"tagger",
",",
"lemmatizer",
",",
"lemmatize",
",",
"stopset",
",",
"first_cap_re",
",",
"all_cap_re",
",",
"digits_punctuation_whitespace_re",
",... | Extracts the sets of keywords for each Twitter list.
Inputs: - list_of_twitter_lists: A python list of Twitter lists in json format.
- lemmatizing: A string containing one of the following: "porter", "snowball" or "wordnet".
Output: - list_of_keyword_sets: A list of sets of keywords (i.e. not a ba... | [
"Extracts",
"the",
"sets",
"of",
"keywords",
"for",
"each",
"Twitter",
"list",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/twitter/clean_twitter_list.py#L48-L79 |
41,658 | MKLab-ITI/reveal-user-annotation | reveal_user_annotation/twitter/clean_twitter_list.py | user_twitter_list_bag_of_words | def user_twitter_list_bag_of_words(twitter_list_corpus,
sent_tokenize, _treebank_word_tokenize,
tagger, lemmatizer, lemmatize, stopset,
first_cap_re, all_cap_re, digits_punctuation_whitespace_re,
... | python | def user_twitter_list_bag_of_words(twitter_list_corpus,
sent_tokenize, _treebank_word_tokenize,
tagger, lemmatizer, lemmatize, stopset,
first_cap_re, all_cap_re, digits_punctuation_whitespace_re,
... | [
"def",
"user_twitter_list_bag_of_words",
"(",
"twitter_list_corpus",
",",
"sent_tokenize",
",",
"_treebank_word_tokenize",
",",
"tagger",
",",
"lemmatizer",
",",
"lemmatize",
",",
"stopset",
",",
"first_cap_re",
",",
"all_cap_re",
",",
"digits_punctuation_whitespace_re",
... | Extract a bag-of-words for a corpus of Twitter lists pertaining to a Twitter user.
Inputs: - twitter_list_corpus: A python list of Twitter lists in json format.
- lemmatizing: A string containing one of the following: "porter", "snowball" or "wordnet".
Output: - bag_of_words: A bag-of-words in pyt... | [
"Extract",
"a",
"bag",
"-",
"of",
"-",
"words",
"for",
"a",
"corpus",
"of",
"Twitter",
"lists",
"pertaining",
"to",
"a",
"Twitter",
"user",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/twitter/clean_twitter_list.py#L82-L114 |
41,659 | MKLab-ITI/reveal-user-annotation | reveal_user_annotation/text/map_data.py | grouper | def grouper(iterable, n, pad_value=None):
"""
Returns a generator of n-length chunks of an input iterable, with appropriate padding at the end.
Example: grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')
Inputs: - iterable: The source iterable that needs to be chunkified.
... | python | def grouper(iterable, n, pad_value=None):
"""
Returns a generator of n-length chunks of an input iterable, with appropriate padding at the end.
Example: grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')
Inputs: - iterable: The source iterable that needs to be chunkified.
... | [
"def",
"grouper",
"(",
"iterable",
",",
"n",
",",
"pad_value",
"=",
"None",
")",
":",
"chunk_gen",
"=",
"(",
"chunk",
"for",
"chunk",
"in",
"zip_longest",
"(",
"*",
"[",
"iter",
"(",
"iterable",
")",
"]",
"*",
"n",
",",
"fillvalue",
"=",
"pad_value",... | Returns a generator of n-length chunks of an input iterable, with appropriate padding at the end.
Example: grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')
Inputs: - iterable: The source iterable that needs to be chunkified.
- n: The size of the chunks.
- pad_... | [
"Returns",
"a",
"generator",
"of",
"n",
"-",
"length",
"chunks",
"of",
"an",
"input",
"iterable",
"with",
"appropriate",
"padding",
"at",
"the",
"end",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/text/map_data.py#L9-L22 |
41,660 | MKLab-ITI/reveal-user-annotation | reveal_user_annotation/text/map_data.py | chunks | def chunks(iterable, n):
"""
A python generator that yields 100-length sub-list chunks.
Input: - full_list: The input list that is to be separated in chunks of 100.
- chunk_size: Should be set to 100, unless the Twitter API changes.
Yields: - sub_list: List chunks of length 100.
"""
... | python | def chunks(iterable, n):
"""
A python generator that yields 100-length sub-list chunks.
Input: - full_list: The input list that is to be separated in chunks of 100.
- chunk_size: Should be set to 100, unless the Twitter API changes.
Yields: - sub_list: List chunks of length 100.
"""
... | [
"def",
"chunks",
"(",
"iterable",
",",
"n",
")",
":",
"for",
"i",
"in",
"np",
".",
"arange",
"(",
"0",
",",
"len",
"(",
"iterable",
")",
",",
"n",
")",
":",
"yield",
"iterable",
"[",
"i",
":",
"i",
"+",
"n",
"]"
] | A python generator that yields 100-length sub-list chunks.
Input: - full_list: The input list that is to be separated in chunks of 100.
- chunk_size: Should be set to 100, unless the Twitter API changes.
Yields: - sub_list: List chunks of length 100. | [
"A",
"python",
"generator",
"that",
"yields",
"100",
"-",
"length",
"sub",
"-",
"list",
"chunks",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/text/map_data.py#L25-L35 |
41,661 | MKLab-ITI/reveal-user-annotation | reveal_user_annotation/text/map_data.py | split_every | def split_every(iterable, n): # TODO: Remove this, or make it return a generator.
"""
A generator of n-length chunks of an input iterable
"""
i = iter(iterable)
piece = list(islice(i, n))
while piece:
yield piece
piece = list(islice(i, n)) | python | def split_every(iterable, n): # TODO: Remove this, or make it return a generator.
"""
A generator of n-length chunks of an input iterable
"""
i = iter(iterable)
piece = list(islice(i, n))
while piece:
yield piece
piece = list(islice(i, n)) | [
"def",
"split_every",
"(",
"iterable",
",",
"n",
")",
":",
"# TODO: Remove this, or make it return a generator.",
"i",
"=",
"iter",
"(",
"iterable",
")",
"piece",
"=",
"list",
"(",
"islice",
"(",
"i",
",",
"n",
")",
")",
"while",
"piece",
":",
"yield",
"pi... | A generator of n-length chunks of an input iterable | [
"A",
"generator",
"of",
"n",
"-",
"length",
"chunks",
"of",
"an",
"input",
"iterable"
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/text/map_data.py#L38-L46 |
41,662 | NORDUnet/python-norduniclient | norduniclient/helpers.py | merge_properties | def merge_properties(item_properties, prop_name, merge_value):
"""
Tries to figure out which type of property value that should be merged and
invoke the right function.
Returns new properties if the merge was successful otherwise False.
"""
existing_value = item_properties.get(prop_name, None)
... | python | def merge_properties(item_properties, prop_name, merge_value):
"""
Tries to figure out which type of property value that should be merged and
invoke the right function.
Returns new properties if the merge was successful otherwise False.
"""
existing_value = item_properties.get(prop_name, None)
... | [
"def",
"merge_properties",
"(",
"item_properties",
",",
"prop_name",
",",
"merge_value",
")",
":",
"existing_value",
"=",
"item_properties",
".",
"get",
"(",
"prop_name",
",",
"None",
")",
"if",
"not",
"existing_value",
":",
"# A node without existing values for the p... | Tries to figure out which type of property value that should be merged and
invoke the right function.
Returns new properties if the merge was successful otherwise False. | [
"Tries",
"to",
"figure",
"out",
"which",
"type",
"of",
"property",
"value",
"that",
"should",
"be",
"merged",
"and",
"invoke",
"the",
"right",
"function",
".",
"Returns",
"new",
"properties",
"if",
"the",
"merge",
"was",
"successful",
"otherwise",
"False",
"... | ee5084a6f45caac614b4fda4a023749ca52f786c | https://github.com/NORDUnet/python-norduniclient/blob/ee5084a6f45caac614b4fda4a023749ca52f786c/norduniclient/helpers.py#L34-L50 |
41,663 | hatemile/hatemile-for-python | hatemile/util/idgenerator.py | IDGenerator.generate_id | def generate_id(self, element):
"""
Generate a id for a element.
:param element: The element.
:type element: hatemile.util.html.HTMLDOMElement
"""
if not element.has_attribute('id'):
element.set_attribute('id', self.prefix_id + str(self.count))
s... | python | def generate_id(self, element):
"""
Generate a id for a element.
:param element: The element.
:type element: hatemile.util.html.HTMLDOMElement
"""
if not element.has_attribute('id'):
element.set_attribute('id', self.prefix_id + str(self.count))
s... | [
"def",
"generate_id",
"(",
"self",
",",
"element",
")",
":",
"if",
"not",
"element",
".",
"has_attribute",
"(",
"'id'",
")",
":",
"element",
".",
"set_attribute",
"(",
"'id'",
",",
"self",
".",
"prefix_id",
"+",
"str",
"(",
"self",
".",
"count",
")",
... | Generate a id for a element.
:param element: The element.
:type element: hatemile.util.html.HTMLDOMElement | [
"Generate",
"a",
"id",
"for",
"a",
"element",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/hatemile/util/idgenerator.py#L60-L70 |
41,664 | The-Politico/politico-civic-demography | demography/management/commands/bootstrap/fetch/__init__.py | Fetcher.fetch_state_data | def fetch_state_data(self, states):
"""
Fetch census estimates from table.
"""
print("Fetching census data")
for table in CensusTable.objects.all():
api = self.get_series(table.series)
for variable in table.variables.all():
estimate = "{}_{... | python | def fetch_state_data(self, states):
"""
Fetch census estimates from table.
"""
print("Fetching census data")
for table in CensusTable.objects.all():
api = self.get_series(table.series)
for variable in table.variables.all():
estimate = "{}_{... | [
"def",
"fetch_state_data",
"(",
"self",
",",
"states",
")",
":",
"print",
"(",
"\"Fetching census data\"",
")",
"for",
"table",
"in",
"CensusTable",
".",
"objects",
".",
"all",
"(",
")",
":",
"api",
"=",
"self",
".",
"get_series",
"(",
"table",
".",
"ser... | Fetch census estimates from table. | [
"Fetch",
"census",
"estimates",
"from",
"table",
"."
] | 080bb964b64b06db7fd04386530e893ceed1cf98 | https://github.com/The-Politico/politico-civic-demography/blob/080bb964b64b06db7fd04386530e893ceed1cf98/demography/management/commands/bootstrap/fetch/__init__.py#L20-L55 |
41,665 | panyam/typecube | typecube/annotations.py | Annotations.has | def has(self, name):
"""
Returns True if there is atleast one annotation by a given name, otherwise False.
"""
for a in self.all_annotations:
if a.name == name:
return True
return False | python | def has(self, name):
"""
Returns True if there is atleast one annotation by a given name, otherwise False.
"""
for a in self.all_annotations:
if a.name == name:
return True
return False | [
"def",
"has",
"(",
"self",
",",
"name",
")",
":",
"for",
"a",
"in",
"self",
".",
"all_annotations",
":",
"if",
"a",
".",
"name",
"==",
"name",
":",
"return",
"True",
"return",
"False"
] | Returns True if there is atleast one annotation by a given name, otherwise False. | [
"Returns",
"True",
"if",
"there",
"is",
"atleast",
"one",
"annotation",
"by",
"a",
"given",
"name",
"otherwise",
"False",
"."
] | e8fa235675b6497acd52c68286bb9e4aefc5c8d1 | https://github.com/panyam/typecube/blob/e8fa235675b6497acd52c68286bb9e4aefc5c8d1/typecube/annotations.py#L57-L64 |
41,666 | panyam/typecube | typecube/annotations.py | Annotations.get_first | def get_first(self, name):
"""
Get the first annotation by a given name.
"""
for a in self.all_annotations:
if a.name == name:
return a
return None | python | def get_first(self, name):
"""
Get the first annotation by a given name.
"""
for a in self.all_annotations:
if a.name == name:
return a
return None | [
"def",
"get_first",
"(",
"self",
",",
"name",
")",
":",
"for",
"a",
"in",
"self",
".",
"all_annotations",
":",
"if",
"a",
".",
"name",
"==",
"name",
":",
"return",
"a",
"return",
"None"
] | Get the first annotation by a given name. | [
"Get",
"the",
"first",
"annotation",
"by",
"a",
"given",
"name",
"."
] | e8fa235675b6497acd52c68286bb9e4aefc5c8d1 | https://github.com/panyam/typecube/blob/e8fa235675b6497acd52c68286bb9e4aefc5c8d1/typecube/annotations.py#L66-L73 |
41,667 | panyam/typecube | typecube/annotations.py | Annotations.get_all | def get_all(self, name):
"""
Get all the annotation by a given name.
"""
return [annot for annot in self.all_annotations if annot.name == name] | python | def get_all(self, name):
"""
Get all the annotation by a given name.
"""
return [annot for annot in self.all_annotations if annot.name == name] | [
"def",
"get_all",
"(",
"self",
",",
"name",
")",
":",
"return",
"[",
"annot",
"for",
"annot",
"in",
"self",
".",
"all_annotations",
"if",
"annot",
".",
"name",
"==",
"name",
"]"
] | Get all the annotation by a given name. | [
"Get",
"all",
"the",
"annotation",
"by",
"a",
"given",
"name",
"."
] | e8fa235675b6497acd52c68286bb9e4aefc5c8d1 | https://github.com/panyam/typecube/blob/e8fa235675b6497acd52c68286bb9e4aefc5c8d1/typecube/annotations.py#L75-L79 |
41,668 | panyam/typecube | typecube/annotations.py | Annotation.first_value_of | def first_value_of(self, name, default_value = None):
"""
Return the first value of a particular param by name if it exists otherwise false.
"""
vals = self.values_of(name)
if vals is not None:
return vals if type(vals) is not list else vals[0]
return default_... | python | def first_value_of(self, name, default_value = None):
"""
Return the first value of a particular param by name if it exists otherwise false.
"""
vals = self.values_of(name)
if vals is not None:
return vals if type(vals) is not list else vals[0]
return default_... | [
"def",
"first_value_of",
"(",
"self",
",",
"name",
",",
"default_value",
"=",
"None",
")",
":",
"vals",
"=",
"self",
".",
"values_of",
"(",
"name",
")",
"if",
"vals",
"is",
"not",
"None",
":",
"return",
"vals",
"if",
"type",
"(",
"vals",
")",
"is",
... | Return the first value of a particular param by name if it exists otherwise false. | [
"Return",
"the",
"first",
"value",
"of",
"a",
"particular",
"param",
"by",
"name",
"if",
"it",
"exists",
"otherwise",
"false",
"."
] | e8fa235675b6497acd52c68286bb9e4aefc5c8d1 | https://github.com/panyam/typecube/blob/e8fa235675b6497acd52c68286bb9e4aefc5c8d1/typecube/annotations.py#L127-L134 |
41,669 | hatemile/hatemile-for-python | setup.py | get_long_description | def get_long_description():
"""
Returns the long description of HaTeMiLe for Python.
:return: The long description of HaTeMiLe for Python.
:rtype: str
"""
with open(
os.path.join(BASE_DIRECTORY, 'README.md'),
'r',
encoding='utf-8'
) as readme_file:
return re... | python | def get_long_description():
"""
Returns the long description of HaTeMiLe for Python.
:return: The long description of HaTeMiLe for Python.
:rtype: str
"""
with open(
os.path.join(BASE_DIRECTORY, 'README.md'),
'r',
encoding='utf-8'
) as readme_file:
return re... | [
"def",
"get_long_description",
"(",
")",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"BASE_DIRECTORY",
",",
"'README.md'",
")",
",",
"'r'",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"readme_file",
":",
"return",
"readme_file",
".",
"... | Returns the long description of HaTeMiLe for Python.
:return: The long description of HaTeMiLe for Python.
:rtype: str | [
"Returns",
"the",
"long",
"description",
"of",
"HaTeMiLe",
"for",
"Python",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/setup.py#L26-L39 |
41,670 | hatemile/hatemile-for-python | setup.py | get_packages | def get_packages():
"""
Returns the packages used for HaTeMiLe for Python.
:return: The packages used for HaTeMiLe for Python.
:rtype: list(str)
"""
packages = find_packages(exclude=['tests'])
packages.append('')
packages.append('js')
packages.append(LOCALES_DIRECTORY)
for dir... | python | def get_packages():
"""
Returns the packages used for HaTeMiLe for Python.
:return: The packages used for HaTeMiLe for Python.
:rtype: list(str)
"""
packages = find_packages(exclude=['tests'])
packages.append('')
packages.append('js')
packages.append(LOCALES_DIRECTORY)
for dir... | [
"def",
"get_packages",
"(",
")",
":",
"packages",
"=",
"find_packages",
"(",
"exclude",
"=",
"[",
"'tests'",
"]",
")",
"packages",
".",
"append",
"(",
"''",
")",
"packages",
".",
"append",
"(",
"'js'",
")",
"packages",
".",
"append",
"(",
"LOCALES_DIRECT... | Returns the packages used for HaTeMiLe for Python.
:return: The packages used for HaTeMiLe for Python.
:rtype: list(str) | [
"Returns",
"the",
"packages",
"used",
"for",
"HaTeMiLe",
"for",
"Python",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/setup.py#L42-L57 |
41,671 | hatemile/hatemile-for-python | setup.py | get_package_data | def get_package_data():
"""
Returns the packages with static files of HaTeMiLe for Python.
:return: The packages with static files of HaTeMiLe for Python.
:rtype: dict(str, list(str))
"""
package_data = {
'': ['*.xml'],
'js': ['*.js'],
LOCALES_DIRECTORY: ['*']
}
... | python | def get_package_data():
"""
Returns the packages with static files of HaTeMiLe for Python.
:return: The packages with static files of HaTeMiLe for Python.
:rtype: dict(str, list(str))
"""
package_data = {
'': ['*.xml'],
'js': ['*.js'],
LOCALES_DIRECTORY: ['*']
}
... | [
"def",
"get_package_data",
"(",
")",
":",
"package_data",
"=",
"{",
"''",
":",
"[",
"'*.xml'",
"]",
",",
"'js'",
":",
"[",
"'*.js'",
"]",
",",
"LOCALES_DIRECTORY",
":",
"[",
"'*'",
"]",
"}",
"for",
"directory",
"in",
"os",
".",
"listdir",
"(",
"LOCAL... | Returns the packages with static files of HaTeMiLe for Python.
:return: The packages with static files of HaTeMiLe for Python.
:rtype: dict(str, list(str)) | [
"Returns",
"the",
"packages",
"with",
"static",
"files",
"of",
"HaTeMiLe",
"for",
"Python",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/setup.py#L60-L76 |
41,672 | hatemile/hatemile-for-python | setup.py | get_requirements | def get_requirements():
"""
Returns the content of 'requirements.txt' in a list.
:return: The content of 'requirements.txt'.
:rtype: list(str)
"""
requirements = []
with open(
os.path.join(BASE_DIRECTORY, 'requirements.txt'),
'r',
encoding='utf-8'
) as requireme... | python | def get_requirements():
"""
Returns the content of 'requirements.txt' in a list.
:return: The content of 'requirements.txt'.
:rtype: list(str)
"""
requirements = []
with open(
os.path.join(BASE_DIRECTORY, 'requirements.txt'),
'r',
encoding='utf-8'
) as requireme... | [
"def",
"get_requirements",
"(",
")",
":",
"requirements",
"=",
"[",
"]",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"BASE_DIRECTORY",
",",
"'requirements.txt'",
")",
",",
"'r'",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"requirements_file"... | Returns the content of 'requirements.txt' in a list.
:return: The content of 'requirements.txt'.
:rtype: list(str) | [
"Returns",
"the",
"content",
"of",
"requirements",
".",
"txt",
"in",
"a",
"list",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/setup.py#L79-L96 |
41,673 | AtomHash/evernode | evernode/models/session_model.py | SessionModel.where_session_id | def where_session_id(cls, session_id):
""" Easy way to query by session id """
try:
session = cls.query.filter_by(session_id=session_id).one()
return session
except (NoResultFound, MultipleResultsFound):
return None | python | def where_session_id(cls, session_id):
""" Easy way to query by session id """
try:
session = cls.query.filter_by(session_id=session_id).one()
return session
except (NoResultFound, MultipleResultsFound):
return None | [
"def",
"where_session_id",
"(",
"cls",
",",
"session_id",
")",
":",
"try",
":",
"session",
"=",
"cls",
".",
"query",
".",
"filter_by",
"(",
"session_id",
"=",
"session_id",
")",
".",
"one",
"(",
")",
"return",
"session",
"except",
"(",
"NoResultFound",
"... | Easy way to query by session id | [
"Easy",
"way",
"to",
"query",
"by",
"session",
"id"
] | b2fb91555fb937a3f3eba41db56dee26f9b034be | https://github.com/AtomHash/evernode/blob/b2fb91555fb937a3f3eba41db56dee26f9b034be/evernode/models/session_model.py#L14-L20 |
41,674 | AtomHash/evernode | evernode/models/session_model.py | SessionModel.count | def count(cls, user_id):
""" Count sessions with user_id """
return cls.query.with_entities(
cls.user_id).filter_by(user_id=user_id).count() | python | def count(cls, user_id):
""" Count sessions with user_id """
return cls.query.with_entities(
cls.user_id).filter_by(user_id=user_id).count() | [
"def",
"count",
"(",
"cls",
",",
"user_id",
")",
":",
"return",
"cls",
".",
"query",
".",
"with_entities",
"(",
"cls",
".",
"user_id",
")",
".",
"filter_by",
"(",
"user_id",
"=",
"user_id",
")",
".",
"count",
"(",
")"
] | Count sessions with user_id | [
"Count",
"sessions",
"with",
"user_id"
] | b2fb91555fb937a3f3eba41db56dee26f9b034be | https://github.com/AtomHash/evernode/blob/b2fb91555fb937a3f3eba41db56dee26f9b034be/evernode/models/session_model.py#L40-L43 |
41,675 | VJftw/invoke-tools | idflow/utils.py | Utils.get_branch | def get_branch():
"""
Returns the current code branch
"""
if os.getenv('GIT_BRANCH'):
# Travis
branch = os.getenv('GIT_BRANCH')
elif os.getenv('BRANCH_NAME'):
# Jenkins 2
branch = os.getenv('BRANCH_NAME')
else:
b... | python | def get_branch():
"""
Returns the current code branch
"""
if os.getenv('GIT_BRANCH'):
# Travis
branch = os.getenv('GIT_BRANCH')
elif os.getenv('BRANCH_NAME'):
# Jenkins 2
branch = os.getenv('BRANCH_NAME')
else:
b... | [
"def",
"get_branch",
"(",
")",
":",
"if",
"os",
".",
"getenv",
"(",
"'GIT_BRANCH'",
")",
":",
"# Travis",
"branch",
"=",
"os",
".",
"getenv",
"(",
"'GIT_BRANCH'",
")",
"elif",
"os",
".",
"getenv",
"(",
"'BRANCH_NAME'",
")",
":",
"# Jenkins 2",
"branch",
... | Returns the current code branch | [
"Returns",
"the",
"current",
"code",
"branch"
] | 9584a1f8a402118310b6f2a495062f388fc8dc3a | https://github.com/VJftw/invoke-tools/blob/9584a1f8a402118310b6f2a495062f388fc8dc3a/idflow/utils.py#L19-L34 |
41,676 | VJftw/invoke-tools | idflow/utils.py | Utils.get_version | def get_version():
"""
Returns the current code version
"""
try:
return check_output(
"git describe --tags".split(" ")
).decode('utf-8').strip()
except CalledProcessError:
return check_output(
"git rev-parse ... | python | def get_version():
"""
Returns the current code version
"""
try:
return check_output(
"git describe --tags".split(" ")
).decode('utf-8').strip()
except CalledProcessError:
return check_output(
"git rev-parse ... | [
"def",
"get_version",
"(",
")",
":",
"try",
":",
"return",
"check_output",
"(",
"\"git describe --tags\"",
".",
"split",
"(",
"\" \"",
")",
")",
".",
"decode",
"(",
"'utf-8'",
")",
".",
"strip",
"(",
")",
"except",
"CalledProcessError",
":",
"return",
"che... | Returns the current code version | [
"Returns",
"the",
"current",
"code",
"version"
] | 9584a1f8a402118310b6f2a495062f388fc8dc3a | https://github.com/VJftw/invoke-tools/blob/9584a1f8a402118310b6f2a495062f388fc8dc3a/idflow/utils.py#L37-L48 |
41,677 | VJftw/invoke-tools | idflow/utils.py | Utils.jenkins_last_build_sha | def jenkins_last_build_sha():
"""
Returns the sha of the last completed jenkins build for this project.
Expects JOB_URL in environment
"""
job_url = os.getenv('JOB_URL')
job_json_url = "{0}/api/json".format(job_url)
response = urllib.urlopen(job_json_url)
... | python | def jenkins_last_build_sha():
"""
Returns the sha of the last completed jenkins build for this project.
Expects JOB_URL in environment
"""
job_url = os.getenv('JOB_URL')
job_json_url = "{0}/api/json".format(job_url)
response = urllib.urlopen(job_json_url)
... | [
"def",
"jenkins_last_build_sha",
"(",
")",
":",
"job_url",
"=",
"os",
".",
"getenv",
"(",
"'JOB_URL'",
")",
"job_json_url",
"=",
"\"{0}/api/json\"",
".",
"format",
"(",
"job_url",
")",
"response",
"=",
"urllib",
".",
"urlopen",
"(",
"job_json_url",
")",
"job... | Returns the sha of the last completed jenkins build for this project.
Expects JOB_URL in environment | [
"Returns",
"the",
"sha",
"of",
"the",
"last",
"completed",
"jenkins",
"build",
"for",
"this",
"project",
".",
"Expects",
"JOB_URL",
"in",
"environment"
] | 9584a1f8a402118310b6f2a495062f388fc8dc3a | https://github.com/VJftw/invoke-tools/blob/9584a1f8a402118310b6f2a495062f388fc8dc3a/idflow/utils.py#L58-L74 |
41,678 | VJftw/invoke-tools | idflow/utils.py | Utils.get_changed_files_from | def get_changed_files_from(old_commit_sha, new_commit_sha):
"""
Returns a list of the files changed between two commits
"""
return check_output(
"git diff-tree --no-commit-id --name-only -r {0}..{1}".format(
old_commit_sha,
new_commit_sha
... | python | def get_changed_files_from(old_commit_sha, new_commit_sha):
"""
Returns a list of the files changed between two commits
"""
return check_output(
"git diff-tree --no-commit-id --name-only -r {0}..{1}".format(
old_commit_sha,
new_commit_sha
... | [
"def",
"get_changed_files_from",
"(",
"old_commit_sha",
",",
"new_commit_sha",
")",
":",
"return",
"check_output",
"(",
"\"git diff-tree --no-commit-id --name-only -r {0}..{1}\"",
".",
"format",
"(",
"old_commit_sha",
",",
"new_commit_sha",
")",
".",
"split",
"(",
"\" \""... | Returns a list of the files changed between two commits | [
"Returns",
"a",
"list",
"of",
"the",
"files",
"changed",
"between",
"two",
"commits"
] | 9584a1f8a402118310b6f2a495062f388fc8dc3a | https://github.com/VJftw/invoke-tools/blob/9584a1f8a402118310b6f2a495062f388fc8dc3a/idflow/utils.py#L77-L86 |
41,679 | MKLab-ITI/reveal-user-annotation | reveal_user_annotation/mongo/store_snow_data.py | extract_snow_tweets_from_file_generator | def extract_snow_tweets_from_file_generator(json_file_path):
"""
A generator that opens a file containing many json tweets and yields all the tweets contained inside.
Input: - json_file_path: The path of a json file containing a tweet in each line.
Yields: - tweet: A tweet in python dictionary (json)... | python | def extract_snow_tweets_from_file_generator(json_file_path):
"""
A generator that opens a file containing many json tweets and yields all the tweets contained inside.
Input: - json_file_path: The path of a json file containing a tweet in each line.
Yields: - tweet: A tweet in python dictionary (json)... | [
"def",
"extract_snow_tweets_from_file_generator",
"(",
"json_file_path",
")",
":",
"with",
"open",
"(",
"json_file_path",
",",
"\"r\"",
",",
"encoding",
"=",
"\"utf-8\"",
")",
"as",
"fp",
":",
"for",
"file_line",
"in",
"fp",
":",
"tweet",
"=",
"json",
".",
"... | A generator that opens a file containing many json tweets and yields all the tweets contained inside.
Input: - json_file_path: The path of a json file containing a tweet in each line.
Yields: - tweet: A tweet in python dictionary (json) format. | [
"A",
"generator",
"that",
"opens",
"a",
"file",
"containing",
"many",
"json",
"tweets",
"and",
"yields",
"all",
"the",
"tweets",
"contained",
"inside",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/mongo/store_snow_data.py#L8-L19 |
41,680 | MKLab-ITI/reveal-user-annotation | reveal_user_annotation/mongo/store_snow_data.py | extract_all_snow_tweets_from_disk_generator | def extract_all_snow_tweets_from_disk_generator(json_folder_path):
"""
A generator that returns all SNOW tweets stored in disk.
Input: - json_file_path: The path of the folder containing the raw data.
Yields: - tweet: A tweet in python dictionary (json) format.
"""
# Get a generator with all ... | python | def extract_all_snow_tweets_from_disk_generator(json_folder_path):
"""
A generator that returns all SNOW tweets stored in disk.
Input: - json_file_path: The path of the folder containing the raw data.
Yields: - tweet: A tweet in python dictionary (json) format.
"""
# Get a generator with all ... | [
"def",
"extract_all_snow_tweets_from_disk_generator",
"(",
"json_folder_path",
")",
":",
"# Get a generator with all file paths in the folder",
"json_file_path_generator",
"=",
"(",
"json_folder_path",
"+",
"\"/\"",
"+",
"name",
"for",
"name",
"in",
"os",
".",
"listdir",
"(... | A generator that returns all SNOW tweets stored in disk.
Input: - json_file_path: The path of the folder containing the raw data.
Yields: - tweet: A tweet in python dictionary (json) format. | [
"A",
"generator",
"that",
"returns",
"all",
"SNOW",
"tweets",
"stored",
"in",
"disk",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/mongo/store_snow_data.py#L22-L35 |
41,681 | MKLab-ITI/reveal-user-annotation | reveal_user_annotation/mongo/store_snow_data.py | store_snow_tweets_from_disk_to_mongodb | def store_snow_tweets_from_disk_to_mongodb(snow_tweets_folder):
"""
Store all SNOW tweets in a mongodb collection.
"""
client = pymongo.MongoClient("localhost", 27017)
db = client["snow_tweet_storage"]
collection = db["tweets"]
for tweet in extract_all_snow_tweets_from_disk_generator(snow_... | python | def store_snow_tweets_from_disk_to_mongodb(snow_tweets_folder):
"""
Store all SNOW tweets in a mongodb collection.
"""
client = pymongo.MongoClient("localhost", 27017)
db = client["snow_tweet_storage"]
collection = db["tweets"]
for tweet in extract_all_snow_tweets_from_disk_generator(snow_... | [
"def",
"store_snow_tweets_from_disk_to_mongodb",
"(",
"snow_tweets_folder",
")",
":",
"client",
"=",
"pymongo",
".",
"MongoClient",
"(",
"\"localhost\"",
",",
"27017",
")",
"db",
"=",
"client",
"[",
"\"snow_tweet_storage\"",
"]",
"collection",
"=",
"db",
"[",
"\"t... | Store all SNOW tweets in a mongodb collection. | [
"Store",
"all",
"SNOW",
"tweets",
"in",
"a",
"mongodb",
"collection",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/mongo/store_snow_data.py#L38-L48 |
41,682 | liminspace/dju-image | dju_image/tools.py | save_file | def save_file(f, full_path):
"""
Saves file f to full_path and set rules.
"""
make_dirs_for_file_path(full_path, mode=dju_settings.DJU_IMG_CHMOD_DIR)
with open(full_path, 'wb') as t:
f.seek(0)
while True:
buf = f.read(dju_settings.DJU_IMG_RW_FILE_BUFFER_SIZE)
... | python | def save_file(f, full_path):
"""
Saves file f to full_path and set rules.
"""
make_dirs_for_file_path(full_path, mode=dju_settings.DJU_IMG_CHMOD_DIR)
with open(full_path, 'wb') as t:
f.seek(0)
while True:
buf = f.read(dju_settings.DJU_IMG_RW_FILE_BUFFER_SIZE)
... | [
"def",
"save_file",
"(",
"f",
",",
"full_path",
")",
":",
"make_dirs_for_file_path",
"(",
"full_path",
",",
"mode",
"=",
"dju_settings",
".",
"DJU_IMG_CHMOD_DIR",
")",
"with",
"open",
"(",
"full_path",
",",
"'wb'",
")",
"as",
"t",
":",
"f",
".",
"seek",
... | Saves file f to full_path and set rules. | [
"Saves",
"file",
"f",
"to",
"full_path",
"and",
"set",
"rules",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L35-L47 |
41,683 | liminspace/dju-image | dju_image/tools.py | get_profile_configs | def get_profile_configs(profile=None, use_cache=True):
"""
Returns upload configs for profile.
"""
if use_cache and profile in _profile_configs_cache:
return _profile_configs_cache[profile]
profile_conf = None
if profile is not None:
try:
profile_conf = dju_settings.D... | python | def get_profile_configs(profile=None, use_cache=True):
"""
Returns upload configs for profile.
"""
if use_cache and profile in _profile_configs_cache:
return _profile_configs_cache[profile]
profile_conf = None
if profile is not None:
try:
profile_conf = dju_settings.D... | [
"def",
"get_profile_configs",
"(",
"profile",
"=",
"None",
",",
"use_cache",
"=",
"True",
")",
":",
"if",
"use_cache",
"and",
"profile",
"in",
"_profile_configs_cache",
":",
"return",
"_profile_configs_cache",
"[",
"profile",
"]",
"profile_conf",
"=",
"None",
"i... | Returns upload configs for profile. | [
"Returns",
"upload",
"configs",
"for",
"profile",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L50-L72 |
41,684 | liminspace/dju-image | dju_image/tools.py | generate_img_id | def generate_img_id(profile, ext=None, label=None, tmp=False):
"""
Generates img_id.
"""
if ext and not ext.startswith('.'):
ext = '.' + ext
if label:
label = re.sub(r'[^a-z0-9_\-]', '', label, flags=re.I)
label = re.sub(r'_+', '_', label)
label = label[:60]
retur... | python | def generate_img_id(profile, ext=None, label=None, tmp=False):
"""
Generates img_id.
"""
if ext and not ext.startswith('.'):
ext = '.' + ext
if label:
label = re.sub(r'[^a-z0-9_\-]', '', label, flags=re.I)
label = re.sub(r'_+', '_', label)
label = label[:60]
retur... | [
"def",
"generate_img_id",
"(",
"profile",
",",
"ext",
"=",
"None",
",",
"label",
"=",
"None",
",",
"tmp",
"=",
"False",
")",
":",
"if",
"ext",
"and",
"not",
"ext",
".",
"startswith",
"(",
"'.'",
")",
":",
"ext",
"=",
"'.'",
"+",
"ext",
"if",
"lab... | Generates img_id. | [
"Generates",
"img_id",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L75-L92 |
41,685 | liminspace/dju-image | dju_image/tools.py | get_relative_path_from_img_id | def get_relative_path_from_img_id(img_id, variant_label=None, ext=None, create_dirs=False):
"""
Returns path to file relative MEDIA_URL.
"""
profile, base_name = img_id.split(':', 1)
conf = get_profile_configs(profile)
if not variant_label:
status_suffix = dju_settings.DJU_IMG_UPLOAD_MAI... | python | def get_relative_path_from_img_id(img_id, variant_label=None, ext=None, create_dirs=False):
"""
Returns path to file relative MEDIA_URL.
"""
profile, base_name = img_id.split(':', 1)
conf = get_profile_configs(profile)
if not variant_label:
status_suffix = dju_settings.DJU_IMG_UPLOAD_MAI... | [
"def",
"get_relative_path_from_img_id",
"(",
"img_id",
",",
"variant_label",
"=",
"None",
",",
"ext",
"=",
"None",
",",
"create_dirs",
"=",
"False",
")",
":",
"profile",
",",
"base_name",
"=",
"img_id",
".",
"split",
"(",
"':'",
",",
"1",
")",
"conf",
"=... | Returns path to file relative MEDIA_URL. | [
"Returns",
"path",
"to",
"file",
"relative",
"MEDIA_URL",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L101-L144 |
41,686 | liminspace/dju-image | dju_image/tools.py | is_img_id_exists | def is_img_id_exists(img_id):
"""
Checks if img_id has real file on filesystem.
"""
main_rel_path = get_relative_path_from_img_id(img_id)
main_path = media_path(main_rel_path)
return os.path.isfile(main_path) | python | def is_img_id_exists(img_id):
"""
Checks if img_id has real file on filesystem.
"""
main_rel_path = get_relative_path_from_img_id(img_id)
main_path = media_path(main_rel_path)
return os.path.isfile(main_path) | [
"def",
"is_img_id_exists",
"(",
"img_id",
")",
":",
"main_rel_path",
"=",
"get_relative_path_from_img_id",
"(",
"img_id",
")",
"main_path",
"=",
"media_path",
"(",
"main_rel_path",
")",
"return",
"os",
".",
"path",
".",
"isfile",
"(",
"main_path",
")"
] | Checks if img_id has real file on filesystem. | [
"Checks",
"if",
"img_id",
"has",
"real",
"file",
"on",
"filesystem",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L147-L153 |
41,687 | liminspace/dju-image | dju_image/tools.py | is_img_id_valid | def is_img_id_valid(img_id):
"""
Checks if img_id is valid.
"""
t = re.sub(r'[^a-z0-9_:\-\.]', '', img_id, re.IGNORECASE)
t = re.sub(r'\.+', '.', t)
if img_id != t or img_id.count(':') != 1:
return False
profile, base_name = img_id.split(':', 1)
if not profile or not base_name:
... | python | def is_img_id_valid(img_id):
"""
Checks if img_id is valid.
"""
t = re.sub(r'[^a-z0-9_:\-\.]', '', img_id, re.IGNORECASE)
t = re.sub(r'\.+', '.', t)
if img_id != t or img_id.count(':') != 1:
return False
profile, base_name = img_id.split(':', 1)
if not profile or not base_name:
... | [
"def",
"is_img_id_valid",
"(",
"img_id",
")",
":",
"t",
"=",
"re",
".",
"sub",
"(",
"r'[^a-z0-9_:\\-\\.]'",
",",
"''",
",",
"img_id",
",",
"re",
".",
"IGNORECASE",
")",
"t",
"=",
"re",
".",
"sub",
"(",
"r'\\.+'",
",",
"'.'",
",",
"t",
")",
"if",
... | Checks if img_id is valid. | [
"Checks",
"if",
"img_id",
"is",
"valid",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L156-L171 |
41,688 | liminspace/dju-image | dju_image/tools.py | remove_all_files_of_img_id | def remove_all_files_of_img_id(img_id):
"""
Removes all img_id's files.
"""
files = get_files_by_img_id(img_id, check_hash=False)
if files:
os.remove(media_path(files['main']))
for fn in files['variants'].values():
os.remove(media_path(fn)) | python | def remove_all_files_of_img_id(img_id):
"""
Removes all img_id's files.
"""
files = get_files_by_img_id(img_id, check_hash=False)
if files:
os.remove(media_path(files['main']))
for fn in files['variants'].values():
os.remove(media_path(fn)) | [
"def",
"remove_all_files_of_img_id",
"(",
"img_id",
")",
":",
"files",
"=",
"get_files_by_img_id",
"(",
"img_id",
",",
"check_hash",
"=",
"False",
")",
"if",
"files",
":",
"os",
".",
"remove",
"(",
"media_path",
"(",
"files",
"[",
"'main'",
"]",
")",
")",
... | Removes all img_id's files. | [
"Removes",
"all",
"img_id",
"s",
"files",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L236-L244 |
41,689 | liminspace/dju-image | dju_image/tools.py | remove_tmp_prefix_from_filename | def remove_tmp_prefix_from_filename(filename):
"""
Remove tmp prefix from filename.
"""
if not filename.startswith(dju_settings.DJU_IMG_UPLOAD_TMP_PREFIX):
raise RuntimeError(ERROR_MESSAGES['filename_hasnt_tmp_prefix'] % {'filename': filename})
return filename[len(dju_settings.DJU_IMG_UPLOAD... | python | def remove_tmp_prefix_from_filename(filename):
"""
Remove tmp prefix from filename.
"""
if not filename.startswith(dju_settings.DJU_IMG_UPLOAD_TMP_PREFIX):
raise RuntimeError(ERROR_MESSAGES['filename_hasnt_tmp_prefix'] % {'filename': filename})
return filename[len(dju_settings.DJU_IMG_UPLOAD... | [
"def",
"remove_tmp_prefix_from_filename",
"(",
"filename",
")",
":",
"if",
"not",
"filename",
".",
"startswith",
"(",
"dju_settings",
".",
"DJU_IMG_UPLOAD_TMP_PREFIX",
")",
":",
"raise",
"RuntimeError",
"(",
"ERROR_MESSAGES",
"[",
"'filename_hasnt_tmp_prefix'",
"]",
"... | Remove tmp prefix from filename. | [
"Remove",
"tmp",
"prefix",
"from",
"filename",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L251-L257 |
41,690 | liminspace/dju-image | dju_image/tools.py | remove_tmp_prefix_from_file_path | def remove_tmp_prefix_from_file_path(file_path):
"""
Remove tmp prefix from file path or url.
"""
path, filename = os.path.split(file_path)
return os.path.join(path, remove_tmp_prefix_from_filename(filename)).replace('\\', '/') | python | def remove_tmp_prefix_from_file_path(file_path):
"""
Remove tmp prefix from file path or url.
"""
path, filename = os.path.split(file_path)
return os.path.join(path, remove_tmp_prefix_from_filename(filename)).replace('\\', '/') | [
"def",
"remove_tmp_prefix_from_file_path",
"(",
"file_path",
")",
":",
"path",
",",
"filename",
"=",
"os",
".",
"path",
".",
"split",
"(",
"file_path",
")",
"return",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"remove_tmp_prefix_from_filename",
"(",
"... | Remove tmp prefix from file path or url. | [
"Remove",
"tmp",
"prefix",
"from",
"file",
"path",
"or",
"url",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L260-L265 |
41,691 | liminspace/dju-image | dju_image/tools.py | make_permalink | def make_permalink(img_id):
"""
Removes tmp prefix from filename and rename main and variant files.
Returns img_id without tmp prefix.
"""
profile, filename = img_id.split(':', 1)
new_img_id = profile + ':' + remove_tmp_prefix_from_filename(filename)
urls = get_files_by_img_id(img_id)
if... | python | def make_permalink(img_id):
"""
Removes tmp prefix from filename and rename main and variant files.
Returns img_id without tmp prefix.
"""
profile, filename = img_id.split(':', 1)
new_img_id = profile + ':' + remove_tmp_prefix_from_filename(filename)
urls = get_files_by_img_id(img_id)
if... | [
"def",
"make_permalink",
"(",
"img_id",
")",
":",
"profile",
",",
"filename",
"=",
"img_id",
".",
"split",
"(",
"':'",
",",
"1",
")",
"new_img_id",
"=",
"profile",
"+",
"':'",
"+",
"remove_tmp_prefix_from_filename",
"(",
"filename",
")",
"urls",
"=",
"get_... | Removes tmp prefix from filename and rename main and variant files.
Returns img_id without tmp prefix. | [
"Removes",
"tmp",
"prefix",
"from",
"filename",
"and",
"rename",
"main",
"and",
"variant",
"files",
".",
"Returns",
"img_id",
"without",
"tmp",
"prefix",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L268-L283 |
41,692 | liminspace/dju-image | dju_image/tools.py | upload_from_fs | def upload_from_fs(fn, profile=None, label=None):
"""
Saves image from fn with TMP prefix and returns img_id.
"""
if not os.path.isfile(fn):
raise ValueError('File is not exists: {}'.format(fn))
if profile is None:
profile = 'default'
conf = get_profile_configs(profile)
with ... | python | def upload_from_fs(fn, profile=None, label=None):
"""
Saves image from fn with TMP prefix and returns img_id.
"""
if not os.path.isfile(fn):
raise ValueError('File is not exists: {}'.format(fn))
if profile is None:
profile = 'default'
conf = get_profile_configs(profile)
with ... | [
"def",
"upload_from_fs",
"(",
"fn",
",",
"profile",
"=",
"None",
",",
"label",
"=",
"None",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"fn",
")",
":",
"raise",
"ValueError",
"(",
"'File is not exists: {}'",
".",
"format",
"(",
"fn",
... | Saves image from fn with TMP prefix and returns img_id. | [
"Saves",
"image",
"from",
"fn",
"with",
"TMP",
"prefix",
"and",
"returns",
"img_id",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L308-L323 |
41,693 | liminspace/dju-image | dju_image/tools.py | upload_from_fileobject | def upload_from_fileobject(f, profile=None, label=None):
"""
Saves image from f with TMP prefix and returns img_id.
"""
if profile is None:
profile = 'default'
conf = get_profile_configs(profile)
f.seek(0)
if not is_image(f, types=conf['TYPES']):
msg = (('Format of uploaded f... | python | def upload_from_fileobject(f, profile=None, label=None):
"""
Saves image from f with TMP prefix and returns img_id.
"""
if profile is None:
profile = 'default'
conf = get_profile_configs(profile)
f.seek(0)
if not is_image(f, types=conf['TYPES']):
msg = (('Format of uploaded f... | [
"def",
"upload_from_fileobject",
"(",
"f",
",",
"profile",
"=",
"None",
",",
"label",
"=",
"None",
")",
":",
"if",
"profile",
"is",
"None",
":",
"profile",
"=",
"'default'",
"conf",
"=",
"get_profile_configs",
"(",
"profile",
")",
"f",
".",
"seek",
"(",
... | Saves image from f with TMP prefix and returns img_id. | [
"Saves",
"image",
"from",
"f",
"with",
"TMP",
"prefix",
"and",
"returns",
"img_id",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/tools.py#L326-L339 |
41,694 | PonteIneptique/flask-github-proxy | flask_github_proxy/__init__.py | GithubProxy.request | def request(self, method, url, **kwargs):
""" Unified method to make request to the Github API
:param method: HTTP Method to use
:param url: URL to reach
:param kwargs: dictionary of arguments (params for URL parameters, data for post/put data)
:return: Response
"""
... | python | def request(self, method, url, **kwargs):
""" Unified method to make request to the Github API
:param method: HTTP Method to use
:param url: URL to reach
:param kwargs: dictionary of arguments (params for URL parameters, data for post/put data)
:return: Response
"""
... | [
"def",
"request",
"(",
"self",
",",
"method",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"\"data\"",
"in",
"kwargs",
":",
"kwargs",
"[",
"\"data\"",
"]",
"=",
"json",
".",
"dumps",
"(",
"kwargs",
"[",
"\"data\"",
"]",
")",
"kwargs",
"[",
... | Unified method to make request to the Github API
:param method: HTTP Method to use
:param url: URL to reach
:param kwargs: dictionary of arguments (params for URL parameters, data for post/put data)
:return: Response | [
"Unified",
"method",
"to",
"make",
"request",
"to",
"the",
"Github",
"API"
] | f0a60639342f7c0834360dc12a099bfc3a06d939 | https://github.com/PonteIneptique/flask-github-proxy/blob/f0a60639342f7c0834360dc12a099bfc3a06d939/flask_github_proxy/__init__.py#L113-L141 |
41,695 | PonteIneptique/flask-github-proxy | flask_github_proxy/__init__.py | GithubProxy.default_branch | def default_branch(self, file):
""" Decide the name of the default branch given the file and the configuration
:param file: File with informations about it
:return: Branch Name
"""
if isinstance(self.__default_branch__, str):
return self.__default_branch__
el... | python | def default_branch(self, file):
""" Decide the name of the default branch given the file and the configuration
:param file: File with informations about it
:return: Branch Name
"""
if isinstance(self.__default_branch__, str):
return self.__default_branch__
el... | [
"def",
"default_branch",
"(",
"self",
",",
"file",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"__default_branch__",
",",
"str",
")",
":",
"return",
"self",
".",
"__default_branch__",
"elif",
"self",
".",
"__default_branch__",
"==",
"GithubProxy",
".",
"... | Decide the name of the default branch given the file and the configuration
:param file: File with informations about it
:return: Branch Name | [
"Decide",
"the",
"name",
"of",
"the",
"default",
"branch",
"given",
"the",
"file",
"and",
"the",
"configuration"
] | f0a60639342f7c0834360dc12a099bfc3a06d939 | https://github.com/PonteIneptique/flask-github-proxy/blob/f0a60639342f7c0834360dc12a099bfc3a06d939/flask_github_proxy/__init__.py#L143-L154 |
41,696 | PonteIneptique/flask-github-proxy | flask_github_proxy/__init__.py | GithubProxy.init_app | def init_app(self, app):
""" Initialize the application and register the blueprint
:param app: Flask Application
:return: Blueprint of the current nemo app
:rtype: flask.Blueprint
"""
self.app = app
self.__blueprint__ = Blueprint(
self.__name__,
... | python | def init_app(self, app):
""" Initialize the application and register the blueprint
:param app: Flask Application
:return: Blueprint of the current nemo app
:rtype: flask.Blueprint
"""
self.app = app
self.__blueprint__ = Blueprint(
self.__name__,
... | [
"def",
"init_app",
"(",
"self",
",",
"app",
")",
":",
"self",
".",
"app",
"=",
"app",
"self",
".",
"__blueprint__",
"=",
"Blueprint",
"(",
"self",
".",
"__name__",
",",
"self",
".",
"__name__",
",",
"url_prefix",
"=",
"self",
".",
"__prefix__",
",",
... | Initialize the application and register the blueprint
:param app: Flask Application
:return: Blueprint of the current nemo app
:rtype: flask.Blueprint | [
"Initialize",
"the",
"application",
"and",
"register",
"the",
"blueprint"
] | f0a60639342f7c0834360dc12a099bfc3a06d939 | https://github.com/PonteIneptique/flask-github-proxy/blob/f0a60639342f7c0834360dc12a099bfc3a06d939/flask_github_proxy/__init__.py#L184-L208 |
41,697 | PonteIneptique/flask-github-proxy | flask_github_proxy/__init__.py | GithubProxy.put | def put(self, file):
""" Create a new file on github
:param file: File to create
:return: File or self.ProxyError
"""
input_ = {
"message": file.logs,
"author": file.author.dict(),
"content": file.base64,
"branch": file.branch
... | python | def put(self, file):
""" Create a new file on github
:param file: File to create
:return: File or self.ProxyError
"""
input_ = {
"message": file.logs,
"author": file.author.dict(),
"content": file.base64,
"branch": file.branch
... | [
"def",
"put",
"(",
"self",
",",
"file",
")",
":",
"input_",
"=",
"{",
"\"message\"",
":",
"file",
".",
"logs",
",",
"\"author\"",
":",
"file",
".",
"author",
".",
"dict",
"(",
")",
",",
"\"content\"",
":",
"file",
".",
"base64",
",",
"\"branch\"",
... | Create a new file on github
:param file: File to create
:return: File or self.ProxyError | [
"Create",
"a",
"new",
"file",
"on",
"github"
] | f0a60639342f7c0834360dc12a099bfc3a06d939 | https://github.com/PonteIneptique/flask-github-proxy/blob/f0a60639342f7c0834360dc12a099bfc3a06d939/flask_github_proxy/__init__.py#L210-L240 |
41,698 | PonteIneptique/flask-github-proxy | flask_github_proxy/__init__.py | GithubProxy.get | def get(self, file):
""" Check on github if a file exists
:param file: File to check status of
:return: File with new information, including blob, or Error
:rtype: File or self.ProxyError
"""
uri = "{api}/repos/{origin}/contents/{path}".format(
api=self.githu... | python | def get(self, file):
""" Check on github if a file exists
:param file: File to check status of
:return: File with new information, including blob, or Error
:rtype: File or self.ProxyError
"""
uri = "{api}/repos/{origin}/contents/{path}".format(
api=self.githu... | [
"def",
"get",
"(",
"self",
",",
"file",
")",
":",
"uri",
"=",
"\"{api}/repos/{origin}/contents/{path}\"",
".",
"format",
"(",
"api",
"=",
"self",
".",
"github_api_url",
",",
"origin",
"=",
"self",
".",
"origin",
",",
"path",
"=",
"file",
".",
"path",
")"... | Check on github if a file exists
:param file: File to check status of
:return: File with new information, including blob, or Error
:rtype: File or self.ProxyError | [
"Check",
"on",
"github",
"if",
"a",
"file",
"exists"
] | f0a60639342f7c0834360dc12a099bfc3a06d939 | https://github.com/PonteIneptique/flask-github-proxy/blob/f0a60639342f7c0834360dc12a099bfc3a06d939/flask_github_proxy/__init__.py#L242-L273 |
41,699 | PonteIneptique/flask-github-proxy | flask_github_proxy/__init__.py | GithubProxy.update | def update(self, file):
""" Make an update query on Github API for given file
:param file: File to update, with its content
:return: File with new information, including success (or Error)
"""
params = {
"message": file.logs,
"author": file.author.dict(),... | python | def update(self, file):
""" Make an update query on Github API for given file
:param file: File to update, with its content
:return: File with new information, including success (or Error)
"""
params = {
"message": file.logs,
"author": file.author.dict(),... | [
"def",
"update",
"(",
"self",
",",
"file",
")",
":",
"params",
"=",
"{",
"\"message\"",
":",
"file",
".",
"logs",
",",
"\"author\"",
":",
"file",
".",
"author",
".",
"dict",
"(",
")",
",",
"\"content\"",
":",
"file",
".",
"base64",
",",
"\"sha\"",
... | Make an update query on Github API for given file
:param file: File to update, with its content
:return: File with new information, including success (or Error) | [
"Make",
"an",
"update",
"query",
"on",
"Github",
"API",
"for",
"given",
"file"
] | f0a60639342f7c0834360dc12a099bfc3a06d939 | https://github.com/PonteIneptique/flask-github-proxy/blob/f0a60639342f7c0834360dc12a099bfc3a06d939/flask_github_proxy/__init__.py#L275-L305 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.