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 listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
erikrose/nose-progressive | noseprogressive/tracebacks.py | _count_relevant_tb_levels | def _count_relevant_tb_levels(tb):
"""Return the number of frames in ``tb`` before all that's left is unittest frames.
Unlike its namesake in unittest, this doesn't bail out as soon as it hits a
unittest frame, which means we don't bail out as soon as somebody uses the
mock library, which defines ``__u... | python | def _count_relevant_tb_levels(tb):
"""Return the number of frames in ``tb`` before all that's left is unittest frames.
Unlike its namesake in unittest, this doesn't bail out as soon as it hits a
unittest frame, which means we don't bail out as soon as somebody uses the
mock library, which defines ``__u... | [
"def",
"_count_relevant_tb_levels",
"(",
"tb",
")",
":",
"length",
"=",
"contiguous_unittest_frames",
"=",
"0",
"while",
"tb",
":",
"length",
"+=",
"1",
"if",
"_is_unittest_frame",
"(",
"tb",
")",
":",
"contiguous_unittest_frames",
"+=",
"1",
"else",
":",
"con... | Return the number of frames in ``tb`` before all that's left is unittest frames.
Unlike its namesake in unittest, this doesn't bail out as soon as it hits a
unittest frame, which means we don't bail out as soon as somebody uses the
mock library, which defines ``__unittest``. | [
"Return",
"the",
"number",
"of",
"frames",
"in",
"tb",
"before",
"all",
"that",
"s",
"left",
"is",
"unittest",
"frames",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/tracebacks.py#L142-L158 | train | 60,700 |
erikrose/nose-progressive | noseprogressive/wrapping.py | cmdloop | def cmdloop(self, *args, **kwargs):
"""Call pdb's cmdloop, making readline work.
Patch raw_input so it sees the original stdin and stdout, lest
readline refuse to work.
The C implementation of raw_input uses readline functionality only if
both stdin and stdout are from a terminal AND are FILE*s (n... | python | def cmdloop(self, *args, **kwargs):
"""Call pdb's cmdloop, making readline work.
Patch raw_input so it sees the original stdin and stdout, lest
readline refuse to work.
The C implementation of raw_input uses readline functionality only if
both stdin and stdout are from a terminal AND are FILE*s (n... | [
"def",
"cmdloop",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"unwrapping_raw_input",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Call raw_input(), making sure it finds an unwrapped stdout.\"\"\"",
"wrapped_stdout",
"="... | Call pdb's cmdloop, making readline work.
Patch raw_input so it sees the original stdin and stdout, lest
readline refuse to work.
The C implementation of raw_input uses readline functionality only if
both stdin and stdout are from a terminal AND are FILE*s (not
PyObject*s): http://bugs.python.org/... | [
"Call",
"pdb",
"s",
"cmdloop",
"making",
"readline",
"work",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/wrapping.py#L10-L45 | train | 60,701 |
erikrose/nose-progressive | noseprogressive/wrapping.py | set_trace | def set_trace(*args, **kwargs):
"""Call pdb.set_trace, making sure it receives the unwrapped stdout.
This is so we don't keep drawing progress bars over debugger output.
"""
# There's no stream attr if capture plugin is enabled:
out = sys.stdout.stream if hasattr(sys.stdout, 'stream') else None
... | python | def set_trace(*args, **kwargs):
"""Call pdb.set_trace, making sure it receives the unwrapped stdout.
This is so we don't keep drawing progress bars over debugger output.
"""
# There's no stream attr if capture plugin is enabled:
out = sys.stdout.stream if hasattr(sys.stdout, 'stream') else None
... | [
"def",
"set_trace",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# There's no stream attr if capture plugin is enabled:",
"out",
"=",
"sys",
".",
"stdout",
".",
"stream",
"if",
"hasattr",
"(",
"sys",
".",
"stdout",
",",
"'stream'",
")",
"else",
"Non... | Call pdb.set_trace, making sure it receives the unwrapped stdout.
This is so we don't keep drawing progress bars over debugger output. | [
"Call",
"pdb",
".",
"set_trace",
"making",
"sure",
"it",
"receives",
"the",
"unwrapped",
"stdout",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/wrapping.py#L48-L66 | train | 60,702 |
erikrose/nose-progressive | noseprogressive/plugin.py | ProgressivePlugin.begin | def begin(self):
"""Make some monkeypatches to dodge progress bar.
Wrap stderr and stdout to keep other users of them from smearing the
progress bar. Wrap some pdb routines to stop showing the bar while in
the debugger.
"""
# The calls to begin/finalize end up like this... | python | def begin(self):
"""Make some monkeypatches to dodge progress bar.
Wrap stderr and stdout to keep other users of them from smearing the
progress bar. Wrap some pdb routines to stop showing the bar while in
the debugger.
"""
# The calls to begin/finalize end up like this... | [
"def",
"begin",
"(",
"self",
")",
":",
"# The calls to begin/finalize end up like this: a call to begin() on",
"# instance A of the plugin, then a paired begin/finalize for each test",
"# on instance B, then a final call to finalize() on instance A.",
"# TODO: Do only if isatty.",
"self",
".",... | Make some monkeypatches to dodge progress bar.
Wrap stderr and stdout to keep other users of them from smearing the
progress bar. Wrap some pdb routines to stop showing the bar while in
the debugger. | [
"Make",
"some",
"monkeypatches",
"to",
"dodge",
"progress",
"bar",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/plugin.py#L27-L54 | train | 60,703 |
erikrose/nose-progressive | noseprogressive/plugin.py | ProgressivePlugin.finalize | def finalize(self, result):
"""Put monkeypatches back as we found them."""
sys.stderr = self._stderr.pop()
sys.stdout = self._stdout.pop()
pdb.set_trace = self._set_trace.pop()
pdb.Pdb.cmdloop = self._cmdloop.pop() | python | def finalize(self, result):
"""Put monkeypatches back as we found them."""
sys.stderr = self._stderr.pop()
sys.stdout = self._stdout.pop()
pdb.set_trace = self._set_trace.pop()
pdb.Pdb.cmdloop = self._cmdloop.pop() | [
"def",
"finalize",
"(",
"self",
",",
"result",
")",
":",
"sys",
".",
"stderr",
"=",
"self",
".",
"_stderr",
".",
"pop",
"(",
")",
"sys",
".",
"stdout",
"=",
"self",
".",
"_stdout",
".",
"pop",
"(",
")",
"pdb",
".",
"set_trace",
"=",
"self",
".",
... | Put monkeypatches back as we found them. | [
"Put",
"monkeypatches",
"back",
"as",
"we",
"found",
"them",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/plugin.py#L56-L61 | train | 60,704 |
erikrose/nose-progressive | noseprogressive/plugin.py | ProgressivePlugin.configure | def configure(self, options, conf):
"""Turn style-forcing on if bar-forcing is on.
It'd be messy to position the bar but still have the rest of the
terminal capabilities emit ''.
"""
super(ProgressivePlugin, self).configure(options, conf)
if (getattr(options, 'verbosity... | python | def configure(self, options, conf):
"""Turn style-forcing on if bar-forcing is on.
It'd be messy to position the bar but still have the rest of the
terminal capabilities emit ''.
"""
super(ProgressivePlugin, self).configure(options, conf)
if (getattr(options, 'verbosity... | [
"def",
"configure",
"(",
"self",
",",
"options",
",",
"conf",
")",
":",
"super",
"(",
"ProgressivePlugin",
",",
"self",
")",
".",
"configure",
"(",
"options",
",",
"conf",
")",
"if",
"(",
"getattr",
"(",
"options",
",",
"'verbosity'",
",",
"0",
")",
... | Turn style-forcing on if bar-forcing is on.
It'd be messy to position the bar but still have the rest of the
terminal capabilities emit ''. | [
"Turn",
"style",
"-",
"forcing",
"on",
"if",
"bar",
"-",
"forcing",
"is",
"on",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/plugin.py#L147-L162 | train | 60,705 |
erikrose/nose-progressive | noseprogressive/bar.py | ProgressBar.update | def update(self, test_path, number):
"""Draw an updated progress bar.
At the moment, the graph takes a fixed width, and the test identifier
takes the rest of the row, truncated from the left to fit.
test_path -- the selector of the test being run
number -- how many tests have b... | python | def update(self, test_path, number):
"""Draw an updated progress bar.
At the moment, the graph takes a fixed width, and the test identifier
takes the rest of the row, truncated from the left to fit.
test_path -- the selector of the test being run
number -- how many tests have b... | [
"def",
"update",
"(",
"self",
",",
"test_path",
",",
"number",
")",
":",
"# TODO: Play nicely with absurdly narrow terminals. (OS X's won't even",
"# go small enough to hurt us.)",
"# Figure out graph:",
"GRAPH_WIDTH",
"=",
"14",
"# min() is in case we somehow get the total test coun... | Draw an updated progress bar.
At the moment, the graph takes a fixed width, and the test identifier
takes the rest of the row, truncated from the left to fit.
test_path -- the selector of the test being run
number -- how many tests have been run so far, including this one | [
"Draw",
"an",
"updated",
"progress",
"bar",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/bar.py#L41-L72 | train | 60,706 |
erikrose/nose-progressive | noseprogressive/bar.py | ProgressBar.erase | def erase(self):
"""White out the progress bar."""
with self._at_last_line():
self.stream.write(self._term.clear_eol)
self.stream.flush() | python | def erase(self):
"""White out the progress bar."""
with self._at_last_line():
self.stream.write(self._term.clear_eol)
self.stream.flush() | [
"def",
"erase",
"(",
"self",
")",
":",
"with",
"self",
".",
"_at_last_line",
"(",
")",
":",
"self",
".",
"stream",
".",
"write",
"(",
"self",
".",
"_term",
".",
"clear_eol",
")",
"self",
".",
"stream",
".",
"flush",
"(",
")"
] | White out the progress bar. | [
"White",
"out",
"the",
"progress",
"bar",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/bar.py#L74-L78 | train | 60,707 |
erikrose/nose-progressive | noseprogressive/bar.py | ProgressBar.dodging | def dodging(bar):
"""Return a context manager which erases the bar, lets you output things, and then redraws the bar.
It's reentrant.
"""
class ShyProgressBar(object):
"""Context manager that implements a progress bar that gets out of the way"""
def __enter__(s... | python | def dodging(bar):
"""Return a context manager which erases the bar, lets you output things, and then redraws the bar.
It's reentrant.
"""
class ShyProgressBar(object):
"""Context manager that implements a progress bar that gets out of the way"""
def __enter__(s... | [
"def",
"dodging",
"(",
"bar",
")",
":",
"class",
"ShyProgressBar",
"(",
"object",
")",
":",
"\"\"\"Context manager that implements a progress bar that gets out of the way\"\"\"",
"def",
"__enter__",
"(",
"self",
")",
":",
"\"\"\"Erase the progress bar so bits of disembodied pro... | Return a context manager which erases the bar, lets you output things, and then redraws the bar.
It's reentrant. | [
"Return",
"a",
"context",
"manager",
"which",
"erases",
"the",
"bar",
"lets",
"you",
"output",
"things",
"and",
"then",
"redraws",
"the",
"bar",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/bar.py#L84-L113 | train | 60,708 |
erikrose/nose-progressive | noseprogressive/runner.py | ProgressiveRunner._makeResult | def _makeResult(self):
"""Return a Result that doesn't print dots.
Nose's ResultProxy will wrap it, and other plugins can still print
stuff---but without smashing into our progress bar, care of
ProgressivePlugin's stderr/out wrapping.
"""
return ProgressiveResult(self._... | python | def _makeResult(self):
"""Return a Result that doesn't print dots.
Nose's ResultProxy will wrap it, and other plugins can still print
stuff---but without smashing into our progress bar, care of
ProgressivePlugin's stderr/out wrapping.
"""
return ProgressiveResult(self._... | [
"def",
"_makeResult",
"(",
"self",
")",
":",
"return",
"ProgressiveResult",
"(",
"self",
".",
"_cwd",
",",
"self",
".",
"_totalTests",
",",
"self",
".",
"stream",
",",
"config",
"=",
"self",
".",
"config",
")"
] | Return a Result that doesn't print dots.
Nose's ResultProxy will wrap it, and other plugins can still print
stuff---but without smashing into our progress bar, care of
ProgressivePlugin's stderr/out wrapping. | [
"Return",
"a",
"Result",
"that",
"doesn",
"t",
"print",
"dots",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/runner.py#L16-L27 | train | 60,709 |
erikrose/nose-progressive | noseprogressive/runner.py | ProgressiveRunner.run | def run(self, test):
"Run the given test case or test suite...quietly."
# These parts of Nose's pluggability are baked into
# nose.core.TextTestRunner. Reproduce them:
wrapper = self.config.plugins.prepareTest(test)
if wrapper is not None:
test = wrapper
wrapp... | python | def run(self, test):
"Run the given test case or test suite...quietly."
# These parts of Nose's pluggability are baked into
# nose.core.TextTestRunner. Reproduce them:
wrapper = self.config.plugins.prepareTest(test)
if wrapper is not None:
test = wrapper
wrapp... | [
"def",
"run",
"(",
"self",
",",
"test",
")",
":",
"# These parts of Nose's pluggability are baked into",
"# nose.core.TextTestRunner. Reproduce them:",
"wrapper",
"=",
"self",
".",
"config",
".",
"plugins",
".",
"prepareTest",
"(",
"test",
")",
"if",
"wrapper",
"is",
... | Run the given test case or test suite...quietly. | [
"Run",
"the",
"given",
"test",
"case",
"or",
"test",
"suite",
"...",
"quietly",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/runner.py#L29-L64 | train | 60,710 |
erikrose/nose-progressive | noseprogressive/result.py | ProgressiveResult._printTraceback | def _printTraceback(self, test, err):
"""Print a nicely formatted traceback.
:arg err: exc_info()-style traceback triple
:arg test: the test that precipitated this call
"""
# Don't bind third item to a local var; that can create
# circular refs which are expensive to co... | python | def _printTraceback(self, test, err):
"""Print a nicely formatted traceback.
:arg err: exc_info()-style traceback triple
:arg test: the test that precipitated this call
"""
# Don't bind third item to a local var; that can create
# circular refs which are expensive to co... | [
"def",
"_printTraceback",
"(",
"self",
",",
"test",
",",
"err",
")",
":",
"# Don't bind third item to a local var; that can create",
"# circular refs which are expensive to collect. See the",
"# sys.exc_info() docs.",
"exception_type",
",",
"exception_value",
"=",
"err",
"[",
"... | Print a nicely formatted traceback.
:arg err: exc_info()-style traceback triple
:arg test: the test that precipitated this call | [
"Print",
"a",
"nicely",
"formatted",
"traceback",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/result.py#L46-L91 | train | 60,711 |
erikrose/nose-progressive | noseprogressive/result.py | ProgressiveResult._printHeadline | def _printHeadline(self, kind, test, is_failure=True):
"""Output a 1-line error summary to the stream if appropriate.
The line contains the kind of error and the pathname of the test.
:arg kind: The (string) type of incident the precipitated this call
:arg test: The test that precipita... | python | def _printHeadline(self, kind, test, is_failure=True):
"""Output a 1-line error summary to the stream if appropriate.
The line contains the kind of error and the pathname of the test.
:arg kind: The (string) type of incident the precipitated this call
:arg test: The test that precipita... | [
"def",
"_printHeadline",
"(",
"self",
",",
"kind",
",",
"test",
",",
"is_failure",
"=",
"True",
")",
":",
"if",
"is_failure",
"or",
"self",
".",
"_options",
".",
"show_advisories",
":",
"with",
"self",
".",
"bar",
".",
"dodging",
"(",
")",
":",
"self",... | Output a 1-line error summary to the stream if appropriate.
The line contains the kind of error and the pathname of the test.
:arg kind: The (string) type of incident the precipitated this call
:arg test: The test that precipitated this call | [
"Output",
"a",
"1",
"-",
"line",
"error",
"summary",
"to",
"the",
"stream",
"if",
"appropriate",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/result.py#L93-L108 | train | 60,712 |
erikrose/nose-progressive | noseprogressive/result.py | ProgressiveResult._recordAndPrintHeadline | def _recordAndPrintHeadline(self, test, error_class, artifact):
"""Record that an error-like thing occurred, and print a summary.
Store ``artifact`` with the record.
Return whether the test result is any sort of failure.
"""
# We duplicate the errorclass handling from super ra... | python | def _recordAndPrintHeadline(self, test, error_class, artifact):
"""Record that an error-like thing occurred, and print a summary.
Store ``artifact`` with the record.
Return whether the test result is any sort of failure.
"""
# We duplicate the errorclass handling from super ra... | [
"def",
"_recordAndPrintHeadline",
"(",
"self",
",",
"test",
",",
"error_class",
",",
"artifact",
")",
":",
"# We duplicate the errorclass handling from super rather than calling",
"# it and monkeying around with showAll flags to keep it from printing",
"# anything.",
"is_error_class",
... | Record that an error-like thing occurred, and print a summary.
Store ``artifact`` with the record.
Return whether the test result is any sort of failure. | [
"Record",
"that",
"an",
"error",
"-",
"like",
"thing",
"occurred",
"and",
"print",
"a",
"summary",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/result.py#L110-L136 | train | 60,713 |
erikrose/nose-progressive | noseprogressive/result.py | ProgressiveResult.addSkip | def addSkip(self, test, reason):
"""Catch skipped tests in Python 2.7 and above.
Though ``addSkip()`` is deprecated in the nose plugin API, it is very
much not deprecated as a Python 2.7 ``TestResult`` method. In Python
2.7, this will get called instead of ``addError()`` for skips.
... | python | def addSkip(self, test, reason):
"""Catch skipped tests in Python 2.7 and above.
Though ``addSkip()`` is deprecated in the nose plugin API, it is very
much not deprecated as a Python 2.7 ``TestResult`` method. In Python
2.7, this will get called instead of ``addError()`` for skips.
... | [
"def",
"addSkip",
"(",
"self",
",",
"test",
",",
"reason",
")",
":",
"self",
".",
"_recordAndPrintHeadline",
"(",
"test",
",",
"SkipTest",
",",
"reason",
")",
"# Python 2.7 users get a little bonus: the reason the test was skipped.",
"if",
"isinstance",
"(",
"reason",... | Catch skipped tests in Python 2.7 and above.
Though ``addSkip()`` is deprecated in the nose plugin API, it is very
much not deprecated as a Python 2.7 ``TestResult`` method. In Python
2.7, this will get called instead of ``addError()`` for skips.
:arg reason: Text describing why the te... | [
"Catch",
"skipped",
"tests",
"in",
"Python",
"2",
".",
"7",
"and",
"above",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/result.py#L138-L155 | train | 60,714 |
erikrose/nose-progressive | noseprogressive/result.py | ProgressiveResult.printSummary | def printSummary(self, start, stop):
"""As a final summary, print number of tests, broken down by result."""
def renderResultType(type, number, is_failure):
"""Return a rendering like '2 failures'.
:arg type: A singular label, like "failure"
:arg number: The number o... | python | def printSummary(self, start, stop):
"""As a final summary, print number of tests, broken down by result."""
def renderResultType(type, number, is_failure):
"""Return a rendering like '2 failures'.
:arg type: A singular label, like "failure"
:arg number: The number o... | [
"def",
"printSummary",
"(",
"self",
",",
"start",
",",
"stop",
")",
":",
"def",
"renderResultType",
"(",
"type",
",",
"number",
",",
"is_failure",
")",
":",
"\"\"\"Return a rendering like '2 failures'.\n\n :arg type: A singular label, like \"failure\"\n ... | As a final summary, print number of tests, broken down by result. | [
"As",
"a",
"final",
"summary",
"print",
"number",
"of",
"tests",
"broken",
"down",
"by",
"result",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/result.py#L170-L209 | train | 60,715 |
erikrose/nose-progressive | noseprogressive/utils.py | nose_selector | def nose_selector(test):
"""Return the string you can pass to nose to run `test`, including argument
values if the test was made by a test generator.
Return "Unknown test" if it can't construct a decent path.
"""
address = test_address(test)
if address:
file, module, rest = address
... | python | def nose_selector(test):
"""Return the string you can pass to nose to run `test`, including argument
values if the test was made by a test generator.
Return "Unknown test" if it can't construct a decent path.
"""
address = test_address(test)
if address:
file, module, rest = address
... | [
"def",
"nose_selector",
"(",
"test",
")",
":",
"address",
"=",
"test_address",
"(",
"test",
")",
"if",
"address",
":",
"file",
",",
"module",
",",
"rest",
"=",
"address",
"if",
"module",
":",
"if",
"rest",
":",
"try",
":",
"return",
"'%s:%s%s'",
"%",
... | Return the string you can pass to nose to run `test`, including argument
values if the test was made by a test generator.
Return "Unknown test" if it can't construct a decent path. | [
"Return",
"the",
"string",
"you",
"can",
"pass",
"to",
"nose",
"to",
"run",
"test",
"including",
"argument",
"values",
"if",
"the",
"test",
"was",
"made",
"by",
"a",
"test",
"generator",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/utils.py#L17-L36 | train | 60,716 |
erikrose/nose-progressive | noseprogressive/utils.py | human_path | def human_path(path, cwd):
"""Return the most human-readable representation of the given path.
If an absolute path is given that's within the current directory, convert
it to a relative path to shorten it. Otherwise, return the absolute path.
"""
# TODO: Canonicalize the path to remove /kitsune/..... | python | def human_path(path, cwd):
"""Return the most human-readable representation of the given path.
If an absolute path is given that's within the current directory, convert
it to a relative path to shorten it. Otherwise, return the absolute path.
"""
# TODO: Canonicalize the path to remove /kitsune/..... | [
"def",
"human_path",
"(",
"path",
",",
"cwd",
")",
":",
"# TODO: Canonicalize the path to remove /kitsune/../kitsune nonsense.",
"path",
"=",
"abspath",
"(",
"path",
")",
"if",
"cwd",
"and",
"path",
".",
"startswith",
"(",
"cwd",
")",
":",
"path",
"=",
"path",
... | Return the most human-readable representation of the given path.
If an absolute path is given that's within the current directory, convert
it to a relative path to shorten it. Otherwise, return the absolute path. | [
"Return",
"the",
"most",
"human",
"-",
"readable",
"representation",
"of",
"the",
"given",
"path",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/utils.py#L121-L132 | train | 60,717 |
erikrose/nose-progressive | noseprogressive/utils.py | OneTrackMind.know | def know(self, what, confidence):
"""Know something with the given confidence, and return self for chaining.
If confidence is higher than that of what we already know, replace
what we already know with what you're telling us.
"""
if confidence > self.confidence:
sel... | python | def know(self, what, confidence):
"""Know something with the given confidence, and return self for chaining.
If confidence is higher than that of what we already know, replace
what we already know with what you're telling us.
"""
if confidence > self.confidence:
sel... | [
"def",
"know",
"(",
"self",
",",
"what",
",",
"confidence",
")",
":",
"if",
"confidence",
">",
"self",
".",
"confidence",
":",
"self",
".",
"best",
"=",
"what",
"self",
".",
"confidence",
"=",
"confidence",
"return",
"self"
] | Know something with the given confidence, and return self for chaining.
If confidence is higher than that of what we already know, replace
what we already know with what you're telling us. | [
"Know",
"something",
"with",
"the",
"given",
"confidence",
"and",
"return",
"self",
"for",
"chaining",
"."
] | 42853f11290cfaac8aa3d204714b71e27cc4ec07 | https://github.com/erikrose/nose-progressive/blob/42853f11290cfaac8aa3d204714b71e27cc4ec07/noseprogressive/utils.py#L51-L61 | train | 60,718 |
astropy/pyregion | pyregion/wcs_converter.py | _generate_arg_types | def _generate_arg_types(coordlist_length, shape_name):
"""Find coordinate types based on shape name and coordlist length
This function returns a list of coordinate types based on which
coordinates can be repeated for a given type of shap
Parameters
----------
coordlist_length : int
The... | python | def _generate_arg_types(coordlist_length, shape_name):
"""Find coordinate types based on shape name and coordlist length
This function returns a list of coordinate types based on which
coordinates can be repeated for a given type of shap
Parameters
----------
coordlist_length : int
The... | [
"def",
"_generate_arg_types",
"(",
"coordlist_length",
",",
"shape_name",
")",
":",
"from",
".",
"ds9_region_parser",
"import",
"ds9_shape_defs",
"from",
".",
"ds9_attr_parser",
"import",
"ds9_shape_in_comment_defs",
"if",
"shape_name",
"in",
"ds9_shape_defs",
":",
"sha... | Find coordinate types based on shape name and coordlist length
This function returns a list of coordinate types based on which
coordinates can be repeated for a given type of shap
Parameters
----------
coordlist_length : int
The number of coordinates or arguments used to define the shape.
... | [
"Find",
"coordinate",
"types",
"based",
"on",
"shape",
"name",
"and",
"coordlist",
"length"
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/wcs_converter.py#L13-L55 | train | 60,719 |
astropy/pyregion | pyregion/wcs_converter.py | convert_to_imagecoord | def convert_to_imagecoord(shape, header):
"""Convert the coordlist of `shape` to image coordinates
Parameters
----------
shape : `pyregion.parser_helper.Shape`
The `Shape` to convert coordinates
header : `~astropy.io.fits.Header`
Specifies what WCS transformations to use.
Retu... | python | def convert_to_imagecoord(shape, header):
"""Convert the coordlist of `shape` to image coordinates
Parameters
----------
shape : `pyregion.parser_helper.Shape`
The `Shape` to convert coordinates
header : `~astropy.io.fits.Header`
Specifies what WCS transformations to use.
Retu... | [
"def",
"convert_to_imagecoord",
"(",
"shape",
",",
"header",
")",
":",
"arg_types",
"=",
"_generate_arg_types",
"(",
"len",
"(",
"shape",
".",
"coord_list",
")",
",",
"shape",
".",
"name",
")",
"new_coordlist",
"=",
"[",
"]",
"is_even_distance",
"=",
"True",... | Convert the coordlist of `shape` to image coordinates
Parameters
----------
shape : `pyregion.parser_helper.Shape`
The `Shape` to convert coordinates
header : `~astropy.io.fits.Header`
Specifies what WCS transformations to use.
Returns
-------
new_coordlist : list
... | [
"Convert",
"the",
"coordlist",
"of",
"shape",
"to",
"image",
"coordinates"
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/wcs_converter.py#L58-L115 | train | 60,720 |
havardgulldahl/jottalib | src/jottalib/JFS.py | get_auth_info | def get_auth_info():
""" Get authentication details to jottacloud.
Will first check environment variables, then the .netrc file.
"""
env_username = os.environ.get('JOTTACLOUD_USERNAME')
env_password = os.environ.get('JOTTACLOUD_PASSWORD')
netrc_auth = None
try:
netrc_file = netrc.ne... | python | def get_auth_info():
""" Get authentication details to jottacloud.
Will first check environment variables, then the .netrc file.
"""
env_username = os.environ.get('JOTTACLOUD_USERNAME')
env_password = os.environ.get('JOTTACLOUD_PASSWORD')
netrc_auth = None
try:
netrc_file = netrc.ne... | [
"def",
"get_auth_info",
"(",
")",
":",
"env_username",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'JOTTACLOUD_USERNAME'",
")",
"env_password",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'JOTTACLOUD_PASSWORD'",
")",
"netrc_auth",
"=",
"None",
"try",
":",
... | Get authentication details to jottacloud.
Will first check environment variables, then the .netrc file. | [
"Get",
"authentication",
"details",
"to",
"jottacloud",
"."
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L67-L90 | train | 60,721 |
havardgulldahl/jottalib | src/jottalib/JFS.py | calculate_md5 | def calculate_md5(fileobject, size=2**16):
"""Utility function to calculate md5 hashes while being light on memory usage.
By reading the fileobject piece by piece, we are able to process content that
is larger than available memory"""
fileobject.seek(0)
md5 = hashlib.md5()
for data in iter(lamb... | python | def calculate_md5(fileobject, size=2**16):
"""Utility function to calculate md5 hashes while being light on memory usage.
By reading the fileobject piece by piece, we are able to process content that
is larger than available memory"""
fileobject.seek(0)
md5 = hashlib.md5()
for data in iter(lamb... | [
"def",
"calculate_md5",
"(",
"fileobject",
",",
"size",
"=",
"2",
"**",
"16",
")",
":",
"fileobject",
".",
"seek",
"(",
"0",
")",
"md5",
"=",
"hashlib",
".",
"md5",
"(",
")",
"for",
"data",
"in",
"iter",
"(",
"lambda",
":",
"fileobject",
".",
"read... | Utility function to calculate md5 hashes while being light on memory usage.
By reading the fileobject piece by piece, we are able to process content that
is larger than available memory | [
"Utility",
"function",
"to",
"calculate",
"md5",
"hashes",
"while",
"being",
"light",
"on",
"memory",
"usage",
"."
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L92-L105 | train | 60,722 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSFolder.deleted | def deleted(self):
'Return datetime.datetime or None if the file isnt deleted'
_d = self.folder.attrib.get('deleted', None)
if _d is None: return None
return dateutil.parser.parse(str(_d)) | python | def deleted(self):
'Return datetime.datetime or None if the file isnt deleted'
_d = self.folder.attrib.get('deleted', None)
if _d is None: return None
return dateutil.parser.parse(str(_d)) | [
"def",
"deleted",
"(",
"self",
")",
":",
"_d",
"=",
"self",
".",
"folder",
".",
"attrib",
".",
"get",
"(",
"'deleted'",
",",
"None",
")",
"if",
"_d",
"is",
"None",
":",
"return",
"None",
"return",
"dateutil",
".",
"parser",
".",
"parse",
"(",
"str"... | Return datetime.datetime or None if the file isnt deleted | [
"Return",
"datetime",
".",
"datetime",
"or",
"None",
"if",
"the",
"file",
"isnt",
"deleted"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L240-L244 | train | 60,723 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSFolder.sync | def sync(self):
'Update state of folder from Jottacloud server'
log.info("syncing %r" % self.path)
self.folder = self.jfs.get(self.path)
self.synced = True | python | def sync(self):
'Update state of folder from Jottacloud server'
log.info("syncing %r" % self.path)
self.folder = self.jfs.get(self.path)
self.synced = True | [
"def",
"sync",
"(",
"self",
")",
":",
"log",
".",
"info",
"(",
"\"syncing %r\"",
"%",
"self",
".",
"path",
")",
"self",
".",
"folder",
"=",
"self",
".",
"jfs",
".",
"get",
"(",
"self",
".",
"path",
")",
"self",
".",
"synced",
"=",
"True"
] | Update state of folder from Jottacloud server | [
"Update",
"state",
"of",
"folder",
"from",
"Jottacloud",
"server"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L246-L250 | train | 60,724 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSFolder.mkdir | def mkdir(self, foldername):
'Create a new subfolder and return the new JFSFolder'
#url = '%s?mkDir=true' % posixpath.join(self.path, foldername)
url = posixpath.join(self.path, foldername)
params = {'mkDir':'true'}
r = self.jfs.post(url, params)
self.sync()
retur... | python | def mkdir(self, foldername):
'Create a new subfolder and return the new JFSFolder'
#url = '%s?mkDir=true' % posixpath.join(self.path, foldername)
url = posixpath.join(self.path, foldername)
params = {'mkDir':'true'}
r = self.jfs.post(url, params)
self.sync()
retur... | [
"def",
"mkdir",
"(",
"self",
",",
"foldername",
")",
":",
"#url = '%s?mkDir=true' % posixpath.join(self.path, foldername)",
"url",
"=",
"posixpath",
".",
"join",
"(",
"self",
".",
"path",
",",
"foldername",
")",
"params",
"=",
"{",
"'mkDir'",
":",
"'true'",
"}",... | Create a new subfolder and return the new JFSFolder | [
"Create",
"a",
"new",
"subfolder",
"and",
"return",
"the",
"new",
"JFSFolder"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L280-L287 | train | 60,725 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSFolder.delete | def delete(self):
'Delete this folder and return a deleted JFSFolder'
#url = '%s?dlDir=true' % self.path
params = {'dlDir':'true'}
r = self.jfs.post(self.path, params)
self.sync()
return r | python | def delete(self):
'Delete this folder and return a deleted JFSFolder'
#url = '%s?dlDir=true' % self.path
params = {'dlDir':'true'}
r = self.jfs.post(self.path, params)
self.sync()
return r | [
"def",
"delete",
"(",
"self",
")",
":",
"#url = '%s?dlDir=true' % self.path",
"params",
"=",
"{",
"'dlDir'",
":",
"'true'",
"}",
"r",
"=",
"self",
".",
"jfs",
".",
"post",
"(",
"self",
".",
"path",
",",
"params",
")",
"self",
".",
"sync",
"(",
")",
"... | Delete this folder and return a deleted JFSFolder | [
"Delete",
"this",
"folder",
"and",
"return",
"a",
"deleted",
"JFSFolder"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L315-L321 | train | 60,726 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSFolder.hard_delete | def hard_delete(self):
'Deletes without possibility to restore'
url = 'https://www.jottacloud.com/rest/webrest/%s/action/delete' % self.jfs.username
data = {'paths[]': self.path.replace(JFS_ROOT, ''),
'web': 'true',
'ts': int(time.time()),
'authTok... | python | def hard_delete(self):
'Deletes without possibility to restore'
url = 'https://www.jottacloud.com/rest/webrest/%s/action/delete' % self.jfs.username
data = {'paths[]': self.path.replace(JFS_ROOT, ''),
'web': 'true',
'ts': int(time.time()),
'authTok... | [
"def",
"hard_delete",
"(",
"self",
")",
":",
"url",
"=",
"'https://www.jottacloud.com/rest/webrest/%s/action/delete'",
"%",
"self",
".",
"jfs",
".",
"username",
"data",
"=",
"{",
"'paths[]'",
":",
"self",
".",
"path",
".",
"replace",
"(",
"JFS_ROOT",
",",
"''"... | Deletes without possibility to restore | [
"Deletes",
"without",
"possibility",
"to",
"restore"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L323-L331 | train | 60,727 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSFolder.rename | def rename(self, newpath):
"Move folder to a new name, possibly a whole new path"
# POST https://www.jottacloud.com/jfs/**USERNAME**/Jotta/Sync/Ny%20mappe?mvDir=/**USERNAME**/Jotta/Sync/testFolder
#url = '%s?mvDir=/%s%s' % (self.path, self.jfs.username, newpath)
params = {'mvDir':'/%s%s'... | python | def rename(self, newpath):
"Move folder to a new name, possibly a whole new path"
# POST https://www.jottacloud.com/jfs/**USERNAME**/Jotta/Sync/Ny%20mappe?mvDir=/**USERNAME**/Jotta/Sync/testFolder
#url = '%s?mvDir=/%s%s' % (self.path, self.jfs.username, newpath)
params = {'mvDir':'/%s%s'... | [
"def",
"rename",
"(",
"self",
",",
"newpath",
")",
":",
"# POST https://www.jottacloud.com/jfs/**USERNAME**/Jotta/Sync/Ny%20mappe?mvDir=/**USERNAME**/Jotta/Sync/testFolder",
"#url = '%s?mvDir=/%s%s' % (self.path, self.jfs.username, newpath)",
"params",
"=",
"{",
"'mvDir'",
":",
"'/%s%s... | Move folder to a new name, possibly a whole new path | [
"Move",
"folder",
"to",
"a",
"new",
"name",
"possibly",
"a",
"whole",
"new",
"path"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L334-L342 | train | 60,728 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSFolder.up | def up(self, fileobj_or_path, filename=None, upload_callback=None):
'Upload a file to current folder and return the new JFSFile'
close_on_done = False
if isinstance(fileobj_or_path, six.string_types):
filename = filename or os.path.basename(fileobj_or_path)
fileobj_or_pa... | python | def up(self, fileobj_or_path, filename=None, upload_callback=None):
'Upload a file to current folder and return the new JFSFile'
close_on_done = False
if isinstance(fileobj_or_path, six.string_types):
filename = filename or os.path.basename(fileobj_or_path)
fileobj_or_pa... | [
"def",
"up",
"(",
"self",
",",
"fileobj_or_path",
",",
"filename",
"=",
"None",
",",
"upload_callback",
"=",
"None",
")",
":",
"close_on_done",
"=",
"False",
"if",
"isinstance",
"(",
"fileobj_or_path",
",",
"six",
".",
"string_types",
")",
":",
"filename",
... | Upload a file to current folder and return the new JFSFile | [
"Upload",
"a",
"file",
"to",
"current",
"folder",
"and",
"return",
"the",
"new",
"JFSFile"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L344-L370 | train | 60,729 |
havardgulldahl/jottalib | src/jottalib/JFS.py | ProtoFile.factory | def factory(fileobject, jfs, parentpath): # fileobject from lxml.objectify
'Class method to get the correct file class instatiated'
if hasattr(fileobject, 'currentRevision'): # a normal file
return JFSFile(fileobject, jfs, parentpath)
elif str(fileobject.latestRevision.state) == Prot... | python | def factory(fileobject, jfs, parentpath): # fileobject from lxml.objectify
'Class method to get the correct file class instatiated'
if hasattr(fileobject, 'currentRevision'): # a normal file
return JFSFile(fileobject, jfs, parentpath)
elif str(fileobject.latestRevision.state) == Prot... | [
"def",
"factory",
"(",
"fileobject",
",",
"jfs",
",",
"parentpath",
")",
":",
"# fileobject from lxml.objectify",
"if",
"hasattr",
"(",
"fileobject",
",",
"'currentRevision'",
")",
":",
"# a normal file",
"return",
"JFSFile",
"(",
"fileobject",
",",
"jfs",
",",
... | Class method to get the correct file class instatiated | [
"Class",
"method",
"to",
"get",
"the",
"correct",
"file",
"class",
"instatiated"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L387-L396 | train | 60,730 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSIncompleteFile.resume | def resume(self, data):
'Resume uploading an incomplete file, after a previous upload was interrupted. Returns new file object'
if not hasattr(data, 'read'):
data = six.BytesIO(data)#StringIO(data)
#Check that we actually know from what byte to resume.
#If self.size === -1, ... | python | def resume(self, data):
'Resume uploading an incomplete file, after a previous upload was interrupted. Returns new file object'
if not hasattr(data, 'read'):
data = six.BytesIO(data)#StringIO(data)
#Check that we actually know from what byte to resume.
#If self.size === -1, ... | [
"def",
"resume",
"(",
"self",
",",
"data",
")",
":",
"if",
"not",
"hasattr",
"(",
"data",
",",
"'read'",
")",
":",
"data",
"=",
"six",
".",
"BytesIO",
"(",
"data",
")",
"#StringIO(data)",
"#Check that we actually know from what byte to resume.",
"#If self.size =... | Resume uploading an incomplete file, after a previous upload was interrupted. Returns new file object | [
"Resume",
"uploading",
"an",
"incomplete",
"file",
"after",
"a",
"previous",
"upload",
"was",
"interrupted",
".",
"Returns",
"new",
"file",
"object"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L496-L514 | train | 60,731 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSIncompleteFile.size | def size(self):
"""Bytes uploaded of the file so far.
Note that we only have the file size if the file was requested directly,
not if it's part of a folder listing.
"""
if hasattr(self.f.latestRevision, 'size'):
return int(self.f.latestRevision.size)
return N... | python | def size(self):
"""Bytes uploaded of the file so far.
Note that we only have the file size if the file was requested directly,
not if it's part of a folder listing.
"""
if hasattr(self.f.latestRevision, 'size'):
return int(self.f.latestRevision.size)
return N... | [
"def",
"size",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
".",
"f",
".",
"latestRevision",
",",
"'size'",
")",
":",
"return",
"int",
"(",
"self",
".",
"f",
".",
"latestRevision",
".",
"size",
")",
"return",
"None"
] | Bytes uploaded of the file so far.
Note that we only have the file size if the file was requested directly,
not if it's part of a folder listing. | [
"Bytes",
"uploaded",
"of",
"the",
"file",
"so",
"far",
"."
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L517-L525 | train | 60,732 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSFile.stream | def stream(self, chunk_size=64*1024):
'Returns a generator to iterate over the file contents'
#return self.jfs.stream(url='%s?mode=bin' % self.path, chunk_size=chunk_size)
return self.jfs.stream(url=self.path, params={'mode':'bin'}, chunk_size=chunk_size) | python | def stream(self, chunk_size=64*1024):
'Returns a generator to iterate over the file contents'
#return self.jfs.stream(url='%s?mode=bin' % self.path, chunk_size=chunk_size)
return self.jfs.stream(url=self.path, params={'mode':'bin'}, chunk_size=chunk_size) | [
"def",
"stream",
"(",
"self",
",",
"chunk_size",
"=",
"64",
"*",
"1024",
")",
":",
"#return self.jfs.stream(url='%s?mode=bin' % self.path, chunk_size=chunk_size)",
"return",
"self",
".",
"jfs",
".",
"stream",
"(",
"url",
"=",
"self",
".",
"path",
",",
"params",
... | Returns a generator to iterate over the file contents | [
"Returns",
"a",
"generator",
"to",
"iterate",
"over",
"the",
"file",
"contents"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L559-L562 | train | 60,733 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSFile.restore | def restore(self):
'Restore the file'
#
#
# As of 2016-06-15, Jottacloud.com has changed their restore api
# To restore, this is what's done
#
# HTTP POST to https://www.jottacloud.com/web/restore/trash/list
# Data:
# hash:undefined
# ... | python | def restore(self):
'Restore the file'
#
#
# As of 2016-06-15, Jottacloud.com has changed their restore api
# To restore, this is what's done
#
# HTTP POST to https://www.jottacloud.com/web/restore/trash/list
# Data:
# hash:undefined
# ... | [
"def",
"restore",
"(",
"self",
")",
":",
"#",
"#",
"# As of 2016-06-15, Jottacloud.com has changed their restore api",
"# To restore, this is what's done",
"#",
"# HTTP POST to https://www.jottacloud.com/web/restore/trash/list",
"# Data:",
"# hash:undefined",
"# files:@0025d37be5... | Restore the file | [
"Restore",
"the",
"file"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L619-L643 | train | 60,734 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSFile.delete | def delete(self):
'Delete this file and return the new, deleted JFSFile'
#url = '%s?dl=true' % self.path
r = self.jfs.post(url=self.path, params={'dl':'true'})
return r | python | def delete(self):
'Delete this file and return the new, deleted JFSFile'
#url = '%s?dl=true' % self.path
r = self.jfs.post(url=self.path, params={'dl':'true'})
return r | [
"def",
"delete",
"(",
"self",
")",
":",
"#url = '%s?dl=true' % self.path",
"r",
"=",
"self",
".",
"jfs",
".",
"post",
"(",
"url",
"=",
"self",
".",
"path",
",",
"params",
"=",
"{",
"'dl'",
":",
"'true'",
"}",
")",
"return",
"r"
] | Delete this file and return the new, deleted JFSFile | [
"Delete",
"this",
"file",
"and",
"return",
"the",
"new",
"deleted",
"JFSFile"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L655-L659 | train | 60,735 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSFile.thumb | def thumb(self, size=BIGTHUMB):
'''Get a thumbnail as string or None if the file isnt an image
size would be one of JFSFile.BIGTHUMB, .MEDIUMTHUMB, .SMALLTHUMB or .XLTHUMB'''
if not self.is_image():
return None
if not size in (self.BIGTHUMB, self.MEDIUMTHUMB, self.SMALLTHUMB... | python | def thumb(self, size=BIGTHUMB):
'''Get a thumbnail as string or None if the file isnt an image
size would be one of JFSFile.BIGTHUMB, .MEDIUMTHUMB, .SMALLTHUMB or .XLTHUMB'''
if not self.is_image():
return None
if not size in (self.BIGTHUMB, self.MEDIUMTHUMB, self.SMALLTHUMB... | [
"def",
"thumb",
"(",
"self",
",",
"size",
"=",
"BIGTHUMB",
")",
":",
"if",
"not",
"self",
".",
"is_image",
"(",
")",
":",
"return",
"None",
"if",
"not",
"size",
"in",
"(",
"self",
".",
"BIGTHUMB",
",",
"self",
".",
"MEDIUMTHUMB",
",",
"self",
".",
... | Get a thumbnail as string or None if the file isnt an image
size would be one of JFSFile.BIGTHUMB, .MEDIUMTHUMB, .SMALLTHUMB or .XLTHUMB | [
"Get",
"a",
"thumbnail",
"as",
"string",
"or",
"None",
"if",
"the",
"file",
"isnt",
"an",
"image"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L670-L680 | train | 60,736 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSDevice.new_mountpoint | def new_mountpoint(self, name):
"""Create a new mountpoint"""
url = posixpath.join(self.path, name)
r = self._jfs.post(url, extra_headers={'content-type': 'application/x-www-form-urlencoded'})
return r | python | def new_mountpoint(self, name):
"""Create a new mountpoint"""
url = posixpath.join(self.path, name)
r = self._jfs.post(url, extra_headers={'content-type': 'application/x-www-form-urlencoded'})
return r | [
"def",
"new_mountpoint",
"(",
"self",
",",
"name",
")",
":",
"url",
"=",
"posixpath",
".",
"join",
"(",
"self",
".",
"path",
",",
"name",
")",
"r",
"=",
"self",
".",
"_jfs",
".",
"post",
"(",
"url",
",",
"extra_headers",
"=",
"{",
"'content-type'",
... | Create a new mountpoint | [
"Create",
"a",
"new",
"mountpoint"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L848-L852 | train | 60,737 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSenableSharing.sharedFiles | def sharedFiles(self):
'iterate over shared files and get their public URI'
for f in self.sharing.files.iterchildren():
yield (f.attrib['name'], f.attrib['uuid'],
'https://www.jottacloud.com/p/%s/%s' % (self.jfs.username, f.publicURI.text)) | python | def sharedFiles(self):
'iterate over shared files and get their public URI'
for f in self.sharing.files.iterchildren():
yield (f.attrib['name'], f.attrib['uuid'],
'https://www.jottacloud.com/p/%s/%s' % (self.jfs.username, f.publicURI.text)) | [
"def",
"sharedFiles",
"(",
"self",
")",
":",
"for",
"f",
"in",
"self",
".",
"sharing",
".",
"files",
".",
"iterchildren",
"(",
")",
":",
"yield",
"(",
"f",
".",
"attrib",
"[",
"'name'",
"]",
",",
"f",
".",
"attrib",
"[",
"'uuid'",
"]",
",",
"'htt... | iterate over shared files and get their public URI | [
"iterate",
"over",
"shared",
"files",
"and",
"get",
"their",
"public",
"URI"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L904-L908 | train | 60,738 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFSsearchresult.files | def files(self):
'iterate over found files'
for _f in self.searchresult.files.iterchildren():
yield ProtoFile.factory(_f, jfs=self.jfs, parentpath=unicode(_f.abspath)) | python | def files(self):
'iterate over found files'
for _f in self.searchresult.files.iterchildren():
yield ProtoFile.factory(_f, jfs=self.jfs, parentpath=unicode(_f.abspath)) | [
"def",
"files",
"(",
"self",
")",
":",
"for",
"_f",
"in",
"self",
".",
"searchresult",
".",
"files",
".",
"iterchildren",
"(",
")",
":",
"yield",
"ProtoFile",
".",
"factory",
"(",
"_f",
",",
"jfs",
"=",
"self",
".",
"jfs",
",",
"parentpath",
"=",
"... | iterate over found files | [
"iterate",
"over",
"found",
"files"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L940-L943 | train | 60,739 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFS.request | def request(self, url, extra_headers=None, params=None):
'Make a GET request for url, with or without caching'
if not url.startswith('http'):
# relative url
url = self.rootpath + url
log.debug("getting url: %r, extra_headers=%r, params=%r", url, extra_headers, params)
... | python | def request(self, url, extra_headers=None, params=None):
'Make a GET request for url, with or without caching'
if not url.startswith('http'):
# relative url
url = self.rootpath + url
log.debug("getting url: %r, extra_headers=%r, params=%r", url, extra_headers, params)
... | [
"def",
"request",
"(",
"self",
",",
"url",
",",
"extra_headers",
"=",
"None",
",",
"params",
"=",
"None",
")",
":",
"if",
"not",
"url",
".",
"startswith",
"(",
"'http'",
")",
":",
"# relative url",
"url",
"=",
"self",
".",
"rootpath",
"+",
"url",
"lo... | Make a GET request for url, with or without caching | [
"Make",
"a",
"GET",
"request",
"for",
"url",
"with",
"or",
"without",
"caching"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L973-L984 | train | 60,740 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFS.raw | def raw(self, url, extra_headers=None, params=None):
'Make a GET request for url and return whatever content we get'
r = self.request(url, extra_headers=extra_headers, params=params)
# uncomment to dump raw xml
# with open('/tmp/%s.xml' % time.time(), 'wb') as f:
# f.write(r.... | python | def raw(self, url, extra_headers=None, params=None):
'Make a GET request for url and return whatever content we get'
r = self.request(url, extra_headers=extra_headers, params=params)
# uncomment to dump raw xml
# with open('/tmp/%s.xml' % time.time(), 'wb') as f:
# f.write(r.... | [
"def",
"raw",
"(",
"self",
",",
"url",
",",
"extra_headers",
"=",
"None",
",",
"params",
"=",
"None",
")",
":",
"r",
"=",
"self",
".",
"request",
"(",
"url",
",",
"extra_headers",
"=",
"extra_headers",
",",
"params",
"=",
"params",
")",
"# uncomment to... | Make a GET request for url and return whatever content we get | [
"Make",
"a",
"GET",
"request",
"for",
"url",
"and",
"return",
"whatever",
"content",
"we",
"get"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L986-L996 | train | 60,741 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFS.get | def get(self, url, params=None):
'Make a GET request for url and return the response content as a generic lxml.objectify object'
url = self.escapeUrl(url)
content = six.BytesIO(self.raw(url, params=params))
# We need to make sure that the xml fits in available memory before we parse
... | python | def get(self, url, params=None):
'Make a GET request for url and return the response content as a generic lxml.objectify object'
url = self.escapeUrl(url)
content = six.BytesIO(self.raw(url, params=params))
# We need to make sure that the xml fits in available memory before we parse
... | [
"def",
"get",
"(",
"self",
",",
"url",
",",
"params",
"=",
"None",
")",
":",
"url",
"=",
"self",
".",
"escapeUrl",
"(",
"url",
")",
"content",
"=",
"six",
".",
"BytesIO",
"(",
"self",
".",
"raw",
"(",
"url",
",",
"params",
"=",
"params",
")",
"... | Make a GET request for url and return the response content as a generic lxml.objectify object | [
"Make",
"a",
"GET",
"request",
"for",
"url",
"and",
"return",
"the",
"response",
"content",
"as",
"a",
"generic",
"lxml",
".",
"objectify",
"object"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L998-L1022 | train | 60,742 |
havardgulldahl/jottalib | src/jottalib/JFS.py | JFS.devices | def devices(self):
'return generator of configured devices'
return self.fs is not None and [JFSDevice(d, self, parentpath=self.rootpath) for d in self.fs.devices.iterchildren()] or [x for x in []] | python | def devices(self):
'return generator of configured devices'
return self.fs is not None and [JFSDevice(d, self, parentpath=self.rootpath) for d in self.fs.devices.iterchildren()] or [x for x in []] | [
"def",
"devices",
"(",
"self",
")",
":",
"return",
"self",
".",
"fs",
"is",
"not",
"None",
"and",
"[",
"JFSDevice",
"(",
"d",
",",
"self",
",",
"parentpath",
"=",
"self",
".",
"rootpath",
")",
"for",
"d",
"in",
"self",
".",
"fs",
".",
"devices",
... | return generator of configured devices | [
"return",
"generator",
"of",
"configured",
"devices"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L1194-L1196 | train | 60,743 |
astropy/pyregion | pyregion/core.py | parse | def parse(region_string):
"""Parse DS9 region string into a ShapeList.
Parameters
----------
region_string : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
rp = RegionParser()
ss = rp.parse(region_string)
sss1 = rp.conve... | python | def parse(region_string):
"""Parse DS9 region string into a ShapeList.
Parameters
----------
region_string : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
rp = RegionParser()
ss = rp.parse(region_string)
sss1 = rp.conve... | [
"def",
"parse",
"(",
"region_string",
")",
":",
"rp",
"=",
"RegionParser",
"(",
")",
"ss",
"=",
"rp",
".",
"parse",
"(",
"region_string",
")",
"sss1",
"=",
"rp",
".",
"convert_attr",
"(",
"ss",
")",
"sss2",
"=",
"_check_wcs",
"(",
"sss1",
")",
"shape... | Parse DS9 region string into a ShapeList.
Parameters
----------
region_string : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape` | [
"Parse",
"DS9",
"region",
"string",
"into",
"a",
"ShapeList",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L223-L242 | train | 60,744 |
astropy/pyregion | pyregion/core.py | open | def open(fname):
"""Open, read and parse DS9 region file.
Parameters
----------
fname : str
Filename
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
with _builtin_open(fname) as fh:
region_string = fh.read()
return parse(region_string) | python | def open(fname):
"""Open, read and parse DS9 region file.
Parameters
----------
fname : str
Filename
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
with _builtin_open(fname) as fh:
region_string = fh.read()
return parse(region_string) | [
"def",
"open",
"(",
"fname",
")",
":",
"with",
"_builtin_open",
"(",
"fname",
")",
"as",
"fh",
":",
"region_string",
"=",
"fh",
".",
"read",
"(",
")",
"return",
"parse",
"(",
"region_string",
")"
] | Open, read and parse DS9 region file.
Parameters
----------
fname : str
Filename
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape` | [
"Open",
"read",
"and",
"parse",
"DS9",
"region",
"file",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L245-L260 | train | 60,745 |
astropy/pyregion | pyregion/core.py | read_region | def read_region(s):
"""Read region.
Parameters
----------
s : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
rp = RegionParser()
ss = rp.parse(s)
sss1 = rp.convert_attr(ss)
sss2 = _check_wcs(sss1)
shape_list = r... | python | def read_region(s):
"""Read region.
Parameters
----------
s : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
rp = RegionParser()
ss = rp.parse(s)
sss1 = rp.convert_attr(ss)
sss2 = _check_wcs(sss1)
shape_list = r... | [
"def",
"read_region",
"(",
"s",
")",
":",
"rp",
"=",
"RegionParser",
"(",
")",
"ss",
"=",
"rp",
".",
"parse",
"(",
"s",
")",
"sss1",
"=",
"rp",
".",
"convert_attr",
"(",
"ss",
")",
"sss2",
"=",
"_check_wcs",
"(",
"sss1",
")",
"shape_list",
"=",
"... | Read region.
Parameters
----------
s : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape` | [
"Read",
"region",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L263-L282 | train | 60,746 |
astropy/pyregion | pyregion/core.py | read_region_as_imagecoord | def read_region_as_imagecoord(s, header):
"""Read region as image coordinates.
Parameters
----------
s : str
Region string
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shapes : `~pyregion.ShapeList`
List of `~pyregion.Shape`
"""
rp = Re... | python | def read_region_as_imagecoord(s, header):
"""Read region as image coordinates.
Parameters
----------
s : str
Region string
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shapes : `~pyregion.ShapeList`
List of `~pyregion.Shape`
"""
rp = Re... | [
"def",
"read_region_as_imagecoord",
"(",
"s",
",",
"header",
")",
":",
"rp",
"=",
"RegionParser",
"(",
")",
"ss",
"=",
"rp",
".",
"parse",
"(",
"s",
")",
"sss1",
"=",
"rp",
".",
"convert_attr",
"(",
"ss",
")",
"sss2",
"=",
"_check_wcs",
"(",
"sss1",
... | Read region as image coordinates.
Parameters
----------
s : str
Region string
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shapes : `~pyregion.ShapeList`
List of `~pyregion.Shape` | [
"Read",
"region",
"as",
"image",
"coordinates",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L285-L307 | train | 60,747 |
astropy/pyregion | pyregion/core.py | get_mask | def get_mask(region, hdu, origin=1):
"""Get mask.
Parameters
----------
region : `~pyregion.ShapeList`
List of `~pyregion.Shape`
hdu : `~astropy.io.fits.ImageHDU`
FITS image HDU
origin : float
TODO: document me
Returns
-------
mask : `~numpy.array`
B... | python | def get_mask(region, hdu, origin=1):
"""Get mask.
Parameters
----------
region : `~pyregion.ShapeList`
List of `~pyregion.Shape`
hdu : `~astropy.io.fits.ImageHDU`
FITS image HDU
origin : float
TODO: document me
Returns
-------
mask : `~numpy.array`
B... | [
"def",
"get_mask",
"(",
"region",
",",
"hdu",
",",
"origin",
"=",
"1",
")",
":",
"from",
"pyregion",
".",
"region_to_filter",
"import",
"as_region_filter",
"data",
"=",
"hdu",
".",
"data",
"region_filter",
"=",
"as_region_filter",
"(",
"region",
",",
"origin... | Get mask.
Parameters
----------
region : `~pyregion.ShapeList`
List of `~pyregion.Shape`
hdu : `~astropy.io.fits.ImageHDU`
FITS image HDU
origin : float
TODO: document me
Returns
-------
mask : `~numpy.array`
Boolean mask
Examples
--------
>... | [
"Get",
"mask",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L310-L341 | train | 60,748 |
astropy/pyregion | pyregion/core.py | ShapeList.as_imagecoord | def as_imagecoord(self, header):
"""New shape list in image coordinates.
Parameters
----------
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shape_list : `ShapeList`
New shape list, with coordinates of the each shape
... | python | def as_imagecoord(self, header):
"""New shape list in image coordinates.
Parameters
----------
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shape_list : `ShapeList`
New shape list, with coordinates of the each shape
... | [
"def",
"as_imagecoord",
"(",
"self",
",",
"header",
")",
":",
"comment_list",
"=",
"self",
".",
"_comment_list",
"if",
"comment_list",
"is",
"None",
":",
"comment_list",
"=",
"cycle",
"(",
"[",
"None",
"]",
")",
"r",
"=",
"RegionParser",
".",
"sky_to_image... | New shape list in image coordinates.
Parameters
----------
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shape_list : `ShapeList`
New shape list, with coordinates of the each shape
converted to the image coordinate us... | [
"New",
"shape",
"list",
"in",
"image",
"coordinates",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L48-L71 | train | 60,749 |
astropy/pyregion | pyregion/core.py | ShapeList.get_mask | def get_mask(self, hdu=None, header=None, shape=None):
"""Create a 2-d mask.
Parameters
----------
hdu : `astropy.io.fits.ImageHDU`
FITS image HDU
header : `~astropy.io.fits.Header`
FITS header
shape : tuple
Image shape
Return... | python | def get_mask(self, hdu=None, header=None, shape=None):
"""Create a 2-d mask.
Parameters
----------
hdu : `astropy.io.fits.ImageHDU`
FITS image HDU
header : `~astropy.io.fits.Header`
FITS header
shape : tuple
Image shape
Return... | [
"def",
"get_mask",
"(",
"self",
",",
"hdu",
"=",
"None",
",",
"header",
"=",
"None",
",",
"shape",
"=",
"None",
")",
":",
"if",
"hdu",
"and",
"header",
"is",
"None",
":",
"header",
"=",
"hdu",
".",
"header",
"if",
"hdu",
"and",
"shape",
"is",
"No... | Create a 2-d mask.
Parameters
----------
hdu : `astropy.io.fits.ImageHDU`
FITS image HDU
header : `~astropy.io.fits.Header`
FITS header
shape : tuple
Image shape
Returns
-------
mask : `numpy.array`
Boolean... | [
"Create",
"a",
"2",
"-",
"d",
"mask",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L126-L158 | train | 60,750 |
astropy/pyregion | pyregion/core.py | ShapeList.write | def write(self, outfile):
"""Write this shape list to a region file.
Parameters
----------
outfile : str
File name
"""
if len(self) < 1:
print("WARNING: The region list is empty. The region file "
"'{:s}' will be empty.".format(o... | python | def write(self, outfile):
"""Write this shape list to a region file.
Parameters
----------
outfile : str
File name
"""
if len(self) < 1:
print("WARNING: The region list is empty. The region file "
"'{:s}' will be empty.".format(o... | [
"def",
"write",
"(",
"self",
",",
"outfile",
")",
":",
"if",
"len",
"(",
"self",
")",
"<",
"1",
":",
"print",
"(",
"\"WARNING: The region list is empty. The region file \"",
"\"'{:s}' will be empty.\"",
".",
"format",
"(",
"outfile",
")",
")",
"try",
":",
"out... | Write this shape list to a region file.
Parameters
----------
outfile : str
File name | [
"Write",
"this",
"shape",
"list",
"to",
"a",
"region",
"file",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L160-L220 | train | 60,751 |
trustrachel/Flask-FeatureFlags | flask_featureflags/__init__.py | AppConfigFlagHandler | def AppConfigFlagHandler(feature=None):
""" This is the default handler. It checks for feature flags in the current app's configuration.
For example, to have 'unfinished_feature' hidden in production but active in development:
config.py
class ProductionConfig(Config):
FEATURE_FLAGS = {
'unfinished... | python | def AppConfigFlagHandler(feature=None):
""" This is the default handler. It checks for feature flags in the current app's configuration.
For example, to have 'unfinished_feature' hidden in production but active in development:
config.py
class ProductionConfig(Config):
FEATURE_FLAGS = {
'unfinished... | [
"def",
"AppConfigFlagHandler",
"(",
"feature",
"=",
"None",
")",
":",
"if",
"not",
"current_app",
":",
"log",
".",
"warn",
"(",
"u\"Got a request to check for {feature} but we're outside the request context. Returning False\"",
".",
"format",
"(",
"feature",
"=",
"feature... | This is the default handler. It checks for feature flags in the current app's configuration.
For example, to have 'unfinished_feature' hidden in production but active in development:
config.py
class ProductionConfig(Config):
FEATURE_FLAGS = {
'unfinished_feature' : False,
}
class Development... | [
"This",
"is",
"the",
"default",
"handler",
".",
"It",
"checks",
"for",
"feature",
"flags",
"in",
"the",
"current",
"app",
"s",
"configuration",
"."
] | bf32d07c8ce72adc009619ef04e666c51736f80c | https://github.com/trustrachel/Flask-FeatureFlags/blob/bf32d07c8ce72adc009619ef04e666c51736f80c/flask_featureflags/__init__.py#L48-L76 | train | 60,752 |
trustrachel/Flask-FeatureFlags | flask_featureflags/__init__.py | is_active | def is_active(feature):
""" Check if a feature is active """
if current_app:
feature_flagger = current_app.extensions.get(EXTENSION_NAME)
if feature_flagger:
return feature_flagger.check(feature)
else:
raise AssertionError("Oops. This application doesn't have the Flask-FeatureFlag extention... | python | def is_active(feature):
""" Check if a feature is active """
if current_app:
feature_flagger = current_app.extensions.get(EXTENSION_NAME)
if feature_flagger:
return feature_flagger.check(feature)
else:
raise AssertionError("Oops. This application doesn't have the Flask-FeatureFlag extention... | [
"def",
"is_active",
"(",
"feature",
")",
":",
"if",
"current_app",
":",
"feature_flagger",
"=",
"current_app",
".",
"extensions",
".",
"get",
"(",
"EXTENSION_NAME",
")",
"if",
"feature_flagger",
":",
"return",
"feature_flagger",
".",
"check",
"(",
"feature",
"... | Check if a feature is active | [
"Check",
"if",
"a",
"feature",
"is",
"active"
] | bf32d07c8ce72adc009619ef04e666c51736f80c | https://github.com/trustrachel/Flask-FeatureFlags/blob/bf32d07c8ce72adc009619ef04e666c51736f80c/flask_featureflags/__init__.py#L150-L162 | train | 60,753 |
trustrachel/Flask-FeatureFlags | flask_featureflags/__init__.py | is_active_feature | def is_active_feature(feature, redirect_to=None, redirect=None):
"""
Decorator for Flask views. If a feature is off, it can either return a 404 or redirect to a URL if you'd rather.
"""
def _is_active_feature(func):
@wraps(func)
def wrapped(*args, **kwargs):
if not is_active(feature):
url... | python | def is_active_feature(feature, redirect_to=None, redirect=None):
"""
Decorator for Flask views. If a feature is off, it can either return a 404 or redirect to a URL if you'd rather.
"""
def _is_active_feature(func):
@wraps(func)
def wrapped(*args, **kwargs):
if not is_active(feature):
url... | [
"def",
"is_active_feature",
"(",
"feature",
",",
"redirect_to",
"=",
"None",
",",
"redirect",
"=",
"None",
")",
":",
"def",
"_is_active_feature",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
... | Decorator for Flask views. If a feature is off, it can either return a 404 or redirect to a URL if you'd rather. | [
"Decorator",
"for",
"Flask",
"views",
".",
"If",
"a",
"feature",
"is",
"off",
"it",
"can",
"either",
"return",
"a",
"404",
"or",
"redirect",
"to",
"a",
"URL",
"if",
"you",
"d",
"rather",
"."
] | bf32d07c8ce72adc009619ef04e666c51736f80c | https://github.com/trustrachel/Flask-FeatureFlags/blob/bf32d07c8ce72adc009619ef04e666c51736f80c/flask_featureflags/__init__.py#L165-L187 | train | 60,754 |
trustrachel/Flask-FeatureFlags | flask_featureflags/__init__.py | FeatureFlag.init_app | def init_app(self, app):
""" Add ourselves into the app config and setup, and add a jinja function test """
app.config.setdefault(FEATURE_FLAGS_CONFIG, {})
app.config.setdefault(RAISE_ERROR_ON_MISSING_FEATURES, False)
if hasattr(app, "add_template_test"):
# flask 0.10 and higher has a proper hoo... | python | def init_app(self, app):
""" Add ourselves into the app config and setup, and add a jinja function test """
app.config.setdefault(FEATURE_FLAGS_CONFIG, {})
app.config.setdefault(RAISE_ERROR_ON_MISSING_FEATURES, False)
if hasattr(app, "add_template_test"):
# flask 0.10 and higher has a proper hoo... | [
"def",
"init_app",
"(",
"self",
",",
"app",
")",
":",
"app",
".",
"config",
".",
"setdefault",
"(",
"FEATURE_FLAGS_CONFIG",
",",
"{",
"}",
")",
"app",
".",
"config",
".",
"setdefault",
"(",
"RAISE_ERROR_ON_MISSING_FEATURES",
",",
"False",
")",
"if",
"hasat... | Add ourselves into the app config and setup, and add a jinja function test | [
"Add",
"ourselves",
"into",
"the",
"app",
"config",
"and",
"setup",
"and",
"add",
"a",
"jinja",
"function",
"test"
] | bf32d07c8ce72adc009619ef04e666c51736f80c | https://github.com/trustrachel/Flask-FeatureFlags/blob/bf32d07c8ce72adc009619ef04e666c51736f80c/flask_featureflags/__init__.py#L90-L104 | train | 60,755 |
trustrachel/Flask-FeatureFlags | flask_featureflags/__init__.py | FeatureFlag.check | def check(self, feature):
""" Loop through all our feature flag checkers and return true if any of them are true.
The order of handlers matters - we will immediately return True if any handler returns true.
If you want to a handler to return False and stop the chain, raise the StopCheckingFeatureFlags exc... | python | def check(self, feature):
""" Loop through all our feature flag checkers and return true if any of them are true.
The order of handlers matters - we will immediately return True if any handler returns true.
If you want to a handler to return False and stop the chain, raise the StopCheckingFeatureFlags exc... | [
"def",
"check",
"(",
"self",
",",
"feature",
")",
":",
"found",
"=",
"False",
"for",
"handler",
"in",
"self",
".",
"handlers",
":",
"try",
":",
"if",
"handler",
"(",
"feature",
")",
":",
"return",
"True",
"except",
"StopCheckingFeatureFlags",
":",
"retur... | Loop through all our feature flag checkers and return true if any of them are true.
The order of handlers matters - we will immediately return True if any handler returns true.
If you want to a handler to return False and stop the chain, raise the StopCheckingFeatureFlags exception. | [
"Loop",
"through",
"all",
"our",
"feature",
"flag",
"checkers",
"and",
"return",
"true",
"if",
"any",
"of",
"them",
"are",
"true",
"."
] | bf32d07c8ce72adc009619ef04e666c51736f80c | https://github.com/trustrachel/Flask-FeatureFlags/blob/bf32d07c8ce72adc009619ef04e666c51736f80c/flask_featureflags/__init__.py#L121-L147 | train | 60,756 |
havardgulldahl/jottalib | src/jottalib/contrib/mwt.py | Memoize.yank_path | def yank_path(self, path):
"""Clear cache of results from a specific path"""
for func in self._caches:
cache = {}
for key in self._caches[func].keys():
log.debug("cache key %s for func %s", key, func)
if path in key[0]:
log.debu... | python | def yank_path(self, path):
"""Clear cache of results from a specific path"""
for func in self._caches:
cache = {}
for key in self._caches[func].keys():
log.debug("cache key %s for func %s", key, func)
if path in key[0]:
log.debu... | [
"def",
"yank_path",
"(",
"self",
",",
"path",
")",
":",
"for",
"func",
"in",
"self",
".",
"_caches",
":",
"cache",
"=",
"{",
"}",
"for",
"key",
"in",
"self",
".",
"_caches",
"[",
"func",
"]",
".",
"keys",
"(",
")",
":",
"log",
".",
"debug",
"("... | Clear cache of results from a specific path | [
"Clear",
"cache",
"of",
"results",
"from",
"a",
"specific",
"path"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/contrib/mwt.py#L87-L95 | train | 60,757 |
havardgulldahl/jottalib | src/jottalib/jottafuse.py | JottaFuse.release | def release(self, path, fh):
"Run after a read or write operation has finished. This is where we upload on writes"
#print "release! inpath:", path in self.__newfiles.keys()
# if the path exists in self.__newfiles.keys(), we have a new version to upload
try:
f = self.__newfile... | python | def release(self, path, fh):
"Run after a read or write operation has finished. This is where we upload on writes"
#print "release! inpath:", path in self.__newfiles.keys()
# if the path exists in self.__newfiles.keys(), we have a new version to upload
try:
f = self.__newfile... | [
"def",
"release",
"(",
"self",
",",
"path",
",",
"fh",
")",
":",
"#print \"release! inpath:\", path in self.__newfiles.keys()",
"# if the path exists in self.__newfiles.keys(), we have a new version to upload",
"try",
":",
"f",
"=",
"self",
".",
"__newfiles",
"[",
"path",
"... | Run after a read or write operation has finished. This is where we upload on writes | [
"Run",
"after",
"a",
"read",
"or",
"write",
"operation",
"has",
"finished",
".",
"This",
"is",
"where",
"we",
"upload",
"on",
"writes"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottafuse.py#L246-L260 | train | 60,758 |
havardgulldahl/jottalib | src/jottalib/jottafuse.py | JottaFuse.truncate | def truncate(self, path, length, fh=None):
"Download existing path, truncate and reupload"
try:
f = self._getpath(path)
except JFS.JFSError:
raise OSError(errno.ENOENT, '')
if isinstance(f, (JFS.JFSFile, JFS.JFSFolder)) and f.is_deleted():
raise OSErro... | python | def truncate(self, path, length, fh=None):
"Download existing path, truncate and reupload"
try:
f = self._getpath(path)
except JFS.JFSError:
raise OSError(errno.ENOENT, '')
if isinstance(f, (JFS.JFSFile, JFS.JFSFolder)) and f.is_deleted():
raise OSErro... | [
"def",
"truncate",
"(",
"self",
",",
"path",
",",
"length",
",",
"fh",
"=",
"None",
")",
":",
"try",
":",
"f",
"=",
"self",
".",
"_getpath",
"(",
"path",
")",
"except",
"JFS",
".",
"JFSError",
":",
"raise",
"OSError",
"(",
"errno",
".",
"ENOENT",
... | Download existing path, truncate and reupload | [
"Download",
"existing",
"path",
"truncate",
"and",
"reupload"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottafuse.py#L330-L345 | train | 60,759 |
havardgulldahl/jottalib | src/jottalib/cli.py | commandline_text | def commandline_text(bytestring):
'Convert bytestring from command line to unicode, using default file system encoding'
if six.PY3:
return bytestring
unicode_string = bytestring.decode(sys.getfilesystemencoding())
return unicode_string | python | def commandline_text(bytestring):
'Convert bytestring from command line to unicode, using default file system encoding'
if six.PY3:
return bytestring
unicode_string = bytestring.decode(sys.getfilesystemencoding())
return unicode_string | [
"def",
"commandline_text",
"(",
"bytestring",
")",
":",
"if",
"six",
".",
"PY3",
":",
"return",
"bytestring",
"unicode_string",
"=",
"bytestring",
".",
"decode",
"(",
"sys",
".",
"getfilesystemencoding",
"(",
")",
")",
"return",
"unicode_string"
] | Convert bytestring from command line to unicode, using default file system encoding | [
"Convert",
"bytestring",
"from",
"command",
"line",
"to",
"unicode",
"using",
"default",
"file",
"system",
"encoding"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/cli.py#L98-L103 | train | 60,760 |
astropy/pyregion | pyregion/ds9_region_parser.py | RegionParser.sky_to_image | def sky_to_image(shape_list, header):
"""Converts a `ShapeList` into shapes with coordinates in image coordinates
Parameters
----------
shape_list : `pyregion.ShapeList`
The ShapeList to convert
header : `~astropy.io.fits.Header`
Specifies what WCS transf... | python | def sky_to_image(shape_list, header):
"""Converts a `ShapeList` into shapes with coordinates in image coordinates
Parameters
----------
shape_list : `pyregion.ShapeList`
The ShapeList to convert
header : `~astropy.io.fits.Header`
Specifies what WCS transf... | [
"def",
"sky_to_image",
"(",
"shape_list",
",",
"header",
")",
":",
"for",
"shape",
",",
"comment",
"in",
"shape_list",
":",
"if",
"isinstance",
"(",
"shape",
",",
"Shape",
")",
"and",
"(",
"shape",
".",
"coord_format",
"not",
"in",
"image_like_coordformats",... | Converts a `ShapeList` into shapes with coordinates in image coordinates
Parameters
----------
shape_list : `pyregion.ShapeList`
The ShapeList to convert
header : `~astropy.io.fits.Header`
Specifies what WCS transformations to use.
Yields
-------... | [
"Converts",
"a",
"ShapeList",
"into",
"shapes",
"with",
"coordinates",
"in",
"image",
"coordinates"
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/ds9_region_parser.py#L162-L209 | train | 60,761 |
havardgulldahl/jottalib | src/jottalib/monitor.py | ArchiveEventHandler._new | def _new(self, src_path, dry_run=False, remove_uploaded=False):
'Code to upload'
# are we getting a symbolic link?
if os.path.islink(src_path):
sourcefile = os.path.normpath(os.path.join(self.topdir, os.readlink(src_path)))
if not os.path.exists(source... | python | def _new(self, src_path, dry_run=False, remove_uploaded=False):
'Code to upload'
# are we getting a symbolic link?
if os.path.islink(src_path):
sourcefile = os.path.normpath(os.path.join(self.topdir, os.readlink(src_path)))
if not os.path.exists(source... | [
"def",
"_new",
"(",
"self",
",",
"src_path",
",",
"dry_run",
"=",
"False",
",",
"remove_uploaded",
"=",
"False",
")",
":",
"# are we getting a symbolic link?",
"if",
"os",
".",
"path",
".",
"islink",
"(",
"src_path",
")",
":",
"sourcefile",
"=",
"os",
".",... | Code to upload | [
"Code",
"to",
"upload"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/monitor.py#L126-L157 | train | 60,762 |
astropy/pyregion | pyregion/wcs_helper.py | _estimate_angle | def _estimate_angle(angle, reg_coordinate_frame, header):
"""Transform an angle into a different frame
Parameters
----------
angle : float, int
The number of degrees, measured from the Y axis in origin's frame
reg_coordinate_frame : str
Coordinate frame in which ``angle`` is define... | python | def _estimate_angle(angle, reg_coordinate_frame, header):
"""Transform an angle into a different frame
Parameters
----------
angle : float, int
The number of degrees, measured from the Y axis in origin's frame
reg_coordinate_frame : str
Coordinate frame in which ``angle`` is define... | [
"def",
"_estimate_angle",
"(",
"angle",
",",
"reg_coordinate_frame",
",",
"header",
")",
":",
"y_axis_rot",
"=",
"_calculate_rotation_angle",
"(",
"reg_coordinate_frame",
",",
"header",
")",
"return",
"angle",
"-",
"y_axis_rot"
] | Transform an angle into a different frame
Parameters
----------
angle : float, int
The number of degrees, measured from the Y axis in origin's frame
reg_coordinate_frame : str
Coordinate frame in which ``angle`` is defined
header : `~astropy.io.fits.Header` instance
Header... | [
"Transform",
"an",
"angle",
"into",
"a",
"different",
"frame"
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/wcs_helper.py#L7-L27 | train | 60,763 |
astropy/pyregion | pyregion/wcs_helper.py | _calculate_rotation_angle | def _calculate_rotation_angle(reg_coordinate_frame, header):
"""Calculates the rotation angle from the region to the header's frame
This attempts to be compatible with the implementation used by SAOImage
DS9. In particular, this measures the rotation of the north axis as
measured at the center of the i... | python | def _calculate_rotation_angle(reg_coordinate_frame, header):
"""Calculates the rotation angle from the region to the header's frame
This attempts to be compatible with the implementation used by SAOImage
DS9. In particular, this measures the rotation of the north axis as
measured at the center of the i... | [
"def",
"_calculate_rotation_angle",
"(",
"reg_coordinate_frame",
",",
"header",
")",
":",
"new_wcs",
"=",
"WCS",
"(",
"header",
")",
"region_frame",
"=",
"SkyCoord",
"(",
"'0d 0d'",
",",
"frame",
"=",
"reg_coordinate_frame",
",",
"obstime",
"=",
"'J2000'",
")",
... | Calculates the rotation angle from the region to the header's frame
This attempts to be compatible with the implementation used by SAOImage
DS9. In particular, this measures the rotation of the north axis as
measured at the center of the image, and therefore requires a
`~astropy.io.fits.Header` object ... | [
"Calculates",
"the",
"rotation",
"angle",
"from",
"the",
"region",
"to",
"the",
"header",
"s",
"frame"
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/wcs_helper.py#L30-L89 | train | 60,764 |
havardgulldahl/jottalib | src/jottalib/jottacloud.py | sf | def sf(f, dirpath, jottapath):
"""Create and return a SyncFile tuple from filename.
localpath will be a byte string with utf8 code points
jottapath will be a unicode string"""
log.debug('Create SyncFile from %s', repr(f))
log.debug('Got encoded filename %r, joining with dirpath %r',... | python | def sf(f, dirpath, jottapath):
"""Create and return a SyncFile tuple from filename.
localpath will be a byte string with utf8 code points
jottapath will be a unicode string"""
log.debug('Create SyncFile from %s', repr(f))
log.debug('Got encoded filename %r, joining with dirpath %r',... | [
"def",
"sf",
"(",
"f",
",",
"dirpath",
",",
"jottapath",
")",
":",
"log",
".",
"debug",
"(",
"'Create SyncFile from %s'",
",",
"repr",
"(",
"f",
")",
")",
"log",
".",
"debug",
"(",
"'Got encoded filename %r, joining with dirpath %r'",
",",
"_encode_filename_to_f... | Create and return a SyncFile tuple from filename.
localpath will be a byte string with utf8 code points
jottapath will be a unicode string | [
"Create",
"and",
"return",
"a",
"SyncFile",
"tuple",
"from",
"filename",
"."
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L44-L52 | train | 60,765 |
havardgulldahl/jottalib | src/jottalib/jottacloud.py | get_jottapath | def get_jottapath(localtopdir, dirpath, jottamountpoint):
"""Translate localtopdir to jottapath. Returns unicode string"""
log.debug("get_jottapath %r %r %r", localtopdir, dirpath, jottamountpoint)
normpath = posixpath.normpath(posixpath.join(jottamountpoint, posixpath.basename(localtopdir),
... | python | def get_jottapath(localtopdir, dirpath, jottamountpoint):
"""Translate localtopdir to jottapath. Returns unicode string"""
log.debug("get_jottapath %r %r %r", localtopdir, dirpath, jottamountpoint)
normpath = posixpath.normpath(posixpath.join(jottamountpoint, posixpath.basename(localtopdir),
... | [
"def",
"get_jottapath",
"(",
"localtopdir",
",",
"dirpath",
",",
"jottamountpoint",
")",
":",
"log",
".",
"debug",
"(",
"\"get_jottapath %r %r %r\"",
",",
"localtopdir",
",",
"dirpath",
",",
"jottamountpoint",
")",
"normpath",
"=",
"posixpath",
".",
"normpath",
... | Translate localtopdir to jottapath. Returns unicode string | [
"Translate",
"localtopdir",
"to",
"jottapath",
".",
"Returns",
"unicode",
"string"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L55-L60 | train | 60,766 |
havardgulldahl/jottalib | src/jottalib/jottacloud.py | is_file | def is_file(jottapath, JFS):
"""Check if a file exists on jottacloud"""
log.debug("is_file %r", jottapath)
try:
jf = JFS.getObject(jottapath)
except JFSNotFoundError:
return False
return isinstance(jf, JFSFile) | python | def is_file(jottapath, JFS):
"""Check if a file exists on jottacloud"""
log.debug("is_file %r", jottapath)
try:
jf = JFS.getObject(jottapath)
except JFSNotFoundError:
return False
return isinstance(jf, JFSFile) | [
"def",
"is_file",
"(",
"jottapath",
",",
"JFS",
")",
":",
"log",
".",
"debug",
"(",
"\"is_file %r\"",
",",
"jottapath",
")",
"try",
":",
"jf",
"=",
"JFS",
".",
"getObject",
"(",
"jottapath",
")",
"except",
"JFSNotFoundError",
":",
"return",
"False",
"ret... | Check if a file exists on jottacloud | [
"Check",
"if",
"a",
"file",
"exists",
"on",
"jottacloud"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L63-L70 | train | 60,767 |
havardgulldahl/jottalib | src/jottalib/jottacloud.py | compare | def compare(localtopdir, jottamountpoint, JFS, followlinks=False, exclude_patterns=None):
"""Make a tree of local files and folders and compare it with what's currently on JottaCloud.
For each folder, yields:
dirpath, # byte string, full path
onlylocal, # set(), files that only exist locally, i... | python | def compare(localtopdir, jottamountpoint, JFS, followlinks=False, exclude_patterns=None):
"""Make a tree of local files and folders and compare it with what's currently on JottaCloud.
For each folder, yields:
dirpath, # byte string, full path
onlylocal, # set(), files that only exist locally, i... | [
"def",
"compare",
"(",
"localtopdir",
",",
"jottamountpoint",
",",
"JFS",
",",
"followlinks",
"=",
"False",
",",
"exclude_patterns",
"=",
"None",
")",
":",
"def",
"excluded",
"(",
"unicodepath",
",",
"fname",
")",
":",
"fpath",
"=",
"os",
".",
"path",
".... | Make a tree of local files and folders and compare it with what's currently on JottaCloud.
For each folder, yields:
dirpath, # byte string, full path
onlylocal, # set(), files that only exist locally, i.e. newly added files that don't exist online,
onlyremote, # set(), files that only exist... | [
"Make",
"a",
"tree",
"of",
"local",
"files",
"and",
"folders",
"and",
"compare",
"it",
"with",
"what",
"s",
"currently",
"on",
"JottaCloud",
"."
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L94-L147 | train | 60,768 |
havardgulldahl/jottalib | src/jottalib/jottacloud.py | _decode_filename_to_unicode | def _decode_filename_to_unicode(f):
'''Get bytestring filename and return unicode.
First, try to decode from default file system encoding
If that fails, use ``chardet`` module to guess encoding.
As a last resort, try to decode as utf-8.
If the argument already is unicode, return as is'''
log.d... | python | def _decode_filename_to_unicode(f):
'''Get bytestring filename and return unicode.
First, try to decode from default file system encoding
If that fails, use ``chardet`` module to guess encoding.
As a last resort, try to decode as utf-8.
If the argument already is unicode, return as is'''
log.d... | [
"def",
"_decode_filename_to_unicode",
"(",
"f",
")",
":",
"log",
".",
"debug",
"(",
"'_decode_filename_to_unicode(%s)'",
",",
"repr",
"(",
"f",
")",
")",
"if",
"isinstance",
"(",
"f",
",",
"unicode",
")",
":",
"return",
"f",
"try",
":",
"return",
"f",
".... | Get bytestring filename and return unicode.
First, try to decode from default file system encoding
If that fails, use ``chardet`` module to guess encoding.
As a last resort, try to decode as utf-8.
If the argument already is unicode, return as is | [
"Get",
"bytestring",
"filename",
"and",
"return",
"unicode",
".",
"First",
"try",
"to",
"decode",
"from",
"default",
"file",
"system",
"encoding",
"If",
"that",
"fails",
"use",
"chardet",
"module",
"to",
"guess",
"encoding",
".",
"As",
"a",
"last",
"resort",... | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L150-L183 | train | 60,769 |
havardgulldahl/jottalib | src/jottalib/jottacloud.py | _encode_filename_to_filesystem | def _encode_filename_to_filesystem(f):
'''Get a unicode filename and return bytestring, encoded to file system default.
If the argument already is a bytestring, return as is'''
log.debug('_encode_filename_to_filesystem(%s)', repr(f))
if isinstance(f, str):
return f
try:
return f.enc... | python | def _encode_filename_to_filesystem(f):
'''Get a unicode filename and return bytestring, encoded to file system default.
If the argument already is a bytestring, return as is'''
log.debug('_encode_filename_to_filesystem(%s)', repr(f))
if isinstance(f, str):
return f
try:
return f.enc... | [
"def",
"_encode_filename_to_filesystem",
"(",
"f",
")",
":",
"log",
".",
"debug",
"(",
"'_encode_filename_to_filesystem(%s)'",
",",
"repr",
"(",
"f",
")",
")",
"if",
"isinstance",
"(",
"f",
",",
"str",
")",
":",
"return",
"f",
"try",
":",
"return",
"f",
... | Get a unicode filename and return bytestring, encoded to file system default.
If the argument already is a bytestring, return as is | [
"Get",
"a",
"unicode",
"filename",
"and",
"return",
"bytestring",
"encoded",
"to",
"file",
"system",
"default",
"."
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L186-L196 | train | 60,770 |
havardgulldahl/jottalib | src/jottalib/jottacloud.py | resume | def resume(localfile, jottafile, JFS):
"""Continue uploading a new file from local file (already exists on JottaCloud"""
with open(localfile) as lf:
_complete = jottafile.resume(lf)
return _complete | python | def resume(localfile, jottafile, JFS):
"""Continue uploading a new file from local file (already exists on JottaCloud"""
with open(localfile) as lf:
_complete = jottafile.resume(lf)
return _complete | [
"def",
"resume",
"(",
"localfile",
",",
"jottafile",
",",
"JFS",
")",
":",
"with",
"open",
"(",
"localfile",
")",
"as",
"lf",
":",
"_complete",
"=",
"jottafile",
".",
"resume",
"(",
"lf",
")",
"return",
"_complete"
] | Continue uploading a new file from local file (already exists on JottaCloud | [
"Continue",
"uploading",
"a",
"new",
"file",
"from",
"local",
"file",
"(",
"already",
"exists",
"on",
"JottaCloud"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L206-L210 | train | 60,771 |
havardgulldahl/jottalib | src/jottalib/jottacloud.py | replace_if_changed | def replace_if_changed(localfile, jottapath, JFS):
"""Compare md5 hash to determine if contents have changed.
Upload a file from local disk and replace file on JottaCloud if the md5s differ,
or continue uploading if the file is incompletely uploaded.
Returns the JottaFile object"""
jf = JFS.getObje... | python | def replace_if_changed(localfile, jottapath, JFS):
"""Compare md5 hash to determine if contents have changed.
Upload a file from local disk and replace file on JottaCloud if the md5s differ,
or continue uploading if the file is incompletely uploaded.
Returns the JottaFile object"""
jf = JFS.getObje... | [
"def",
"replace_if_changed",
"(",
"localfile",
",",
"jottapath",
",",
"JFS",
")",
":",
"jf",
"=",
"JFS",
".",
"getObject",
"(",
"jottapath",
")",
"lf_hash",
"=",
"getxattrhash",
"(",
"localfile",
")",
"# try to read previous hash, stored in xattr",
"if",
"lf_hash"... | Compare md5 hash to determine if contents have changed.
Upload a file from local disk and replace file on JottaCloud if the md5s differ,
or continue uploading if the file is incompletely uploaded.
Returns the JottaFile object | [
"Compare",
"md5",
"hash",
"to",
"determine",
"if",
"contents",
"have",
"changed",
".",
"Upload",
"a",
"file",
"from",
"local",
"disk",
"and",
"replace",
"file",
"on",
"JottaCloud",
"if",
"the",
"md5s",
"differ",
"or",
"continue",
"uploading",
"if",
"the",
... | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L212-L232 | train | 60,772 |
havardgulldahl/jottalib | src/jottalib/jottacloud.py | iter_tree | def iter_tree(jottapath, JFS):
"""Get a tree of of files and folders. use as an iterator, you get something like os.walk"""
filedirlist = JFS.getObject('%s?mode=list' % jottapath)
log.debug("got tree: %s", filedirlist)
if not isinstance(filedirlist, JFSFileDirList):
yield ( '', tuple(), tuple() ... | python | def iter_tree(jottapath, JFS):
"""Get a tree of of files and folders. use as an iterator, you get something like os.walk"""
filedirlist = JFS.getObject('%s?mode=list' % jottapath)
log.debug("got tree: %s", filedirlist)
if not isinstance(filedirlist, JFSFileDirList):
yield ( '', tuple(), tuple() ... | [
"def",
"iter_tree",
"(",
"jottapath",
",",
"JFS",
")",
":",
"filedirlist",
"=",
"JFS",
".",
"getObject",
"(",
"'%s?mode=list'",
"%",
"jottapath",
")",
"log",
".",
"debug",
"(",
"\"got tree: %s\"",
",",
"filedirlist",
")",
"if",
"not",
"isinstance",
"(",
"f... | Get a tree of of files and folders. use as an iterator, you get something like os.walk | [
"Get",
"a",
"tree",
"of",
"of",
"files",
"and",
"folders",
".",
"use",
"as",
"an",
"iterator",
"you",
"get",
"something",
"like",
"os",
".",
"walk"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L252-L259 | train | 60,773 |
havardgulldahl/jottalib | src/duplicity-backend.py | JottaCloudBackend._query | def _query(self, filename):
"""Get size of filename"""
# - Query metadata of one file
# - Return a dict with a 'size' key, and a file size value (-1 for not found)
# - Retried if an exception is thrown
log.Info('Querying size of %s' % filename)
from jottalib.JFS import... | python | def _query(self, filename):
"""Get size of filename"""
# - Query metadata of one file
# - Return a dict with a 'size' key, and a file size value (-1 for not found)
# - Retried if an exception is thrown
log.Info('Querying size of %s' % filename)
from jottalib.JFS import... | [
"def",
"_query",
"(",
"self",
",",
"filename",
")",
":",
"# - Query metadata of one file",
"# - Return a dict with a 'size' key, and a file size value (-1 for not found)",
"# - Retried if an exception is thrown",
"log",
".",
"Info",
"(",
"'Querying size of %s'",
"%",
"filename",... | Get size of filename | [
"Get",
"size",
"of",
"filename"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/duplicity-backend.py#L141-L155 | train | 60,774 |
booktype/python-ooxml | ooxml/parse.py | parse_drawing | def parse_drawing(document, container, elem):
"""Parse drawing element.
We don't do much with drawing element. We can find embeded image but we don't do more than that.
"""
_blip = elem.xpath('.//a:blip', namespaces=NAMESPACES)
if len(_blip) > 0:
blip = _blip[0]
_rid = blip.attrib... | python | def parse_drawing(document, container, elem):
"""Parse drawing element.
We don't do much with drawing element. We can find embeded image but we don't do more than that.
"""
_blip = elem.xpath('.//a:blip', namespaces=NAMESPACES)
if len(_blip) > 0:
blip = _blip[0]
_rid = blip.attrib... | [
"def",
"parse_drawing",
"(",
"document",
",",
"container",
",",
"elem",
")",
":",
"_blip",
"=",
"elem",
".",
"xpath",
"(",
"'.//a:blip'",
",",
"namespaces",
"=",
"NAMESPACES",
")",
"if",
"len",
"(",
"_blip",
")",
">",
"0",
":",
"blip",
"=",
"_blip",
... | Parse drawing element.
We don't do much with drawing element. We can find embeded image but we don't do more than that. | [
"Parse",
"drawing",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L177-L190 | train | 60,775 |
booktype/python-ooxml | ooxml/parse.py | parse_footnote | def parse_footnote(document, container, elem):
"Parse the footnote element."
_rid = elem.attrib[_name('{{{w}}}id')]
foot = doc.Footnote(_rid)
container.elements.append(foot) | python | def parse_footnote(document, container, elem):
"Parse the footnote element."
_rid = elem.attrib[_name('{{{w}}}id')]
foot = doc.Footnote(_rid)
container.elements.append(foot) | [
"def",
"parse_footnote",
"(",
"document",
",",
"container",
",",
"elem",
")",
":",
"_rid",
"=",
"elem",
".",
"attrib",
"[",
"_name",
"(",
"'{{{w}}}id'",
")",
"]",
"foot",
"=",
"doc",
".",
"Footnote",
"(",
"_rid",
")",
"container",
".",
"elements",
".",... | Parse the footnote element. | [
"Parse",
"the",
"footnote",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L193-L198 | train | 60,776 |
booktype/python-ooxml | ooxml/parse.py | parse_text | def parse_text(document, container, element):
"Parse text element."
txt = None
alternate = element.find(_name('{{{mc}}}AlternateContent'))
if alternate is not None:
parse_alternate(document, container, alternate)
br = element.find(_name('{{{w}}}br'))
if br is not None:
if _n... | python | def parse_text(document, container, element):
"Parse text element."
txt = None
alternate = element.find(_name('{{{mc}}}AlternateContent'))
if alternate is not None:
parse_alternate(document, container, alternate)
br = element.find(_name('{{{w}}}br'))
if br is not None:
if _n... | [
"def",
"parse_text",
"(",
"document",
",",
"container",
",",
"element",
")",
":",
"txt",
"=",
"None",
"alternate",
"=",
"element",
".",
"find",
"(",
"_name",
"(",
"'{{{mc}}}AlternateContent'",
")",
")",
"if",
"alternate",
"is",
"not",
"None",
":",
"parse_a... | Parse text element. | [
"Parse",
"text",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L224-L291 | train | 60,777 |
booktype/python-ooxml | ooxml/parse.py | parse_paragraph | def parse_paragraph(document, par):
"""Parse paragraph element.
Some other elements could be found inside of paragraph element (math, links).
"""
paragraph = doc.Paragraph()
paragraph.document = document
for elem in par:
if elem.tag == _name('{{{w}}}pPr'):
parse_paragraph_... | python | def parse_paragraph(document, par):
"""Parse paragraph element.
Some other elements could be found inside of paragraph element (math, links).
"""
paragraph = doc.Paragraph()
paragraph.document = document
for elem in par:
if elem.tag == _name('{{{w}}}pPr'):
parse_paragraph_... | [
"def",
"parse_paragraph",
"(",
"document",
",",
"par",
")",
":",
"paragraph",
"=",
"doc",
".",
"Paragraph",
"(",
")",
"paragraph",
".",
"document",
"=",
"document",
"for",
"elem",
"in",
"par",
":",
"if",
"elem",
".",
"tag",
"==",
"_name",
"(",
"'{{{w}}... | Parse paragraph element.
Some other elements could be found inside of paragraph element (math, links). | [
"Parse",
"paragraph",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L313-L358 | train | 60,778 |
booktype/python-ooxml | ooxml/parse.py | parse_table_properties | def parse_table_properties(doc, table, prop):
"Parse table properties."
if not table:
return
style = prop.find(_name('{{{w}}}tblStyle'))
if style is not None:
table.style_id = style.attrib[_name('{{{w}}}val')]
doc.add_style_as_used(table.style_id) | python | def parse_table_properties(doc, table, prop):
"Parse table properties."
if not table:
return
style = prop.find(_name('{{{w}}}tblStyle'))
if style is not None:
table.style_id = style.attrib[_name('{{{w}}}val')]
doc.add_style_as_used(table.style_id) | [
"def",
"parse_table_properties",
"(",
"doc",
",",
"table",
",",
"prop",
")",
":",
"if",
"not",
"table",
":",
"return",
"style",
"=",
"prop",
".",
"find",
"(",
"_name",
"(",
"'{{{w}}}tblStyle'",
")",
")",
"if",
"style",
"is",
"not",
"None",
":",
"table"... | Parse table properties. | [
"Parse",
"table",
"properties",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L361-L371 | train | 60,779 |
booktype/python-ooxml | ooxml/parse.py | parse_table_column_properties | def parse_table_column_properties(doc, cell, prop):
"Parse table column properties."
if not cell:
return
grid = prop.find(_name('{{{w}}}gridSpan'))
if grid is not None:
cell.grid_span = int(grid.attrib[_name('{{{w}}}val')])
vmerge = prop.find(_name('{{{w}}}vMerge'))
if vmerg... | python | def parse_table_column_properties(doc, cell, prop):
"Parse table column properties."
if not cell:
return
grid = prop.find(_name('{{{w}}}gridSpan'))
if grid is not None:
cell.grid_span = int(grid.attrib[_name('{{{w}}}val')])
vmerge = prop.find(_name('{{{w}}}vMerge'))
if vmerg... | [
"def",
"parse_table_column_properties",
"(",
"doc",
",",
"cell",
",",
"prop",
")",
":",
"if",
"not",
"cell",
":",
"return",
"grid",
"=",
"prop",
".",
"find",
"(",
"_name",
"(",
"'{{{w}}}gridSpan'",
")",
")",
"if",
"grid",
"is",
"not",
"None",
":",
"cel... | Parse table column properties. | [
"Parse",
"table",
"column",
"properties",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L374-L391 | train | 60,780 |
booktype/python-ooxml | ooxml/parse.py | parse_table | def parse_table(document, tbl):
"Parse table element."
def _change(rows, pos_x):
if len(rows) == 1:
return rows
count_x = 1
for x in rows[-1]:
if count_x == pos_x:
x.row_span += 1
count_x += x.grid_span
return rows
tab... | python | def parse_table(document, tbl):
"Parse table element."
def _change(rows, pos_x):
if len(rows) == 1:
return rows
count_x = 1
for x in rows[-1]:
if count_x == pos_x:
x.row_span += 1
count_x += x.grid_span
return rows
tab... | [
"def",
"parse_table",
"(",
"document",
",",
"tbl",
")",
":",
"def",
"_change",
"(",
"rows",
",",
"pos_x",
")",
":",
"if",
"len",
"(",
"rows",
")",
"==",
"1",
":",
"return",
"rows",
"count_x",
"=",
"1",
"for",
"x",
"in",
"rows",
"[",
"-",
"1",
"... | Parse table element. | [
"Parse",
"table",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L394-L443 | train | 60,781 |
booktype/python-ooxml | ooxml/parse.py | parse_document | def parse_document(xmlcontent):
"""Parse document with content.
Content is placed in file 'document.xml'.
"""
document = etree.fromstring(xmlcontent)
body = document.xpath('.//w:body', namespaces=NAMESPACES)[0]
document = doc.Document()
for elem in body:
if elem.tag == _name('{{... | python | def parse_document(xmlcontent):
"""Parse document with content.
Content is placed in file 'document.xml'.
"""
document = etree.fromstring(xmlcontent)
body = document.xpath('.//w:body', namespaces=NAMESPACES)[0]
document = doc.Document()
for elem in body:
if elem.tag == _name('{{... | [
"def",
"parse_document",
"(",
"xmlcontent",
")",
":",
"document",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"body",
"=",
"document",
".",
"xpath",
"(",
"'.//w:body'",
",",
"namespaces",
"=",
"NAMESPACES",
")",
"[",
"0",
"]",
"document",
"=",... | Parse document with content.
Content is placed in file 'document.xml'. | [
"Parse",
"document",
"with",
"content",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L446-L468 | train | 60,782 |
booktype/python-ooxml | ooxml/parse.py | parse_relationship | def parse_relationship(document, xmlcontent, rel_type):
"""Parse relationship document.
Relationships hold information like external or internal references for links.
Relationships are placed in file '_rels/document.xml.rels'.
"""
doc = etree.fromstring(xmlcontent)
for elem in doc:
i... | python | def parse_relationship(document, xmlcontent, rel_type):
"""Parse relationship document.
Relationships hold information like external or internal references for links.
Relationships are placed in file '_rels/document.xml.rels'.
"""
doc = etree.fromstring(xmlcontent)
for elem in doc:
i... | [
"def",
"parse_relationship",
"(",
"document",
",",
"xmlcontent",
",",
"rel_type",
")",
":",
"doc",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"for",
"elem",
"in",
"doc",
":",
"if",
"elem",
".",
"tag",
"==",
"_name",
"(",
"'{{{pr}}}Relationshi... | Parse relationship document.
Relationships hold information like external or internal references for links.
Relationships are placed in file '_rels/document.xml.rels'. | [
"Parse",
"relationship",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L471-L487 | train | 60,783 |
booktype/python-ooxml | ooxml/parse.py | parse_style | def parse_style(document, xmlcontent):
"""Parse styles document.
Styles are defined in file 'styles.xml'.
"""
styles = etree.fromstring(xmlcontent)
_r = styles.xpath('.//w:rPrDefault', namespaces=NAMESPACES)
if len(_r) > 0:
rpr = _r[0].find(_name('{{{w}}}rPr'))
if rpr is not... | python | def parse_style(document, xmlcontent):
"""Parse styles document.
Styles are defined in file 'styles.xml'.
"""
styles = etree.fromstring(xmlcontent)
_r = styles.xpath('.//w:rPrDefault', namespaces=NAMESPACES)
if len(_r) > 0:
rpr = _r[0].find(_name('{{{w}}}rPr'))
if rpr is not... | [
"def",
"parse_style",
"(",
"document",
",",
"xmlcontent",
")",
":",
"styles",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"_r",
"=",
"styles",
".",
"xpath",
"(",
"'.//w:rPrDefault'",
",",
"namespaces",
"=",
"NAMESPACES",
")",
"if",
"len",
"(",... | Parse styles document.
Styles are defined in file 'styles.xml'. | [
"Parse",
"styles",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L490-L545 | train | 60,784 |
booktype/python-ooxml | ooxml/parse.py | parse_comments | def parse_comments(document, xmlcontent):
"""Parse comments document.
Comments are defined in file 'comments.xml'
"""
comments = etree.fromstring(xmlcontent)
document.comments = {}
for comment in comments.xpath('.//w:comment', namespaces=NAMESPACES):
# w:author
# w:id
... | python | def parse_comments(document, xmlcontent):
"""Parse comments document.
Comments are defined in file 'comments.xml'
"""
comments = etree.fromstring(xmlcontent)
document.comments = {}
for comment in comments.xpath('.//w:comment', namespaces=NAMESPACES):
# w:author
# w:id
... | [
"def",
"parse_comments",
"(",
"document",
",",
"xmlcontent",
")",
":",
"comments",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"document",
".",
"comments",
"=",
"{",
"}",
"for",
"comment",
"in",
"comments",
".",
"xpath",
"(",
"'.//w:comment'",
... | Parse comments document.
Comments are defined in file 'comments.xml' | [
"Parse",
"comments",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L548-L569 | train | 60,785 |
booktype/python-ooxml | ooxml/parse.py | parse_footnotes | def parse_footnotes(document, xmlcontent):
"""Parse footnotes document.
Footnotes are defined in file 'footnotes.xml'
"""
footnotes = etree.fromstring(xmlcontent)
document.footnotes = {}
for footnote in footnotes.xpath('.//w:footnote', namespaces=NAMESPACES):
_type = footnote.attrib.g... | python | def parse_footnotes(document, xmlcontent):
"""Parse footnotes document.
Footnotes are defined in file 'footnotes.xml'
"""
footnotes = etree.fromstring(xmlcontent)
document.footnotes = {}
for footnote in footnotes.xpath('.//w:footnote', namespaces=NAMESPACES):
_type = footnote.attrib.g... | [
"def",
"parse_footnotes",
"(",
"document",
",",
"xmlcontent",
")",
":",
"footnotes",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"document",
".",
"footnotes",
"=",
"{",
"}",
"for",
"footnote",
"in",
"footnotes",
".",
"xpath",
"(",
"'.//w:footnot... | Parse footnotes document.
Footnotes are defined in file 'footnotes.xml' | [
"Parse",
"footnotes",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L572-L590 | train | 60,786 |
booktype/python-ooxml | ooxml/parse.py | parse_endnotes | def parse_endnotes(document, xmlcontent):
"""Parse endnotes document.
Endnotes are defined in file 'endnotes.xml'
"""
endnotes = etree.fromstring(xmlcontent)
document.endnotes = {}
for note in endnotes.xpath('.//w:endnote', namespaces=NAMESPACES):
paragraphs = [parse_paragraph(documen... | python | def parse_endnotes(document, xmlcontent):
"""Parse endnotes document.
Endnotes are defined in file 'endnotes.xml'
"""
endnotes = etree.fromstring(xmlcontent)
document.endnotes = {}
for note in endnotes.xpath('.//w:endnote', namespaces=NAMESPACES):
paragraphs = [parse_paragraph(documen... | [
"def",
"parse_endnotes",
"(",
"document",
",",
"xmlcontent",
")",
":",
"endnotes",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"document",
".",
"endnotes",
"=",
"{",
"}",
"for",
"note",
"in",
"endnotes",
".",
"xpath",
"(",
"'.//w:endnote'",
",... | Parse endnotes document.
Endnotes are defined in file 'endnotes.xml' | [
"Parse",
"endnotes",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L593-L605 | train | 60,787 |
booktype/python-ooxml | ooxml/parse.py | parse_numbering | def parse_numbering(document, xmlcontent):
"""Parse numbering document.
Numbering is defined in file 'numbering.xml'.
"""
numbering = etree.fromstring(xmlcontent)
document.abstruct_numbering = {}
document.numbering = {}
for abstruct_num in numbering.xpath('.//w:abstractNum', namespaces=N... | python | def parse_numbering(document, xmlcontent):
"""Parse numbering document.
Numbering is defined in file 'numbering.xml'.
"""
numbering = etree.fromstring(xmlcontent)
document.abstruct_numbering = {}
document.numbering = {}
for abstruct_num in numbering.xpath('.//w:abstractNum', namespaces=N... | [
"def",
"parse_numbering",
"(",
"document",
",",
"xmlcontent",
")",
":",
"numbering",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"document",
".",
"abstruct_numbering",
"=",
"{",
"}",
"document",
".",
"numbering",
"=",
"{",
"}",
"for",
"abstruct_... | Parse numbering document.
Numbering is defined in file 'numbering.xml'. | [
"Parse",
"numbering",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L608-L636 | train | 60,788 |
booktype/python-ooxml | ooxml/parse.py | parse_from_file | def parse_from_file(file_object):
"""Parses existing OOXML file.
:Args:
- file_object (:class:`ooxml.docx.DOCXFile`): OOXML file object
:Returns:
Returns parsed document of type :class:`ooxml.doc.Document`
"""
logger.info('Parsing %s file.', file_object.file_name)
# Read the file... | python | def parse_from_file(file_object):
"""Parses existing OOXML file.
:Args:
- file_object (:class:`ooxml.docx.DOCXFile`): OOXML file object
:Returns:
Returns parsed document of type :class:`ooxml.doc.Document`
"""
logger.info('Parsing %s file.', file_object.file_name)
# Read the file... | [
"def",
"parse_from_file",
"(",
"file_object",
")",
":",
"logger",
".",
"info",
"(",
"'Parsing %s file.'",
",",
"file_object",
".",
"file_name",
")",
"# Read the files",
"doc_content",
"=",
"file_object",
".",
"read_file",
"(",
"'document.xml'",
")",
"# Parse the doc... | Parses existing OOXML file.
:Args:
- file_object (:class:`ooxml.docx.DOCXFile`): OOXML file object
:Returns:
Returns parsed document of type :class:`ooxml.doc.Document` | [
"Parses",
"existing",
"OOXML",
"file",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L639-L705 | train | 60,789 |
booktype/python-ooxml | ooxml/doc.py | StylesCollection.get_by_name | def get_by_name(self, name, style_type = None):
"""Find style by it's descriptive name.
:Returns:
Returns found style of type :class:`ooxml.doc.Style`.
"""
for st in self.styles.values():
if st:
if st.name == name:
return st
... | python | def get_by_name(self, name, style_type = None):
"""Find style by it's descriptive name.
:Returns:
Returns found style of type :class:`ooxml.doc.Style`.
"""
for st in self.styles.values():
if st:
if st.name == name:
return st
... | [
"def",
"get_by_name",
"(",
"self",
",",
"name",
",",
"style_type",
"=",
"None",
")",
":",
"for",
"st",
"in",
"self",
".",
"styles",
".",
"values",
"(",
")",
":",
"if",
"st",
":",
"if",
"st",
".",
"name",
"==",
"name",
":",
"return",
"st",
"if",
... | Find style by it's descriptive name.
:Returns:
Returns found style of type :class:`ooxml.doc.Style`. | [
"Find",
"style",
"by",
"it",
"s",
"descriptive",
"name",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/doc.py#L55-L68 | train | 60,790 |
booktype/python-ooxml | ooxml/doc.py | StylesCollection.get_by_id | def get_by_id(self, style_id, style_type = None):
"""Find style by it's unique identifier
:Returns:
Returns found style of type :class:`ooxml.doc.Style`.
"""
for st in self.styles.values():
if st:
if st.style_id == style_id:
ret... | python | def get_by_id(self, style_id, style_type = None):
"""Find style by it's unique identifier
:Returns:
Returns found style of type :class:`ooxml.doc.Style`.
"""
for st in self.styles.values():
if st:
if st.style_id == style_id:
ret... | [
"def",
"get_by_id",
"(",
"self",
",",
"style_id",
",",
"style_type",
"=",
"None",
")",
":",
"for",
"st",
"in",
"self",
".",
"styles",
".",
"values",
"(",
")",
":",
"if",
"st",
":",
"if",
"st",
".",
"style_id",
"==",
"style_id",
":",
"return",
"st",... | Find style by it's unique identifier
:Returns:
Returns found style of type :class:`ooxml.doc.Style`. | [
"Find",
"style",
"by",
"it",
"s",
"unique",
"identifier"
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/doc.py#L70-L84 | train | 60,791 |
rfk/threading2 | threading2/t2_base.py | process_affinity | def process_affinity(affinity=None):
"""Get or set the CPU affinity set for the current process.
This will affect all future threads spawned by this process. It is
implementation-defined whether it will also affect previously-spawned
threads.
"""
if affinity is not None:
affinity = CPU... | python | def process_affinity(affinity=None):
"""Get or set the CPU affinity set for the current process.
This will affect all future threads spawned by this process. It is
implementation-defined whether it will also affect previously-spawned
threads.
"""
if affinity is not None:
affinity = CPU... | [
"def",
"process_affinity",
"(",
"affinity",
"=",
"None",
")",
":",
"if",
"affinity",
"is",
"not",
"None",
":",
"affinity",
"=",
"CPUSet",
"(",
"affinity",
")",
"if",
"not",
"affinity",
".",
"issubset",
"(",
"system_affinity",
"(",
")",
")",
":",
"raise",... | Get or set the CPU affinity set for the current process.
This will affect all future threads spawned by this process. It is
implementation-defined whether it will also affect previously-spawned
threads. | [
"Get",
"or",
"set",
"the",
"CPU",
"affinity",
"set",
"for",
"the",
"current",
"process",
"."
] | 7ec234ddd8c0d7e683b1a5c4a79a3d001143189f | https://github.com/rfk/threading2/blob/7ec234ddd8c0d7e683b1a5c4a79a3d001143189f/threading2/t2_base.py#L610-L621 | train | 60,792 |
rfk/threading2 | threading2/t2_base.py | Lock.acquire | def acquire(self,blocking=True,timeout=None):
"""Attempt to acquire this lock.
If the optional argument "blocking" is True and "timeout" is None,
this methods blocks until is successfully acquires the lock. If
"blocking" is False, it returns immediately if the lock could not
be... | python | def acquire(self,blocking=True,timeout=None):
"""Attempt to acquire this lock.
If the optional argument "blocking" is True and "timeout" is None,
this methods blocks until is successfully acquires the lock. If
"blocking" is False, it returns immediately if the lock could not
be... | [
"def",
"acquire",
"(",
"self",
",",
"blocking",
"=",
"True",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"return",
"self",
".",
"__lock",
".",
"acquire",
"(",
"blocking",
")",
"else",
":",
"# Simulated timeout using progress... | Attempt to acquire this lock.
If the optional argument "blocking" is True and "timeout" is None,
this methods blocks until is successfully acquires the lock. If
"blocking" is False, it returns immediately if the lock could not
be acquired. Otherwise, it blocks for at most "timeout" se... | [
"Attempt",
"to",
"acquire",
"this",
"lock",
"."
] | 7ec234ddd8c0d7e683b1a5c4a79a3d001143189f | https://github.com/rfk/threading2/blob/7ec234ddd8c0d7e683b1a5c4a79a3d001143189f/threading2/t2_base.py#L39-L68 | train | 60,793 |
rfk/threading2 | threading2/t2_base.py | Thread.from_thread | def from_thread(cls,thread):
"""Convert a vanilla thread object into an instance of this class.
This method "upgrades" a vanilla thread object to an instance of this
extended class. You might need to call this if you obtain a reference
to a thread by some means other than (a) creating ... | python | def from_thread(cls,thread):
"""Convert a vanilla thread object into an instance of this class.
This method "upgrades" a vanilla thread object to an instance of this
extended class. You might need to call this if you obtain a reference
to a thread by some means other than (a) creating ... | [
"def",
"from_thread",
"(",
"cls",
",",
"thread",
")",
":",
"new_classes",
"=",
"[",
"]",
"for",
"new_cls",
"in",
"cls",
".",
"__mro__",
":",
"if",
"new_cls",
"not",
"in",
"thread",
".",
"__class__",
".",
"__mro__",
":",
"new_classes",
".",
"append",
"(... | Convert a vanilla thread object into an instance of this class.
This method "upgrades" a vanilla thread object to an instance of this
extended class. You might need to call this if you obtain a reference
to a thread by some means other than (a) creating it, or (b) from the
methods of ... | [
"Convert",
"a",
"vanilla",
"thread",
"object",
"into",
"an",
"instance",
"of",
"this",
"class",
"."
] | 7ec234ddd8c0d7e683b1a5c4a79a3d001143189f | https://github.com/rfk/threading2/blob/7ec234ddd8c0d7e683b1a5c4a79a3d001143189f/threading2/t2_base.py#L290-L313 | train | 60,794 |
rfk/threading2 | threading2/t2_base.py | SHLock.acquire | def acquire(self,blocking=True,timeout=None,shared=False):
"""Acquire the lock in shared or exclusive mode."""
with self._lock:
if shared:
self._acquire_shared(blocking,timeout)
else:
self._acquire_exclusive(blocking,timeout)
assert not... | python | def acquire(self,blocking=True,timeout=None,shared=False):
"""Acquire the lock in shared or exclusive mode."""
with self._lock:
if shared:
self._acquire_shared(blocking,timeout)
else:
self._acquire_exclusive(blocking,timeout)
assert not... | [
"def",
"acquire",
"(",
"self",
",",
"blocking",
"=",
"True",
",",
"timeout",
"=",
"None",
",",
"shared",
"=",
"False",
")",
":",
"with",
"self",
".",
"_lock",
":",
"if",
"shared",
":",
"self",
".",
"_acquire_shared",
"(",
"blocking",
",",
"timeout",
... | Acquire the lock in shared or exclusive mode. | [
"Acquire",
"the",
"lock",
"in",
"shared",
"or",
"exclusive",
"mode",
"."
] | 7ec234ddd8c0d7e683b1a5c4a79a3d001143189f | https://github.com/rfk/threading2/blob/7ec234ddd8c0d7e683b1a5c4a79a3d001143189f/threading2/t2_base.py#L450-L457 | train | 60,795 |
booktype/python-ooxml | ooxml/serialize.py | _get_font_size | def _get_font_size(document, style):
"""Get font size defined for this style.
It will try to get font size from it's parent style if it is not defined by original style.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
:Ret... | python | def _get_font_size(document, style):
"""Get font size defined for this style.
It will try to get font size from it's parent style if it is not defined by original style.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
:Ret... | [
"def",
"_get_font_size",
"(",
"document",
",",
"style",
")",
":",
"font_size",
"=",
"style",
".",
"get_font_size",
"(",
")",
"if",
"font_size",
"==",
"-",
"1",
":",
"if",
"style",
".",
"based_on",
":",
"based_on",
"=",
"document",
".",
"styles",
".",
"... | Get font size defined for this style.
It will try to get font size from it's parent style if it is not defined by original style.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
:Returns:
Returns font size as a number. -... | [
"Get",
"font",
"size",
"defined",
"for",
"this",
"style",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L44-L65 | train | 60,796 |
booktype/python-ooxml | ooxml/serialize.py | _get_numbering | def _get_numbering(document, numid, ilvl):
"""Returns type for the list.
:Returns:
Returns type for the list. Returns "bullet" by default or in case of an error.
"""
try:
abs_num = document.numbering[numid]
return document.abstruct_numbering[abs_num][ilvl]['numFmt']
except:
... | python | def _get_numbering(document, numid, ilvl):
"""Returns type for the list.
:Returns:
Returns type for the list. Returns "bullet" by default or in case of an error.
"""
try:
abs_num = document.numbering[numid]
return document.abstruct_numbering[abs_num][ilvl]['numFmt']
except:
... | [
"def",
"_get_numbering",
"(",
"document",
",",
"numid",
",",
"ilvl",
")",
":",
"try",
":",
"abs_num",
"=",
"document",
".",
"numbering",
"[",
"numid",
"]",
"return",
"document",
".",
"abstruct_numbering",
"[",
"abs_num",
"]",
"[",
"ilvl",
"]",
"[",
"'num... | Returns type for the list.
:Returns:
Returns type for the list. Returns "bullet" by default or in case of an error. | [
"Returns",
"type",
"for",
"the",
"list",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L74-L85 | train | 60,797 |
booktype/python-ooxml | ooxml/serialize.py | _get_parent | def _get_parent(root):
"""Returns root element for a list.
:Args:
root (Element): lxml element of current location
:Returns:
lxml element representing list
"""
elem = root
while True:
elem = elem.getparent()
if elem.tag in ['ul', 'ol']:
return e... | python | def _get_parent(root):
"""Returns root element for a list.
:Args:
root (Element): lxml element of current location
:Returns:
lxml element representing list
"""
elem = root
while True:
elem = elem.getparent()
if elem.tag in ['ul', 'ol']:
return e... | [
"def",
"_get_parent",
"(",
"root",
")",
":",
"elem",
"=",
"root",
"while",
"True",
":",
"elem",
"=",
"elem",
".",
"getparent",
"(",
")",
"if",
"elem",
".",
"tag",
"in",
"[",
"'ul'",
",",
"'ol'",
"]",
":",
"return",
"elem"
] | Returns root element for a list.
:Args:
root (Element): lxml element of current location
:Returns:
lxml element representing list | [
"Returns",
"root",
"element",
"for",
"a",
"list",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L104-L120 | train | 60,798 |
booktype/python-ooxml | ooxml/serialize.py | close_list | def close_list(ctx, root):
"""Close already opened list if needed.
This will try to see if it is needed to close already opened list.
:Args:
- ctx (:class:`Context`): Context object
- root (Element): lxml element representing current position.
:Returns:
lxml element where future co... | python | def close_list(ctx, root):
"""Close already opened list if needed.
This will try to see if it is needed to close already opened list.
:Args:
- ctx (:class:`Context`): Context object
- root (Element): lxml element representing current position.
:Returns:
lxml element where future co... | [
"def",
"close_list",
"(",
"ctx",
",",
"root",
")",
":",
"try",
":",
"n",
"=",
"len",
"(",
"ctx",
".",
"in_list",
")",
"if",
"n",
"<=",
"0",
":",
"return",
"root",
"elem",
"=",
"root",
"while",
"n",
">",
"0",
":",
"while",
"True",
":",
"if",
"... | Close already opened list if needed.
This will try to see if it is needed to close already opened list.
:Args:
- ctx (:class:`Context`): Context object
- root (Element): lxml element representing current position.
:Returns:
lxml element where future content should be placed. | [
"Close",
"already",
"opened",
"list",
"if",
"needed",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L123-L157 | train | 60,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.