repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
jfilter/text-classification-keras | texcla/preprocessing/word_tokenizer.py | SpacyTokenizer._apply_options | def _apply_options(self, token):
"""Applies various filtering and processing options on token.
Returns:
The processed token. None if filtered.
"""
# Apply work token filtering.
if token.is_punct and self.remove_punct:
return None
if token.is_stop ... | python | def _apply_options(self, token):
"""Applies various filtering and processing options on token.
Returns:
The processed token. None if filtered.
"""
# Apply work token filtering.
if token.is_punct and self.remove_punct:
return None
if token.is_stop ... | [
"def",
"_apply_options",
"(",
"self",
",",
"token",
")",
":",
"# Apply work token filtering.",
"if",
"token",
".",
"is_punct",
"and",
"self",
".",
"remove_punct",
":",
"return",
"None",
"if",
"token",
".",
"is_stop",
"and",
"self",
".",
"remove_stop_words",
":... | Applies various filtering and processing options on token.
Returns:
The processed token. None if filtered. | [
"Applies",
"various",
"filtering",
"and",
"processing",
"options",
"on",
"token",
"."
] | a59c652805da41d18937c7fdad0d9fd943cf8578 | https://github.com/jfilter/text-classification-keras/blob/a59c652805da41d18937c7fdad0d9fd943cf8578/texcla/preprocessing/word_tokenizer.py#L52-L77 | train |
jfilter/text-classification-keras | texcla/preprocessing/word_tokenizer.py | SpacyTokenizer.token_generator | def token_generator(self, texts, **kwargs):
"""Yields tokens from texts as `(text_idx, word)`
Args:
texts: The list of texts.
**kwargs: Supported args include:
n_threads/num_threads: Number of threads to use. Uses num_cpus - 1 by default.
batch_si... | python | def token_generator(self, texts, **kwargs):
"""Yields tokens from texts as `(text_idx, word)`
Args:
texts: The list of texts.
**kwargs: Supported args include:
n_threads/num_threads: Number of threads to use. Uses num_cpus - 1 by default.
batch_si... | [
"def",
"token_generator",
"(",
"self",
",",
"texts",
",",
"*",
"*",
"kwargs",
")",
":",
"# Perf optimization. Only process what is necessary.",
"n_threads",
",",
"batch_size",
"=",
"utils",
".",
"_parse_spacy_kwargs",
"(",
"*",
"*",
"kwargs",
")",
"nlp",
"=",
"s... | Yields tokens from texts as `(text_idx, word)`
Args:
texts: The list of texts.
**kwargs: Supported args include:
n_threads/num_threads: Number of threads to use. Uses num_cpus - 1 by default.
batch_size: The number of texts to accumulate into a common wor... | [
"Yields",
"tokens",
"from",
"texts",
"as",
"(",
"text_idx",
"word",
")"
] | a59c652805da41d18937c7fdad0d9fd943cf8578 | https://github.com/jfilter/text-classification-keras/blob/a59c652805da41d18937c7fdad0d9fd943cf8578/texcla/preprocessing/word_tokenizer.py#L79-L107 | train |
jfilter/text-classification-keras | texcla/preprocessing/utils.py | _append | def _append(lst, indices, value):
"""Adds `value` to `lst` list indexed by `indices`. Will create sub lists as required.
"""
for i, idx in enumerate(indices):
# We need to loop because sometimes indices can increment by more than 1 due to missing tokens.
# Example: Sentence with no words aft... | python | def _append(lst, indices, value):
"""Adds `value` to `lst` list indexed by `indices`. Will create sub lists as required.
"""
for i, idx in enumerate(indices):
# We need to loop because sometimes indices can increment by more than 1 due to missing tokens.
# Example: Sentence with no words aft... | [
"def",
"_append",
"(",
"lst",
",",
"indices",
",",
"value",
")",
":",
"for",
"i",
",",
"idx",
"in",
"enumerate",
"(",
"indices",
")",
":",
"# We need to loop because sometimes indices can increment by more than 1 due to missing tokens.",
"# Example: Sentence with no words a... | Adds `value` to `lst` list indexed by `indices`. Will create sub lists as required. | [
"Adds",
"value",
"to",
"lst",
"list",
"indexed",
"by",
"indices",
".",
"Will",
"create",
"sub",
"lists",
"as",
"required",
"."
] | a59c652805da41d18937c7fdad0d9fd943cf8578 | https://github.com/jfilter/text-classification-keras/blob/a59c652805da41d18937c7fdad0d9fd943cf8578/texcla/preprocessing/utils.py#L82-L95 | train |
jfilter/text-classification-keras | texcla/preprocessing/utils.py | _parse_spacy_kwargs | def _parse_spacy_kwargs(**kwargs):
"""Supported args include:
Args:
n_threads/num_threads: Number of threads to use. Uses num_cpus - 1 by default.
batch_size: The number of texts to accumulate into a common working set before processing.
(Default value: 1000)
"""
n_threads =... | python | def _parse_spacy_kwargs(**kwargs):
"""Supported args include:
Args:
n_threads/num_threads: Number of threads to use. Uses num_cpus - 1 by default.
batch_size: The number of texts to accumulate into a common working set before processing.
(Default value: 1000)
"""
n_threads =... | [
"def",
"_parse_spacy_kwargs",
"(",
"*",
"*",
"kwargs",
")",
":",
"n_threads",
"=",
"kwargs",
".",
"get",
"(",
"'n_threads'",
")",
"or",
"kwargs",
".",
"get",
"(",
"'num_threads'",
")",
"batch_size",
"=",
"kwargs",
".",
"get",
"(",
"'batch_size'",
")",
"i... | Supported args include:
Args:
n_threads/num_threads: Number of threads to use. Uses num_cpus - 1 by default.
batch_size: The number of texts to accumulate into a common working set before processing.
(Default value: 1000) | [
"Supported",
"args",
"include",
":"
] | a59c652805da41d18937c7fdad0d9fd943cf8578 | https://github.com/jfilter/text-classification-keras/blob/a59c652805da41d18937c7fdad0d9fd943cf8578/texcla/preprocessing/utils.py#L113-L128 | train |
jfilter/text-classification-keras | texcla/preprocessing/utils.py | _CountTracker.update | def update(self, indices):
"""Updates counts based on indices. The algorithm tracks the index change at i and
update global counts for all indices beyond i with local counts tracked so far.
"""
# Initialize various lists for the first time based on length of indices.
if self._pre... | python | def update(self, indices):
"""Updates counts based on indices. The algorithm tracks the index change at i and
update global counts for all indices beyond i with local counts tracked so far.
"""
# Initialize various lists for the first time based on length of indices.
if self._pre... | [
"def",
"update",
"(",
"self",
",",
"indices",
")",
":",
"# Initialize various lists for the first time based on length of indices.",
"if",
"self",
".",
"_prev_indices",
"is",
"None",
":",
"self",
".",
"_prev_indices",
"=",
"indices",
"# +1 to track token counts in the last ... | Updates counts based on indices. The algorithm tracks the index change at i and
update global counts for all indices beyond i with local counts tracked so far. | [
"Updates",
"counts",
"based",
"on",
"indices",
".",
"The",
"algorithm",
"tracks",
"the",
"index",
"change",
"at",
"i",
"and",
"update",
"global",
"counts",
"for",
"all",
"indices",
"beyond",
"i",
"with",
"local",
"counts",
"tracked",
"so",
"far",
"."
] | a59c652805da41d18937c7fdad0d9fd943cf8578 | https://github.com/jfilter/text-classification-keras/blob/a59c652805da41d18937c7fdad0d9fd943cf8578/texcla/preprocessing/utils.py#L34-L62 | train |
jfilter/text-classification-keras | texcla/preprocessing/utils.py | _CountTracker.finalize | def finalize(self):
"""This will add the very last document to counts. We also get rid of counts[0] since that
represents document level which doesnt come under anything else. We also convert all count
values to numpy arrays so that stats can be computed easily.
"""
for i in rang... | python | def finalize(self):
"""This will add the very last document to counts. We also get rid of counts[0] since that
represents document level which doesnt come under anything else. We also convert all count
values to numpy arrays so that stats can be computed easily.
"""
for i in rang... | [
"def",
"finalize",
"(",
"self",
")",
":",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"self",
".",
"_local_counts",
")",
")",
":",
"self",
".",
"counts",
"[",
"i",
"]",
".",
"append",
"(",
"self",
".",
"_local_counts",
"[",
"i",
"]",
... | This will add the very last document to counts. We also get rid of counts[0] since that
represents document level which doesnt come under anything else. We also convert all count
values to numpy arrays so that stats can be computed easily. | [
"This",
"will",
"add",
"the",
"very",
"last",
"document",
"to",
"counts",
".",
"We",
"also",
"get",
"rid",
"of",
"counts",
"[",
"0",
"]",
"since",
"that",
"represents",
"document",
"level",
"which",
"doesnt",
"come",
"under",
"anything",
"else",
".",
"We... | a59c652805da41d18937c7fdad0d9fd943cf8578 | https://github.com/jfilter/text-classification-keras/blob/a59c652805da41d18937c7fdad0d9fd943cf8578/texcla/preprocessing/utils.py#L64-L74 | train |
jfilter/text-classification-keras | texcla/corpus.py | read_folder | def read_folder(directory):
"""read text files in directory and returns them as array
Args:
directory: where the text files are
Returns:
Array of text
"""
res = []
for filename in os.listdir(directory):
with io.open(os.path.join(directory, filename), encoding="utf-8") a... | python | def read_folder(directory):
"""read text files in directory and returns them as array
Args:
directory: where the text files are
Returns:
Array of text
"""
res = []
for filename in os.listdir(directory):
with io.open(os.path.join(directory, filename), encoding="utf-8") a... | [
"def",
"read_folder",
"(",
"directory",
")",
":",
"res",
"=",
"[",
"]",
"for",
"filename",
"in",
"os",
".",
"listdir",
"(",
"directory",
")",
":",
"with",
"io",
".",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"directory",
",",
"filename",
")... | read text files in directory and returns them as array
Args:
directory: where the text files are
Returns:
Array of text | [
"read",
"text",
"files",
"in",
"directory",
"and",
"returns",
"them",
"as",
"array"
] | a59c652805da41d18937c7fdad0d9fd943cf8578 | https://github.com/jfilter/text-classification-keras/blob/a59c652805da41d18937c7fdad0d9fd943cf8578/texcla/corpus.py#L8-L22 | train |
jfilter/text-classification-keras | texcla/corpus.py | read_pos_neg_data | def read_pos_neg_data(path, folder, limit):
"""returns array with positive and negative examples"""
training_pos_path = os.path.join(path, folder, 'pos')
training_neg_path = os.path.join(path, folder, 'neg')
X_pos = read_folder(training_pos_path)
X_neg = read_folder(training_neg_path)
if limit... | python | def read_pos_neg_data(path, folder, limit):
"""returns array with positive and negative examples"""
training_pos_path = os.path.join(path, folder, 'pos')
training_neg_path = os.path.join(path, folder, 'neg')
X_pos = read_folder(training_pos_path)
X_neg = read_folder(training_neg_path)
if limit... | [
"def",
"read_pos_neg_data",
"(",
"path",
",",
"folder",
",",
"limit",
")",
":",
"training_pos_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"folder",
",",
"'pos'",
")",
"training_neg_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"pat... | returns array with positive and negative examples | [
"returns",
"array",
"with",
"positive",
"and",
"negative",
"examples"
] | a59c652805da41d18937c7fdad0d9fd943cf8578 | https://github.com/jfilter/text-classification-keras/blob/a59c652805da41d18937c7fdad0d9fd943cf8578/texcla/corpus.py#L25-L40 | train |
jfilter/text-classification-keras | texcla/corpus.py | imdb | def imdb(limit=None, shuffle=True):
"""Downloads (and caches) IMDB Moview Reviews. 25k training data, 25k test data
Args:
limit: get only first N items for each class
Returns:
[X_train, y_train, X_test, y_test]
"""
movie_review_url = 'http://ai.stanford.edu/~amaas/data/sentiment/a... | python | def imdb(limit=None, shuffle=True):
"""Downloads (and caches) IMDB Moview Reviews. 25k training data, 25k test data
Args:
limit: get only first N items for each class
Returns:
[X_train, y_train, X_test, y_test]
"""
movie_review_url = 'http://ai.stanford.edu/~amaas/data/sentiment/a... | [
"def",
"imdb",
"(",
"limit",
"=",
"None",
",",
"shuffle",
"=",
"True",
")",
":",
"movie_review_url",
"=",
"'http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz'",
"# download and extract, thus remove the suffix '.tar.gz'",
"path",
"=",
"keras",
".",
"utils",
".",... | Downloads (and caches) IMDB Moview Reviews. 25k training data, 25k test data
Args:
limit: get only first N items for each class
Returns:
[X_train, y_train, X_test, y_test] | [
"Downloads",
"(",
"and",
"caches",
")",
"IMDB",
"Moview",
"Reviews",
".",
"25k",
"training",
"data",
"25k",
"test",
"data"
] | a59c652805da41d18937c7fdad0d9fd943cf8578 | https://github.com/jfilter/text-classification-keras/blob/a59c652805da41d18937c7fdad0d9fd943cf8578/texcla/corpus.py#L43-L66 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | Dial.to_absolute | def to_absolute(self, x, y):
"""
Converts coordinates provided with reference to the center \
of the canvas (0, 0) to absolute coordinates which are used \
by the canvas object in which (0, 0) is located in the top \
left of the object.
:param x: x value in pixels
... | python | def to_absolute(self, x, y):
"""
Converts coordinates provided with reference to the center \
of the canvas (0, 0) to absolute coordinates which are used \
by the canvas object in which (0, 0) is located in the top \
left of the object.
:param x: x value in pixels
... | [
"def",
"to_absolute",
"(",
"self",
",",
"x",
",",
"y",
")",
":",
"return",
"x",
"+",
"self",
".",
"size",
"/",
"2",
",",
"y",
"+",
"self",
".",
"size",
"/",
"2"
] | Converts coordinates provided with reference to the center \
of the canvas (0, 0) to absolute coordinates which are used \
by the canvas object in which (0, 0) is located in the top \
left of the object.
:param x: x value in pixels
:param y: x value in pixels
:return: No... | [
"Converts",
"coordinates",
"provided",
"with",
"reference",
"to",
"the",
"center",
"\\",
"of",
"the",
"canvas",
"(",
"0",
"0",
")",
"to",
"absolute",
"coordinates",
"which",
"are",
"used",
"\\",
"by",
"the",
"canvas",
"object",
"in",
"which",
"(",
"0",
"... | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L43-L54 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | RotaryScale.set_value | def set_value(self, number: (float, int)):
"""
Sets the value of the graphic
:param number: the number (must be between 0 and \
'max_range' or the scale will peg the limits
:return: None
"""
self.canvas.delete('all')
self.canvas.create_image(0, 0, image=s... | python | def set_value(self, number: (float, int)):
"""
Sets the value of the graphic
:param number: the number (must be between 0 and \
'max_range' or the scale will peg the limits
:return: None
"""
self.canvas.delete('all')
self.canvas.create_image(0, 0, image=s... | [
"def",
"set_value",
"(",
"self",
",",
"number",
":",
"(",
"float",
",",
"int",
")",
")",
":",
"self",
".",
"canvas",
".",
"delete",
"(",
"'all'",
")",
"self",
".",
"canvas",
".",
"create_image",
"(",
"0",
",",
"0",
",",
"image",
"=",
"self",
".",... | Sets the value of the graphic
:param number: the number (must be between 0 and \
'max_range' or the scale will peg the limits
:return: None | [
"Sets",
"the",
"value",
"of",
"the",
"graphic"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L112-L145 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | RotaryScale._draw_background | def _draw_background(self, divisions=10):
"""
Draws the background of the dial
:param divisions: the number of divisions
between 'ticks' shown on the dial
:return: None
"""
self.canvas.create_arc(2, 2, self.size-2, self.size-2,
styl... | python | def _draw_background(self, divisions=10):
"""
Draws the background of the dial
:param divisions: the number of divisions
between 'ticks' shown on the dial
:return: None
"""
self.canvas.create_arc(2, 2, self.size-2, self.size-2,
styl... | [
"def",
"_draw_background",
"(",
"self",
",",
"divisions",
"=",
"10",
")",
":",
"self",
".",
"canvas",
".",
"create_arc",
"(",
"2",
",",
"2",
",",
"self",
".",
"size",
"-",
"2",
",",
"self",
".",
"size",
"-",
"2",
",",
"style",
"=",
"tk",
".",
"... | Draws the background of the dial
:param divisions: the number of divisions
between 'ticks' shown on the dial
:return: None | [
"Draws",
"the",
"background",
"of",
"the",
"dial"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L147-L179 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | Graph.draw_axes | def draw_axes(self):
"""
Removes all existing series and re-draws the axes.
:return: None
"""
self.canvas.delete('all')
rect = 50, 50, self.w - 50, self.h - 50
self.canvas.create_rectangle(rect, outline="black")
for x in self.frange(0, self.x_max - self... | python | def draw_axes(self):
"""
Removes all existing series and re-draws the axes.
:return: None
"""
self.canvas.delete('all')
rect = 50, 50, self.w - 50, self.h - 50
self.canvas.create_rectangle(rect, outline="black")
for x in self.frange(0, self.x_max - self... | [
"def",
"draw_axes",
"(",
"self",
")",
":",
"self",
".",
"canvas",
".",
"delete",
"(",
"'all'",
")",
"rect",
"=",
"50",
",",
"50",
",",
"self",
".",
"w",
"-",
"50",
",",
"self",
".",
"h",
"-",
"50",
"self",
".",
"canvas",
".",
"create_rectangle",
... | Removes all existing series and re-draws the axes.
:return: None | [
"Removes",
"all",
"existing",
"series",
"and",
"re",
"-",
"draws",
"the",
"axes",
"."
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L391-L423 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | Graph.plot_point | def plot_point(self, x, y, visible=True, color='black', size=5):
"""
Places a single point on the grid
:param x: the x coordinate
:param y: the y coordinate
:param visible: True if the individual point should be visible
:param color: the color of the point
:param... | python | def plot_point(self, x, y, visible=True, color='black', size=5):
"""
Places a single point on the grid
:param x: the x coordinate
:param y: the y coordinate
:param visible: True if the individual point should be visible
:param color: the color of the point
:param... | [
"def",
"plot_point",
"(",
"self",
",",
"x",
",",
"y",
",",
"visible",
"=",
"True",
",",
"color",
"=",
"'black'",
",",
"size",
"=",
"5",
")",
":",
"xp",
"=",
"(",
"self",
".",
"px_x",
"*",
"(",
"x",
"-",
"self",
".",
"x_min",
")",
")",
"/",
... | Places a single point on the grid
:param x: the x coordinate
:param y: the y coordinate
:param visible: True if the individual point should be visible
:param color: the color of the point
:param size: the point size in pixels
:return: The absolute coordinates as a tuple | [
"Places",
"a",
"single",
"point",
"on",
"the",
"grid"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L425-L451 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | Graph.plot_line | def plot_line(self, points: list, color='black', point_visibility=False):
"""
Plot a line of points
:param points: a list of tuples, each tuple containing an (x, y) point
:param color: the color of the line
:param point_visibility: True if the points \
should be individu... | python | def plot_line(self, points: list, color='black', point_visibility=False):
"""
Plot a line of points
:param points: a list of tuples, each tuple containing an (x, y) point
:param color: the color of the line
:param point_visibility: True if the points \
should be individu... | [
"def",
"plot_line",
"(",
"self",
",",
"points",
":",
"list",
",",
"color",
"=",
"'black'",
",",
"point_visibility",
"=",
"False",
")",
":",
"last_point",
"=",
"(",
")",
"for",
"point",
"in",
"points",
":",
"this_point",
"=",
"self",
".",
"plot_point",
... | Plot a line of points
:param points: a list of tuples, each tuple containing an (x, y) point
:param color: the color of the line
:param point_visibility: True if the points \
should be individually visible
:return: None | [
"Plot",
"a",
"line",
"of",
"points"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L453-L470 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | Graph.frange | def frange(start, stop, step, digits_to_round=3):
"""
Works like range for doubles
:param start: starting value
:param stop: ending value
:param step: the increment_value
:param digits_to_round: the digits to which to round \
(makes floating-point numbers much ea... | python | def frange(start, stop, step, digits_to_round=3):
"""
Works like range for doubles
:param start: starting value
:param stop: ending value
:param step: the increment_value
:param digits_to_round: the digits to which to round \
(makes floating-point numbers much ea... | [
"def",
"frange",
"(",
"start",
",",
"stop",
",",
"step",
",",
"digits_to_round",
"=",
"3",
")",
":",
"while",
"start",
"<",
"stop",
":",
"yield",
"round",
"(",
"start",
",",
"digits_to_round",
")",
"start",
"+=",
"step"
] | Works like range for doubles
:param start: starting value
:param stop: ending value
:param step: the increment_value
:param digits_to_round: the digits to which to round \
(makes floating-point numbers much easier to work with)
:return: generator | [
"Works",
"like",
"range",
"for",
"doubles"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L474-L487 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | Led._load_new | def _load_new(self, img_data: str):
"""
Load a new image.
:param img_data: the image data as a base64 string
:return: None
"""
self._image = tk.PhotoImage(data=img_data)
self._image = self._image.subsample(int(200 / self._size),
... | python | def _load_new(self, img_data: str):
"""
Load a new image.
:param img_data: the image data as a base64 string
:return: None
"""
self._image = tk.PhotoImage(data=img_data)
self._image = self._image.subsample(int(200 / self._size),
... | [
"def",
"_load_new",
"(",
"self",
",",
"img_data",
":",
"str",
")",
":",
"self",
".",
"_image",
"=",
"tk",
".",
"PhotoImage",
"(",
"data",
"=",
"img_data",
")",
"self",
".",
"_image",
"=",
"self",
".",
"_image",
".",
"subsample",
"(",
"int",
"(",
"2... | Load a new image.
:param img_data: the image data as a base64 string
:return: None | [
"Load",
"a",
"new",
"image",
"."
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L534-L548 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | Led.to_grey | def to_grey(self, on: bool=False):
"""
Change the LED to grey.
:param on: Unused, here for API consistency with the other states
:return: None
"""
self._on = False
self._load_new(led_grey) | python | def to_grey(self, on: bool=False):
"""
Change the LED to grey.
:param on: Unused, here for API consistency with the other states
:return: None
"""
self._on = False
self._load_new(led_grey) | [
"def",
"to_grey",
"(",
"self",
",",
"on",
":",
"bool",
"=",
"False",
")",
":",
"self",
".",
"_on",
"=",
"False",
"self",
".",
"_load_new",
"(",
"led_grey",
")"
] | Change the LED to grey.
:param on: Unused, here for API consistency with the other states
:return: None | [
"Change",
"the",
"LED",
"to",
"grey",
"."
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L550-L558 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | Led.to_green | def to_green(self, on: bool=False):
"""
Change the LED to green (on or off).
:param on: True or False
:return: None
"""
self._on = on
if on:
self._load_new(led_green_on)
if self._toggle_on_click:
self._canvas.bind('<Button... | python | def to_green(self, on: bool=False):
"""
Change the LED to green (on or off).
:param on: True or False
:return: None
"""
self._on = on
if on:
self._load_new(led_green_on)
if self._toggle_on_click:
self._canvas.bind('<Button... | [
"def",
"to_green",
"(",
"self",
",",
"on",
":",
"bool",
"=",
"False",
")",
":",
"self",
".",
"_on",
"=",
"on",
"if",
"on",
":",
"self",
".",
"_load_new",
"(",
"led_green_on",
")",
"if",
"self",
".",
"_toggle_on_click",
":",
"self",
".",
"_canvas",
... | Change the LED to green (on or off).
:param on: True or False
:return: None | [
"Change",
"the",
"LED",
"to",
"green",
"(",
"on",
"or",
"off",
")",
"."
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L560-L577 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | Led.to_red | def to_red(self, on: bool=False):
"""
Change the LED to red (on or off)
:param on: True or False
:return: None
"""
self._on = on
if on:
self._load_new(led_red_on)
if self._toggle_on_click:
self._canvas.bind('<Button-1>', la... | python | def to_red(self, on: bool=False):
"""
Change the LED to red (on or off)
:param on: True or False
:return: None
"""
self._on = on
if on:
self._load_new(led_red_on)
if self._toggle_on_click:
self._canvas.bind('<Button-1>', la... | [
"def",
"to_red",
"(",
"self",
",",
"on",
":",
"bool",
"=",
"False",
")",
":",
"self",
".",
"_on",
"=",
"on",
"if",
"on",
":",
"self",
".",
"_load_new",
"(",
"led_red_on",
")",
"if",
"self",
".",
"_toggle_on_click",
":",
"self",
".",
"_canvas",
".",... | Change the LED to red (on or off)
:param on: True or False
:return: None | [
"Change",
"the",
"LED",
"to",
"red",
"(",
"on",
"or",
"off",
")",
":",
"param",
"on",
":",
"True",
"or",
"False",
":",
"return",
":",
"None"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L579-L595 | train |
slightlynybbled/tk_tools | tk_tools/canvas.py | Led.to_yellow | def to_yellow(self, on: bool=False):
"""
Change the LED to yellow (on or off)
:param on: True or False
:return: None
"""
self._on = on
if on:
self._load_new(led_yellow_on)
if self._toggle_on_click:
self._canvas.bind('<Butto... | python | def to_yellow(self, on: bool=False):
"""
Change the LED to yellow (on or off)
:param on: True or False
:return: None
"""
self._on = on
if on:
self._load_new(led_yellow_on)
if self._toggle_on_click:
self._canvas.bind('<Butto... | [
"def",
"to_yellow",
"(",
"self",
",",
"on",
":",
"bool",
"=",
"False",
")",
":",
"self",
".",
"_on",
"=",
"on",
"if",
"on",
":",
"self",
".",
"_load_new",
"(",
"led_yellow_on",
")",
"if",
"self",
".",
"_toggle_on_click",
":",
"self",
".",
"_canvas",
... | Change the LED to yellow (on or off)
:param on: True or False
:return: None | [
"Change",
"the",
"LED",
"to",
"yellow",
"(",
"on",
"or",
"off",
")",
":",
"param",
"on",
":",
"True",
"or",
"False",
":",
"return",
":",
"None"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/canvas.py#L597-L615 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | _Grid._redraw | def _redraw(self):
"""
Forgets the current layout and redraws with the most recent information
:return: None
"""
for row in self._rows:
for widget in row:
widget.grid_forget()
offset = 0 if not self.headers else 1
for i, row in enumer... | python | def _redraw(self):
"""
Forgets the current layout and redraws with the most recent information
:return: None
"""
for row in self._rows:
for widget in row:
widget.grid_forget()
offset = 0 if not self.headers else 1
for i, row in enumer... | [
"def",
"_redraw",
"(",
"self",
")",
":",
"for",
"row",
"in",
"self",
".",
"_rows",
":",
"for",
"widget",
"in",
"row",
":",
"widget",
".",
"grid_forget",
"(",
")",
"offset",
"=",
"0",
"if",
"not",
"self",
".",
"headers",
"else",
"1",
"for",
"i",
"... | Forgets the current layout and redraws with the most recent information
:return: None | [
"Forgets",
"the",
"current",
"layout",
"and",
"redraws",
"with",
"the",
"most",
"recent",
"information"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L56-L69 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | _Grid.remove_row | def remove_row(self, row_number: int=-1):
"""
Removes a specified row of data
:param row_number: the row to remove (defaults to the last row)
:return: None
"""
if len(self._rows) == 0:
return
row = self._rows.pop(row_number)
for widget in row... | python | def remove_row(self, row_number: int=-1):
"""
Removes a specified row of data
:param row_number: the row to remove (defaults to the last row)
:return: None
"""
if len(self._rows) == 0:
return
row = self._rows.pop(row_number)
for widget in row... | [
"def",
"remove_row",
"(",
"self",
",",
"row_number",
":",
"int",
"=",
"-",
"1",
")",
":",
"if",
"len",
"(",
"self",
".",
"_rows",
")",
"==",
"0",
":",
"return",
"row",
"=",
"self",
".",
"_rows",
".",
"pop",
"(",
"row_number",
")",
"for",
"widget"... | Removes a specified row of data
:param row_number: the row to remove (defaults to the last row)
:return: None | [
"Removes",
"a",
"specified",
"row",
"of",
"data"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L71-L83 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | LabelGrid.add_row | def add_row(self, data: list):
"""
Add a row of data to the current widget
:param data: a row of data
:return: None
"""
# validation
if self.headers:
if len(self.headers) != len(data):
raise ValueError
if len(data) != self.num... | python | def add_row(self, data: list):
"""
Add a row of data to the current widget
:param data: a row of data
:return: None
"""
# validation
if self.headers:
if len(self.headers) != len(data):
raise ValueError
if len(data) != self.num... | [
"def",
"add_row",
"(",
"self",
",",
"data",
":",
"list",
")",
":",
"# validation",
"if",
"self",
".",
"headers",
":",
"if",
"len",
"(",
"self",
".",
"headers",
")",
"!=",
"len",
"(",
"data",
")",
":",
"raise",
"ValueError",
"if",
"len",
"(",
"data"... | Add a row of data to the current widget
:param data: a row of data
:return: None | [
"Add",
"a",
"row",
"of",
"data",
"to",
"the",
"current",
"widget"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L109-L132 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | EntryGrid.add_row | def add_row(self, data: list=None):
"""
Add a row of data to the current widget, add a <Tab> \
binding to the last element of the last row, and set \
the focus at the beginning of the next row.
:param data: a row of data
:return: None
"""
# validation
... | python | def add_row(self, data: list=None):
"""
Add a row of data to the current widget, add a <Tab> \
binding to the last element of the last row, and set \
the focus at the beginning of the next row.
:param data: a row of data
:return: None
"""
# validation
... | [
"def",
"add_row",
"(",
"self",
",",
"data",
":",
"list",
"=",
"None",
")",
":",
"# validation",
"if",
"self",
".",
"headers",
"and",
"data",
":",
"if",
"len",
"(",
"self",
".",
"headers",
")",
"!=",
"len",
"(",
"data",
")",
":",
"raise",
"ValueErro... | Add a row of data to the current widget, add a <Tab> \
binding to the last element of the last row, and set \
the focus at the beginning of the next row.
:param data: a row of data
:return: None | [
"Add",
"a",
"row",
"of",
"data",
"to",
"the",
"current",
"widget",
"add",
"a",
"<Tab",
">",
"\\",
"binding",
"to",
"the",
"last",
"element",
"of",
"the",
"last",
"row",
"and",
"set",
"\\",
"the",
"focus",
"at",
"the",
"beginning",
"of",
"the",
"next"... | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L148-L198 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | EntryGrid._read_as_dict | def _read_as_dict(self):
"""
Read the data contained in all entries as a list of
dictionaries with the headers as the dictionary keys
:return: list of dicts containing all tabular data
"""
data = list()
for row in self._rows:
row_data = OrderedDict()
... | python | def _read_as_dict(self):
"""
Read the data contained in all entries as a list of
dictionaries with the headers as the dictionary keys
:return: list of dicts containing all tabular data
"""
data = list()
for row in self._rows:
row_data = OrderedDict()
... | [
"def",
"_read_as_dict",
"(",
"self",
")",
":",
"data",
"=",
"list",
"(",
")",
"for",
"row",
"in",
"self",
".",
"_rows",
":",
"row_data",
"=",
"OrderedDict",
"(",
")",
"for",
"i",
",",
"header",
"in",
"enumerate",
"(",
"self",
".",
"headers",
")",
"... | Read the data contained in all entries as a list of
dictionaries with the headers as the dictionary keys
:return: list of dicts containing all tabular data | [
"Read",
"the",
"data",
"contained",
"in",
"all",
"entries",
"as",
"a",
"list",
"of",
"dictionaries",
"with",
"the",
"headers",
"as",
"the",
"dictionary",
"keys"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L200-L215 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | EntryGrid._read_as_table | def _read_as_table(self):
"""
Read the data contained in all entries as a list of
lists containing all of the data
:return: list of dicts containing all tabular data
"""
rows = list()
for row in self._rows:
rows.append([row[i].get() for i in range(se... | python | def _read_as_table(self):
"""
Read the data contained in all entries as a list of
lists containing all of the data
:return: list of dicts containing all tabular data
"""
rows = list()
for row in self._rows:
rows.append([row[i].get() for i in range(se... | [
"def",
"_read_as_table",
"(",
"self",
")",
":",
"rows",
"=",
"list",
"(",
")",
"for",
"row",
"in",
"self",
".",
"_rows",
":",
"rows",
".",
"append",
"(",
"[",
"row",
"[",
"i",
"]",
".",
"get",
"(",
")",
"for",
"i",
"in",
"range",
"(",
"self",
... | Read the data contained in all entries as a list of
lists containing all of the data
:return: list of dicts containing all tabular data | [
"Read",
"the",
"data",
"contained",
"in",
"all",
"entries",
"as",
"a",
"list",
"of",
"lists",
"containing",
"all",
"of",
"the",
"data"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L217-L229 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | ButtonGrid.add_row | def add_row(self, data: list):
"""
Add a row of buttons each with their own callbacks to the
current widget. Each element in `data` will consist of a
label and a command.
:param data: a list of tuples of the form ('label', <callback>)
:return: None
"""
#... | python | def add_row(self, data: list):
"""
Add a row of buttons each with their own callbacks to the
current widget. Each element in `data` will consist of a
label and a command.
:param data: a list of tuples of the form ('label', <callback>)
:return: None
"""
#... | [
"def",
"add_row",
"(",
"self",
",",
"data",
":",
"list",
")",
":",
"# validation",
"if",
"self",
".",
"headers",
"and",
"data",
":",
"if",
"len",
"(",
"self",
".",
"headers",
")",
"!=",
"len",
"(",
"data",
")",
":",
"raise",
"ValueError",
"offset",
... | Add a row of buttons each with their own callbacks to the
current widget. Each element in `data` will consist of a
label and a command.
:param data: a list of tuples of the form ('label', <callback>)
:return: None | [
"Add",
"a",
"row",
"of",
"buttons",
"each",
"with",
"their",
"own",
"callbacks",
"to",
"the",
"current",
"widget",
".",
"Each",
"element",
"in",
"data",
"will",
"consist",
"of",
"a",
"label",
"and",
"a",
"command",
".",
":",
"param",
"data",
":",
"a",
... | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L256-L287 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | KeyValueEntry.add_row | def add_row(self, key: str, default: str=None,
unit_label: str=None, enable: bool=None):
"""
Add a single row and re-draw as necessary
:param key: the name and dict accessor
:param default: the default value
:param unit_label: the label that should be \
a... | python | def add_row(self, key: str, default: str=None,
unit_label: str=None, enable: bool=None):
"""
Add a single row and re-draw as necessary
:param key: the name and dict accessor
:param default: the default value
:param unit_label: the label that should be \
a... | [
"def",
"add_row",
"(",
"self",
",",
"key",
":",
"str",
",",
"default",
":",
"str",
"=",
"None",
",",
"unit_label",
":",
"str",
"=",
"None",
",",
"enable",
":",
"bool",
"=",
"None",
")",
":",
"self",
".",
"keys",
".",
"append",
"(",
"ttk",
".",
... | Add a single row and re-draw as necessary
:param key: the name and dict accessor
:param default: the default value
:param unit_label: the label that should be \
applied at the right of the entry
:param enable: the 'enabled' state (defaults to True)
:return: | [
"Add",
"a",
"single",
"row",
"and",
"re",
"-",
"draw",
"as",
"necessary"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L346-L399 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | KeyValueEntry.reset | def reset(self):
"""
Clears all entries.
:return: None
"""
for i in range(len(self.values)):
self.values[i].delete(0, tk.END)
if self.defaults[i] is not None:
self.values[i].insert(0, self.defaults[i]) | python | def reset(self):
"""
Clears all entries.
:return: None
"""
for i in range(len(self.values)):
self.values[i].delete(0, tk.END)
if self.defaults[i] is not None:
self.values[i].insert(0, self.defaults[i]) | [
"def",
"reset",
"(",
"self",
")",
":",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"values",
")",
")",
":",
"self",
".",
"values",
"[",
"i",
"]",
".",
"delete",
"(",
"0",
",",
"tk",
".",
"END",
")",
"if",
"self",
".",
"defaults",... | Clears all entries.
:return: None | [
"Clears",
"all",
"entries",
"."
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L401-L411 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | KeyValueEntry.change_enables | def change_enables(self, enables_list: list):
"""
Enable/disable inputs.
:param enables_list: list containing enables for each key
:return: None
"""
for i, entry in enumerate(self.values):
if enables_list[i]:
entry.config(state=tk.NORMAL)
... | python | def change_enables(self, enables_list: list):
"""
Enable/disable inputs.
:param enables_list: list containing enables for each key
:return: None
"""
for i, entry in enumerate(self.values):
if enables_list[i]:
entry.config(state=tk.NORMAL)
... | [
"def",
"change_enables",
"(",
"self",
",",
"enables_list",
":",
"list",
")",
":",
"for",
"i",
",",
"entry",
"in",
"enumerate",
"(",
"self",
".",
"values",
")",
":",
"if",
"enables_list",
"[",
"i",
"]",
":",
"entry",
".",
"config",
"(",
"state",
"=",
... | Enable/disable inputs.
:param enables_list: list containing enables for each key
:return: None | [
"Enable",
"/",
"disable",
"inputs",
"."
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L413-L424 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | KeyValueEntry.load | def load(self, data: dict):
"""
Load values into the key/values via dict.
:param data: dict containing the key/values that should be inserted
:return: None
"""
for i, label in enumerate(self.keys):
key = label.cget('text')
if key in data.keys():
... | python | def load(self, data: dict):
"""
Load values into the key/values via dict.
:param data: dict containing the key/values that should be inserted
:return: None
"""
for i, label in enumerate(self.keys):
key = label.cget('text')
if key in data.keys():
... | [
"def",
"load",
"(",
"self",
",",
"data",
":",
"dict",
")",
":",
"for",
"i",
",",
"label",
"in",
"enumerate",
"(",
"self",
".",
"keys",
")",
":",
"key",
"=",
"label",
".",
"cget",
"(",
"'text'",
")",
"if",
"key",
"in",
"data",
".",
"keys",
"(",
... | Load values into the key/values via dict.
:param data: dict containing the key/values that should be inserted
:return: None | [
"Load",
"values",
"into",
"the",
"key",
"/",
"values",
"via",
"dict",
"."
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L426-L445 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | KeyValueEntry.get | def get(self):
"""
Retrieve the GUI elements for program use.
:return: a dictionary containing all \
of the data from the key/value entries
"""
data = dict()
for label, entry in zip(self.keys, self.values):
data[label.cget('text')] = entry.get()
... | python | def get(self):
"""
Retrieve the GUI elements for program use.
:return: a dictionary containing all \
of the data from the key/value entries
"""
data = dict()
for label, entry in zip(self.keys, self.values):
data[label.cget('text')] = entry.get()
... | [
"def",
"get",
"(",
"self",
")",
":",
"data",
"=",
"dict",
"(",
")",
"for",
"label",
",",
"entry",
"in",
"zip",
"(",
"self",
".",
"keys",
",",
"self",
".",
"values",
")",
":",
"data",
"[",
"label",
".",
"cget",
"(",
"'text'",
")",
"]",
"=",
"e... | Retrieve the GUI elements for program use.
:return: a dictionary containing all \
of the data from the key/value entries | [
"Retrieve",
"the",
"GUI",
"elements",
"for",
"program",
"use",
"."
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L447-L458 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | Calendar._pressed | def _pressed(self, evt):
"""
Clicked somewhere in the calendar.
"""
x, y, widget = evt.x, evt.y, evt.widget
item = widget.identify_row(y)
column = widget.identify_column(x)
if not column or not (item in self._items):
# clicked in the weekdays row or j... | python | def _pressed(self, evt):
"""
Clicked somewhere in the calendar.
"""
x, y, widget = evt.x, evt.y, evt.widget
item = widget.identify_row(y)
column = widget.identify_column(x)
if not column or not (item in self._items):
# clicked in the weekdays row or j... | [
"def",
"_pressed",
"(",
"self",
",",
"evt",
")",
":",
"x",
",",
"y",
",",
"widget",
"=",
"evt",
".",
"x",
",",
"evt",
".",
"y",
",",
"evt",
".",
"widget",
"item",
"=",
"widget",
".",
"identify_row",
"(",
"y",
")",
"column",
"=",
"widget",
".",
... | Clicked somewhere in the calendar. | [
"Clicked",
"somewhere",
"in",
"the",
"calendar",
"."
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L636-L666 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | _SlotFrame.add | def add(self, string: (str, list)):
"""
Clear the contents of the entry field and
insert the contents of string.
:param string: an str containing the text to display
:return:
"""
if len(self._entries) == 1:
self._entries[0].delete(0, 'end')
... | python | def add(self, string: (str, list)):
"""
Clear the contents of the entry field and
insert the contents of string.
:param string: an str containing the text to display
:return:
"""
if len(self._entries) == 1:
self._entries[0].delete(0, 'end')
... | [
"def",
"add",
"(",
"self",
",",
"string",
":",
"(",
"str",
",",
"list",
")",
")",
":",
"if",
"len",
"(",
"self",
".",
"_entries",
")",
"==",
"1",
":",
"self",
".",
"_entries",
"[",
"0",
"]",
".",
"delete",
"(",
"0",
",",
"'end'",
")",
"self",... | Clear the contents of the entry field and
insert the contents of string.
:param string: an str containing the text to display
:return: | [
"Clear",
"the",
"contents",
"of",
"the",
"entry",
"field",
"and",
"insert",
"the",
"contents",
"of",
"string",
"."
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L736-L754 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | _SlotFrame.remove | def remove(self):
"""
Deletes itself.
:return: None
"""
for e in self._entries:
e.grid_forget()
e.destroy()
self._remove_btn.grid_forget()
self._remove_btn.destroy()
self.deleted = True
if self._remove_callback:
... | python | def remove(self):
"""
Deletes itself.
:return: None
"""
for e in self._entries:
e.grid_forget()
e.destroy()
self._remove_btn.grid_forget()
self._remove_btn.destroy()
self.deleted = True
if self._remove_callback:
... | [
"def",
"remove",
"(",
"self",
")",
":",
"for",
"e",
"in",
"self",
".",
"_entries",
":",
"e",
".",
"grid_forget",
"(",
")",
"e",
".",
"destroy",
"(",
")",
"self",
".",
"_remove_btn",
".",
"grid_forget",
"(",
")",
"self",
".",
"_remove_btn",
".",
"de... | Deletes itself.
:return: None | [
"Deletes",
"itself",
".",
":",
"return",
":",
"None"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L756-L771 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | _SlotFrame.get | def get(self):
"""
Returns the value for the slot.
:return: the entry value
"""
values = [e.get() for e in self._entries]
if len(self._entries) == 1:
return values[0]
else:
return values | python | def get(self):
"""
Returns the value for the slot.
:return: the entry value
"""
values = [e.get() for e in self._entries]
if len(self._entries) == 1:
return values[0]
else:
return values | [
"def",
"get",
"(",
"self",
")",
":",
"values",
"=",
"[",
"e",
".",
"get",
"(",
")",
"for",
"e",
"in",
"self",
".",
"_entries",
"]",
"if",
"len",
"(",
"self",
".",
"_entries",
")",
"==",
"1",
":",
"return",
"values",
"[",
"0",
"]",
"else",
":"... | Returns the value for the slot.
:return: the entry value | [
"Returns",
"the",
"value",
"for",
"the",
"slot",
".",
":",
"return",
":",
"the",
"entry",
"value"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L773-L782 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | MultiSlotFrame._redraw | def _redraw(self):
"""
Clears the current layout and re-draws all elements in self._slots
:return:
"""
if self._blank_label:
self._blank_label.grid_forget()
self._blank_label.destroy()
self._blank_label = None
for slot in self._slots:
... | python | def _redraw(self):
"""
Clears the current layout and re-draws all elements in self._slots
:return:
"""
if self._blank_label:
self._blank_label.grid_forget()
self._blank_label.destroy()
self._blank_label = None
for slot in self._slots:
... | [
"def",
"_redraw",
"(",
"self",
")",
":",
"if",
"self",
".",
"_blank_label",
":",
"self",
".",
"_blank_label",
".",
"grid_forget",
"(",
")",
"self",
".",
"_blank_label",
".",
"destroy",
"(",
")",
"self",
".",
"_blank_label",
"=",
"None",
"for",
"slot",
... | Clears the current layout and re-draws all elements in self._slots
:return: | [
"Clears",
"the",
"current",
"layout",
"and",
"re",
"-",
"draws",
"all",
"elements",
"in",
"self",
".",
"_slots",
":",
"return",
":"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L820-L838 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | MultiSlotFrame.add | def add(self, string: (str, list)):
"""
Add a new slot to the multi-frame containing the string.
:param string: a string to insert
:return: None
"""
slot = _SlotFrame(self,
remove_callback=self._redraw,
entries=self._slo... | python | def add(self, string: (str, list)):
"""
Add a new slot to the multi-frame containing the string.
:param string: a string to insert
:return: None
"""
slot = _SlotFrame(self,
remove_callback=self._redraw,
entries=self._slo... | [
"def",
"add",
"(",
"self",
",",
"string",
":",
"(",
"str",
",",
"list",
")",
")",
":",
"slot",
"=",
"_SlotFrame",
"(",
"self",
",",
"remove_callback",
"=",
"self",
".",
"_redraw",
",",
"entries",
"=",
"self",
".",
"_slot_columns",
")",
"slot",
".",
... | Add a new slot to the multi-frame containing the string.
:param string: a string to insert
:return: None | [
"Add",
"a",
"new",
"slot",
"to",
"the",
"multi",
"-",
"frame",
"containing",
"the",
"string",
".",
":",
"param",
"string",
":",
"a",
"string",
"to",
"insert",
":",
"return",
":",
"None"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L840-L853 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | MultiSlotFrame.clear | def clear(self):
"""
Clear out the multi-frame
:return:
"""
for slot in self._slots:
slot.grid_forget()
slot.destroy()
self._slots = [] | python | def clear(self):
"""
Clear out the multi-frame
:return:
"""
for slot in self._slots:
slot.grid_forget()
slot.destroy()
self._slots = [] | [
"def",
"clear",
"(",
"self",
")",
":",
"for",
"slot",
"in",
"self",
".",
"_slots",
":",
"slot",
".",
"grid_forget",
"(",
")",
"slot",
".",
"destroy",
"(",
")",
"self",
".",
"_slots",
"=",
"[",
"]"
] | Clear out the multi-frame
:return: | [
"Clear",
"out",
"the",
"multi",
"-",
"frame",
":",
"return",
":"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L855-L864 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | SevenSegment.clear | def clear(self):
"""
Clear the segment.
:return: None
"""
for _, frame in self._segments.items():
frame.configure(background=self._bg_color) | python | def clear(self):
"""
Clear the segment.
:return: None
"""
for _, frame in self._segments.items():
frame.configure(background=self._bg_color) | [
"def",
"clear",
"(",
"self",
")",
":",
"for",
"_",
",",
"frame",
"in",
"self",
".",
"_segments",
".",
"items",
"(",
")",
":",
"frame",
".",
"configure",
"(",
"background",
"=",
"self",
".",
"_bg_color",
")"
] | Clear the segment.
:return: None | [
"Clear",
"the",
"segment",
".",
":",
"return",
":",
"None"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L944-L950 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | SevenSegment.set_value | def set_value(self, value: str):
"""
Sets the value of the 7-segment display
:param value: the desired value
:return: None
"""
self.clear()
if '.' in value:
self._segments['period'].configure(background=self._color)
if value in ['0', '0.']:
... | python | def set_value(self, value: str):
"""
Sets the value of the 7-segment display
:param value: the desired value
:return: None
"""
self.clear()
if '.' in value:
self._segments['period'].configure(background=self._color)
if value in ['0', '0.']:
... | [
"def",
"set_value",
"(",
"self",
",",
"value",
":",
"str",
")",
":",
"self",
".",
"clear",
"(",
")",
"if",
"'.'",
"in",
"value",
":",
"self",
".",
"_segments",
"[",
"'period'",
"]",
".",
"configure",
"(",
"background",
"=",
"self",
".",
"_color",
"... | Sets the value of the 7-segment display
:param value: the desired value
:return: None | [
"Sets",
"the",
"value",
"of",
"the",
"7",
"-",
"segment",
"display",
":",
"param",
"value",
":",
"the",
"desired",
"value",
":",
"return",
":",
"None"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L952-L1025 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | SevenSegmentDigits._group | def _group(self, value: str):
"""
Takes a string and groups it appropriately with any
period or other appropriate punctuation so that it is
displayed correctly.
:param value: a string containing an integer or float
:return: None
"""
reversed_v = value[::-1... | python | def _group(self, value: str):
"""
Takes a string and groups it appropriately with any
period or other appropriate punctuation so that it is
displayed correctly.
:param value: a string containing an integer or float
:return: None
"""
reversed_v = value[::-1... | [
"def",
"_group",
"(",
"self",
",",
"value",
":",
"str",
")",
":",
"reversed_v",
"=",
"value",
"[",
":",
":",
"-",
"1",
"]",
"parts",
"=",
"[",
"]",
"has_period",
"=",
"False",
"for",
"c",
"in",
"reversed_v",
":",
"if",
"has_period",
":",
"parts",
... | Takes a string and groups it appropriately with any
period or other appropriate punctuation so that it is
displayed correctly.
:param value: a string containing an integer or float
:return: None | [
"Takes",
"a",
"string",
"and",
"groups",
"it",
"appropriately",
"with",
"any",
"period",
"or",
"other",
"appropriate",
"punctuation",
"so",
"that",
"it",
"is",
"displayed",
"correctly",
".",
":",
"param",
"value",
":",
"a",
"string",
"containing",
"an",
"int... | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L1066-L1090 | train |
slightlynybbled/tk_tools | tk_tools/groups.py | SevenSegmentDigits.set_value | def set_value(self, value: str):
"""
Sets the displayed digits based on the value string.
:param value: a string containing an integer or float value
:return: None
"""
[digit.clear() for digit in self._digits]
grouped = self._group(value) # return the parts, rev... | python | def set_value(self, value: str):
"""
Sets the displayed digits based on the value string.
:param value: a string containing an integer or float value
:return: None
"""
[digit.clear() for digit in self._digits]
grouped = self._group(value) # return the parts, rev... | [
"def",
"set_value",
"(",
"self",
",",
"value",
":",
"str",
")",
":",
"[",
"digit",
".",
"clear",
"(",
")",
"for",
"digit",
"in",
"self",
".",
"_digits",
"]",
"grouped",
"=",
"self",
".",
"_group",
"(",
"value",
")",
"# return the parts, reversed",
"dig... | Sets the displayed digits based on the value string.
:param value: a string containing an integer or float value
:return: None | [
"Sets",
"the",
"displayed",
"digits",
"based",
"on",
"the",
"value",
"string",
".",
":",
"param",
"value",
":",
"a",
"string",
"containing",
"an",
"integer",
"or",
"float",
"value",
":",
"return",
":",
"None"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/groups.py#L1092-L1118 | train |
slightlynybbled/tk_tools | tk_tools/widgets.py | SmartWidget.add_callback | def add_callback(self, callback: callable):
"""
Add a callback on change
:param callback: callable function
:return: None
"""
def internal_callback(*args):
try:
callback()
except TypeError:
callback(self.get())
... | python | def add_callback(self, callback: callable):
"""
Add a callback on change
:param callback: callable function
:return: None
"""
def internal_callback(*args):
try:
callback()
except TypeError:
callback(self.get())
... | [
"def",
"add_callback",
"(",
"self",
",",
"callback",
":",
"callable",
")",
":",
"def",
"internal_callback",
"(",
"*",
"args",
")",
":",
"try",
":",
"callback",
"(",
")",
"except",
"TypeError",
":",
"callback",
"(",
"self",
".",
"get",
"(",
")",
")",
... | Add a callback on change
:param callback: callable function
:return: None | [
"Add",
"a",
"callback",
"on",
"change"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/widgets.py#L18-L31 | train |
slightlynybbled/tk_tools | tk_tools/widgets.py | BinaryLabel.set | def set(self, value: int):
"""
Set the current value
:param value:
:return: None
"""
max_value = int(''.join(['1' for _ in range(self._bit_width)]), 2)
if value > max_value:
raise ValueError('the value {} is larger than '
... | python | def set(self, value: int):
"""
Set the current value
:param value:
:return: None
"""
max_value = int(''.join(['1' for _ in range(self._bit_width)]), 2)
if value > max_value:
raise ValueError('the value {} is larger than '
... | [
"def",
"set",
"(",
"self",
",",
"value",
":",
"int",
")",
":",
"max_value",
"=",
"int",
"(",
"''",
".",
"join",
"(",
"[",
"'1'",
"for",
"_",
"in",
"range",
"(",
"self",
".",
"_bit_width",
")",
"]",
")",
",",
"2",
")",
"if",
"value",
">",
"max... | Set the current value
:param value:
:return: None | [
"Set",
"the",
"current",
"value"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/widgets.py#L217-L231 | train |
slightlynybbled/tk_tools | tk_tools/widgets.py | BinaryLabel.get_bit | def get_bit(self, position: int):
"""
Returns the bit value at position
:param position: integer between 0 and <width>, inclusive
:return: the value at position as a integer
"""
if position > (self._bit_width - 1):
raise ValueError('position greater than the... | python | def get_bit(self, position: int):
"""
Returns the bit value at position
:param position: integer between 0 and <width>, inclusive
:return: the value at position as a integer
"""
if position > (self._bit_width - 1):
raise ValueError('position greater than the... | [
"def",
"get_bit",
"(",
"self",
",",
"position",
":",
"int",
")",
":",
"if",
"position",
">",
"(",
"self",
".",
"_bit_width",
"-",
"1",
")",
":",
"raise",
"ValueError",
"(",
"'position greater than the bit width'",
")",
"if",
"self",
".",
"_value",
"&",
"... | Returns the bit value at position
:param position: integer between 0 and <width>, inclusive
:return: the value at position as a integer | [
"Returns",
"the",
"bit",
"value",
"at",
"position"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/widgets.py#L238-L252 | train |
slightlynybbled/tk_tools | tk_tools/widgets.py | BinaryLabel.toggle_bit | def toggle_bit(self, position: int):
"""
Toggles the value at position
:param position: integer between 0 and 7, inclusive
:return: None
"""
if position > (self._bit_width - 1):
raise ValueError('position greater than the bit width')
self._value ^= (... | python | def toggle_bit(self, position: int):
"""
Toggles the value at position
:param position: integer between 0 and 7, inclusive
:return: None
"""
if position > (self._bit_width - 1):
raise ValueError('position greater than the bit width')
self._value ^= (... | [
"def",
"toggle_bit",
"(",
"self",
",",
"position",
":",
"int",
")",
":",
"if",
"position",
">",
"(",
"self",
".",
"_bit_width",
"-",
"1",
")",
":",
"raise",
"ValueError",
"(",
"'position greater than the bit width'",
")",
"self",
".",
"_value",
"^=",
"(",
... | Toggles the value at position
:param position: integer between 0 and 7, inclusive
:return: None | [
"Toggles",
"the",
"value",
"at",
"position"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/widgets.py#L254-L265 | train |
slightlynybbled/tk_tools | tk_tools/widgets.py | BinaryLabel.set_bit | def set_bit(self, position: int):
"""
Sets the value at position
:param position: integer between 0 and 7, inclusive
:return: None
"""
if position > (self._bit_width - 1):
raise ValueError('position greater than the bit width')
self._value |= (1 << p... | python | def set_bit(self, position: int):
"""
Sets the value at position
:param position: integer between 0 and 7, inclusive
:return: None
"""
if position > (self._bit_width - 1):
raise ValueError('position greater than the bit width')
self._value |= (1 << p... | [
"def",
"set_bit",
"(",
"self",
",",
"position",
":",
"int",
")",
":",
"if",
"position",
">",
"(",
"self",
".",
"_bit_width",
"-",
"1",
")",
":",
"raise",
"ValueError",
"(",
"'position greater than the bit width'",
")",
"self",
".",
"_value",
"|=",
"(",
"... | Sets the value at position
:param position: integer between 0 and 7, inclusive
:return: None | [
"Sets",
"the",
"value",
"at",
"position"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/widgets.py#L267-L278 | train |
slightlynybbled/tk_tools | tk_tools/widgets.py | BinaryLabel.clear_bit | def clear_bit(self, position: int):
"""
Clears the value at position
:param position: integer between 0 and 7, inclusive
:return: None
"""
if position > (self._bit_width - 1):
raise ValueError('position greater than the bit width')
self._value &= ~(1... | python | def clear_bit(self, position: int):
"""
Clears the value at position
:param position: integer between 0 and 7, inclusive
:return: None
"""
if position > (self._bit_width - 1):
raise ValueError('position greater than the bit width')
self._value &= ~(1... | [
"def",
"clear_bit",
"(",
"self",
",",
"position",
":",
"int",
")",
":",
"if",
"position",
">",
"(",
"self",
".",
"_bit_width",
"-",
"1",
")",
":",
"raise",
"ValueError",
"(",
"'position greater than the bit width'",
")",
"self",
".",
"_value",
"&=",
"~",
... | Clears the value at position
:param position: integer between 0 and 7, inclusive
:return: None | [
"Clears",
"the",
"value",
"at",
"position"
] | 7c1792cad42890251a34f0617ce9b4b3e7abcf50 | https://github.com/slightlynybbled/tk_tools/blob/7c1792cad42890251a34f0617ce9b4b3e7abcf50/tk_tools/widgets.py#L280-L291 | train |
willhardy/django-seo | rollyourown/seo/utils.py | LazyList._populate | def _populate(self):
""" Populate this list by calling populate(), but only once. """
if not self._populated:
logging.debug("Populating lazy list %d (%s)" % (id(self), self.__class__.__name__))
try:
self.populate()
self._populated = True
... | python | def _populate(self):
""" Populate this list by calling populate(), but only once. """
if not self._populated:
logging.debug("Populating lazy list %d (%s)" % (id(self), self.__class__.__name__))
try:
self.populate()
self._populated = True
... | [
"def",
"_populate",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_populated",
":",
"logging",
".",
"debug",
"(",
"\"Populating lazy list %d (%s)\"",
"%",
"(",
"id",
"(",
"self",
")",
",",
"self",
".",
"__class__",
".",
"__name__",
")",
")",
"try",
... | Populate this list by calling populate(), but only once. | [
"Populate",
"this",
"list",
"by",
"calling",
"populate",
"()",
"but",
"only",
"once",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/utils.py#L43-L51 | train |
willhardy/django-seo | rollyourown/seo/admin.py | _register_admin | def _register_admin(admin_site, model, admin_class):
""" Register model in the admin, ignoring any previously registered models.
Alternatively it could be used in the future to replace a previously
registered model.
"""
try:
admin_site.register(model, admin_class)
except admin.s... | python | def _register_admin(admin_site, model, admin_class):
""" Register model in the admin, ignoring any previously registered models.
Alternatively it could be used in the future to replace a previously
registered model.
"""
try:
admin_site.register(model, admin_class)
except admin.s... | [
"def",
"_register_admin",
"(",
"admin_site",
",",
"model",
",",
"admin_class",
")",
":",
"try",
":",
"admin_site",
".",
"register",
"(",
"model",
",",
"admin_class",
")",
"except",
"admin",
".",
"sites",
".",
"AlreadyRegistered",
":",
"pass"
] | Register model in the admin, ignoring any previously registered models.
Alternatively it could be used in the future to replace a previously
registered model. | [
"Register",
"model",
"in",
"the",
"admin",
"ignoring",
"any",
"previously",
"registered",
"models",
".",
"Alternatively",
"it",
"could",
"be",
"used",
"in",
"the",
"future",
"to",
"replace",
"a",
"previously",
"registered",
"model",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/admin.py#L81-L89 | train |
willhardy/django-seo | rollyourown/seo/admin.py | core_choice_fields | def core_choice_fields(metadata_class):
""" If the 'optional' core fields (_site and _language) are required,
list them here.
"""
fields = []
if metadata_class._meta.use_sites:
fields.append('_site')
if metadata_class._meta.use_i18n:
fields.append('_language')
return fi... | python | def core_choice_fields(metadata_class):
""" If the 'optional' core fields (_site and _language) are required,
list them here.
"""
fields = []
if metadata_class._meta.use_sites:
fields.append('_site')
if metadata_class._meta.use_i18n:
fields.append('_language')
return fi... | [
"def",
"core_choice_fields",
"(",
"metadata_class",
")",
":",
"fields",
"=",
"[",
"]",
"if",
"metadata_class",
".",
"_meta",
".",
"use_sites",
":",
"fields",
".",
"append",
"(",
"'_site'",
")",
"if",
"metadata_class",
".",
"_meta",
".",
"use_i18n",
":",
"f... | If the 'optional' core fields (_site and _language) are required,
list them here. | [
"If",
"the",
"optional",
"core",
"fields",
"(",
"_site",
"and",
"_language",
")",
"are",
"required",
"list",
"them",
"here",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/admin.py#L187-L196 | train |
willhardy/django-seo | rollyourown/seo/admin.py | _monkey_inline | def _monkey_inline(model, admin_class_instance, metadata_class, inline_class, admin_site):
""" Monkey patch the inline onto the given admin_class instance. """
if model in metadata_class._meta.seo_models:
# *Not* adding to the class attribute "inlines", as this will affect
# all instances from t... | python | def _monkey_inline(model, admin_class_instance, metadata_class, inline_class, admin_site):
""" Monkey patch the inline onto the given admin_class instance. """
if model in metadata_class._meta.seo_models:
# *Not* adding to the class attribute "inlines", as this will affect
# all instances from t... | [
"def",
"_monkey_inline",
"(",
"model",
",",
"admin_class_instance",
",",
"metadata_class",
",",
"inline_class",
",",
"admin_site",
")",
":",
"if",
"model",
"in",
"metadata_class",
".",
"_meta",
".",
"seo_models",
":",
"# *Not* adding to the class attribute \"inlines\", ... | Monkey patch the inline onto the given admin_class instance. | [
"Monkey",
"patch",
"the",
"inline",
"onto",
"the",
"given",
"admin_class",
"instance",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/admin.py#L199-L209 | train |
willhardy/django-seo | rollyourown/seo/admin.py | _with_inline | def _with_inline(func, admin_site, metadata_class, inline_class):
""" Decorator for register function that adds an appropriate inline."""
def register(model_or_iterable, admin_class=None, **options):
# Call the (bound) function we were given.
# We have to assume it will be bound to admin_sit... | python | def _with_inline(func, admin_site, metadata_class, inline_class):
""" Decorator for register function that adds an appropriate inline."""
def register(model_or_iterable, admin_class=None, **options):
# Call the (bound) function we were given.
# We have to assume it will be bound to admin_sit... | [
"def",
"_with_inline",
"(",
"func",
",",
"admin_site",
",",
"metadata_class",
",",
"inline_class",
")",
":",
"def",
"register",
"(",
"model_or_iterable",
",",
"admin_class",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"# Call the (bound) function we were give... | Decorator for register function that adds an appropriate inline. | [
"Decorator",
"for",
"register",
"function",
"that",
"adds",
"an",
"appropriate",
"inline",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/admin.py#L211-L220 | train |
willhardy/django-seo | rollyourown/seo/admin.py | auto_register_inlines | def auto_register_inlines(admin_site, metadata_class):
""" This is a questionable function that automatically adds our metadata
inline to all relevant models in the site.
"""
inline_class = get_inline(metadata_class)
for model, admin_class_instance in admin_site._registry.items():
_mon... | python | def auto_register_inlines(admin_site, metadata_class):
""" This is a questionable function that automatically adds our metadata
inline to all relevant models in the site.
"""
inline_class = get_inline(metadata_class)
for model, admin_class_instance in admin_site._registry.items():
_mon... | [
"def",
"auto_register_inlines",
"(",
"admin_site",
",",
"metadata_class",
")",
":",
"inline_class",
"=",
"get_inline",
"(",
"metadata_class",
")",
"for",
"model",
",",
"admin_class_instance",
"in",
"admin_site",
".",
"_registry",
".",
"items",
"(",
")",
":",
"_m... | This is a questionable function that automatically adds our metadata
inline to all relevant models in the site. | [
"This",
"is",
"a",
"questionable",
"function",
"that",
"automatically",
"adds",
"our",
"metadata",
"inline",
"to",
"all",
"relevant",
"models",
"in",
"the",
"site",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/admin.py#L222-L234 | train |
willhardy/django-seo | rollyourown/seo/base.py | get_linked_metadata | def get_linked_metadata(obj, name=None, context=None, site=None, language=None):
""" Gets metadata linked from the given object. """
# XXX Check that 'modelinstance' and 'model' metadata are installed in backends
# I believe that get_model() would return None if not
Metadata = _get_metadata_model(name)
... | python | def get_linked_metadata(obj, name=None, context=None, site=None, language=None):
""" Gets metadata linked from the given object. """
# XXX Check that 'modelinstance' and 'model' metadata are installed in backends
# I believe that get_model() would return None if not
Metadata = _get_metadata_model(name)
... | [
"def",
"get_linked_metadata",
"(",
"obj",
",",
"name",
"=",
"None",
",",
"context",
"=",
"None",
",",
"site",
"=",
"None",
",",
"language",
"=",
"None",
")",
":",
"# XXX Check that 'modelinstance' and 'model' metadata are installed in backends",
"# I believe that get_mo... | Gets metadata linked from the given object. | [
"Gets",
"metadata",
"linked",
"from",
"the",
"given",
"object",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/base.py#L262-L283 | train |
willhardy/django-seo | rollyourown/seo/base.py | populate_metadata | def populate_metadata(model, MetadataClass):
""" For a given model and metadata class, ensure there is metadata for every instance.
"""
content_type = ContentType.objects.get_for_model(model)
for instance in model.objects.all():
create_metadata_instance(MetadataClass, instance) | python | def populate_metadata(model, MetadataClass):
""" For a given model and metadata class, ensure there is metadata for every instance.
"""
content_type = ContentType.objects.get_for_model(model)
for instance in model.objects.all():
create_metadata_instance(MetadataClass, instance) | [
"def",
"populate_metadata",
"(",
"model",
",",
"MetadataClass",
")",
":",
"content_type",
"=",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"model",
")",
"for",
"instance",
"in",
"model",
".",
"objects",
".",
"all",
"(",
")",
":",
"create_metada... | For a given model and metadata class, ensure there is metadata for every instance. | [
"For",
"a",
"given",
"model",
"and",
"metadata",
"class",
"ensure",
"there",
"is",
"metadata",
"for",
"every",
"instance",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/base.py#L326-L331 | train |
willhardy/django-seo | rollyourown/seo/base.py | FormattedMetadata.__instances | def __instances(self):
""" Cache instances, allowing generators to be used and reused.
This fills a cache as the generator gets emptied, eventually
reading exclusively from the cache.
"""
for instance in self.__instances_cache:
yield instance
for inst... | python | def __instances(self):
""" Cache instances, allowing generators to be used and reused.
This fills a cache as the generator gets emptied, eventually
reading exclusively from the cache.
"""
for instance in self.__instances_cache:
yield instance
for inst... | [
"def",
"__instances",
"(",
"self",
")",
":",
"for",
"instance",
"in",
"self",
".",
"__instances_cache",
":",
"yield",
"instance",
"for",
"instance",
"in",
"self",
".",
"__instances_original",
":",
"self",
".",
"__instances_cache",
".",
"append",
"(",
"instance... | Cache instances, allowing generators to be used and reused.
This fills a cache as the generator gets emptied, eventually
reading exclusively from the cache. | [
"Cache",
"instances",
"allowing",
"generators",
"to",
"be",
"used",
"and",
"reused",
".",
"This",
"fills",
"a",
"cache",
"as",
"the",
"generator",
"gets",
"emptied",
"eventually",
"reading",
"exclusively",
"from",
"the",
"cache",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/base.py#L50-L59 | train |
willhardy/django-seo | rollyourown/seo/base.py | FormattedMetadata._resolve_value | def _resolve_value(self, name):
""" Returns an appropriate value for the given name.
This simply asks each of the instances for a value.
"""
for instance in self.__instances():
value = instance._resolve_value(name)
if value:
return value
... | python | def _resolve_value(self, name):
""" Returns an appropriate value for the given name.
This simply asks each of the instances for a value.
"""
for instance in self.__instances():
value = instance._resolve_value(name)
if value:
return value
... | [
"def",
"_resolve_value",
"(",
"self",
",",
"name",
")",
":",
"for",
"instance",
"in",
"self",
".",
"__instances",
"(",
")",
":",
"value",
"=",
"instance",
".",
"_resolve_value",
"(",
"name",
")",
"if",
"value",
":",
"return",
"value",
"# Otherwise, return ... | Returns an appropriate value for the given name.
This simply asks each of the instances for a value. | [
"Returns",
"an",
"appropriate",
"value",
"for",
"the",
"given",
"name",
".",
"This",
"simply",
"asks",
"each",
"of",
"the",
"instances",
"for",
"a",
"value",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/base.py#L61-L79 | train |
willhardy/django-seo | rollyourown/seo/base.py | MetadataBase._get_formatted_data | def _get_formatted_data(cls, path, context=None, site=None, language=None):
""" Return an object to conveniently access the appropriate values. """
return FormattedMetadata(cls(), cls._get_instances(path, context, site, language), path, site, language) | python | def _get_formatted_data(cls, path, context=None, site=None, language=None):
""" Return an object to conveniently access the appropriate values. """
return FormattedMetadata(cls(), cls._get_instances(path, context, site, language), path, site, language) | [
"def",
"_get_formatted_data",
"(",
"cls",
",",
"path",
",",
"context",
"=",
"None",
",",
"site",
"=",
"None",
",",
"language",
"=",
"None",
")",
":",
"return",
"FormattedMetadata",
"(",
"cls",
"(",
")",
",",
"cls",
".",
"_get_instances",
"(",
"path",
"... | Return an object to conveniently access the appropriate values. | [
"Return",
"an",
"object",
"to",
"conveniently",
"access",
"the",
"appropriate",
"values",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/base.py#L217-L219 | train |
willhardy/django-seo | rollyourown/seo/base.py | MetadataBase._get_instances | def _get_instances(cls, path, context=None, site=None, language=None):
""" A sequence of instances to discover metadata.
Each instance from each backend is looked up when possible/necessary.
This is a generator to eliminate unnecessary queries.
"""
backend_context = {'vi... | python | def _get_instances(cls, path, context=None, site=None, language=None):
""" A sequence of instances to discover metadata.
Each instance from each backend is looked up when possible/necessary.
This is a generator to eliminate unnecessary queries.
"""
backend_context = {'vi... | [
"def",
"_get_instances",
"(",
"cls",
",",
"path",
",",
"context",
"=",
"None",
",",
"site",
"=",
"None",
",",
"language",
"=",
"None",
")",
":",
"backend_context",
"=",
"{",
"'view_context'",
":",
"context",
"}",
"for",
"model",
"in",
"cls",
".",
"_met... | A sequence of instances to discover metadata.
Each instance from each backend is looked up when possible/necessary.
This is a generator to eliminate unnecessary queries. | [
"A",
"sequence",
"of",
"instances",
"to",
"discover",
"metadata",
".",
"Each",
"instance",
"from",
"each",
"backend",
"is",
"looked",
"up",
"when",
"possible",
"/",
"necessary",
".",
"This",
"is",
"a",
"generator",
"to",
"eliminate",
"unnecessary",
"queries",
... | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/base.py#L223-L234 | train |
willhardy/django-seo | rollyourown/seo/backends.py | _resolve | def _resolve(value, model_instance=None, context=None):
""" Resolves any template references in the given value.
"""
if isinstance(value, basestring) and "{" in value:
if context is None:
context = Context()
if model_instance is not None:
context[model_instance._met... | python | def _resolve(value, model_instance=None, context=None):
""" Resolves any template references in the given value.
"""
if isinstance(value, basestring) and "{" in value:
if context is None:
context = Context()
if model_instance is not None:
context[model_instance._met... | [
"def",
"_resolve",
"(",
"value",
",",
"model_instance",
"=",
"None",
",",
"context",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"basestring",
")",
"and",
"\"{\"",
"in",
"value",
":",
"if",
"context",
"is",
"None",
":",
"context",
"="... | Resolves any template references in the given value. | [
"Resolves",
"any",
"template",
"references",
"in",
"the",
"given",
"value",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/backends.py#L331-L341 | train |
willhardy/django-seo | rollyourown/seo/backends.py | ModelBackend.validate | def validate(options):
""" Validates the application of this backend to a given metadata
"""
try:
if options.backends.index('modelinstance') > options.backends.index('model'):
raise Exception("Metadata backend 'modelinstance' must come before 'model' backend")
... | python | def validate(options):
""" Validates the application of this backend to a given metadata
"""
try:
if options.backends.index('modelinstance') > options.backends.index('model'):
raise Exception("Metadata backend 'modelinstance' must come before 'model' backend")
... | [
"def",
"validate",
"(",
"options",
")",
":",
"try",
":",
"if",
"options",
".",
"backends",
".",
"index",
"(",
"'modelinstance'",
")",
">",
"options",
".",
"backends",
".",
"index",
"(",
"'model'",
")",
":",
"raise",
"Exception",
"(",
"\"Metadata backend 'm... | Validates the application of this backend to a given metadata | [
"Validates",
"the",
"application",
"of",
"this",
"backend",
"to",
"a",
"given",
"metadata"
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/backends.py#L320-L327 | train |
willhardy/django-seo | rollyourown/seo/options.py | Options._register_elements | def _register_elements(self, elements):
""" Takes elements from the metadata class and creates a base model for all backend models .
"""
self.elements = elements
for key, obj in elements.items():
obj.contribute_to_class(self.metadata, key)
# Create the common Django... | python | def _register_elements(self, elements):
""" Takes elements from the metadata class and creates a base model for all backend models .
"""
self.elements = elements
for key, obj in elements.items():
obj.contribute_to_class(self.metadata, key)
# Create the common Django... | [
"def",
"_register_elements",
"(",
"self",
",",
"elements",
")",
":",
"self",
".",
"elements",
"=",
"elements",
"for",
"key",
",",
"obj",
"in",
"elements",
".",
"items",
"(",
")",
":",
"obj",
".",
"contribute_to_class",
"(",
"self",
".",
"metadata",
",",
... | Takes elements from the metadata class and creates a base model for all backend models . | [
"Takes",
"elements",
"from",
"the",
"metadata",
"class",
"and",
"creates",
"a",
"base",
"model",
"for",
"all",
"backend",
"models",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/options.py#L38-L64 | train |
willhardy/django-seo | rollyourown/seo/options.py | Options._add_backend | def _add_backend(self, backend):
""" Builds a subclass model for the given backend """
md_type = backend.verbose_name
base = backend().get_model(self)
# TODO: Rename this field
new_md_attrs = {'_metadata': self.metadata, '__module__': __name__ }
new_md_meta = {}
... | python | def _add_backend(self, backend):
""" Builds a subclass model for the given backend """
md_type = backend.verbose_name
base = backend().get_model(self)
# TODO: Rename this field
new_md_attrs = {'_metadata': self.metadata, '__module__': __name__ }
new_md_meta = {}
... | [
"def",
"_add_backend",
"(",
"self",
",",
"backend",
")",
":",
"md_type",
"=",
"backend",
".",
"verbose_name",
"base",
"=",
"backend",
"(",
")",
".",
"get_model",
"(",
"self",
")",
"# TODO: Rename this field",
"new_md_attrs",
"=",
"{",
"'_metadata'",
":",
"se... | Builds a subclass model for the given backend | [
"Builds",
"a",
"subclass",
"model",
"for",
"the",
"given",
"backend"
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/options.py#L66-L82 | train |
willhardy/django-seo | rollyourown/seo/options.py | Options._set_seo_models | def _set_seo_models(self, value):
""" Gets the actual models to be used. """
seo_models = []
for model_name in value:
if "." in model_name:
app_label, model_name = model_name.split(".", 1)
model = models.get_model(app_label, model_name)
... | python | def _set_seo_models(self, value):
""" Gets the actual models to be used. """
seo_models = []
for model_name in value:
if "." in model_name:
app_label, model_name = model_name.split(".", 1)
model = models.get_model(app_label, model_name)
... | [
"def",
"_set_seo_models",
"(",
"self",
",",
"value",
")",
":",
"seo_models",
"=",
"[",
"]",
"for",
"model_name",
"in",
"value",
":",
"if",
"\".\"",
"in",
"model_name",
":",
"app_label",
",",
"model_name",
"=",
"model_name",
".",
"split",
"(",
"\".\"",
",... | Gets the actual models to be used. | [
"Gets",
"the",
"actual",
"models",
"to",
"be",
"used",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/options.py#L84-L98 | train |
willhardy/django-seo | rollyourown/seo/fields.py | MetadataField.validate | def validate(self):
""" Discover certain illegal configurations """
if not self.editable:
assert self.populate_from is not NotSet, u"If field (%s) is not editable, you must set populate_from" % self.name | python | def validate(self):
""" Discover certain illegal configurations """
if not self.editable:
assert self.populate_from is not NotSet, u"If field (%s) is not editable, you must set populate_from" % self.name | [
"def",
"validate",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"editable",
":",
"assert",
"self",
".",
"populate_from",
"is",
"not",
"NotSet",
",",
"u\"If field (%s) is not editable, you must set populate_from\"",
"%",
"self",
".",
"name"
] | Discover certain illegal configurations | [
"Discover",
"certain",
"illegal",
"configurations"
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/fields.py#L72-L75 | train |
willhardy/django-seo | rollyourown/seo/management/__init__.py | populate_all_metadata | def populate_all_metadata():
""" Create metadata instances for all models in seo_models if empty.
Once you have created a single metadata instance, this will not run.
This is because it is a potentially slow operation that need only be
done once. If you want to ensure that everything is popu... | python | def populate_all_metadata():
""" Create metadata instances for all models in seo_models if empty.
Once you have created a single metadata instance, this will not run.
This is because it is a potentially slow operation that need only be
done once. If you want to ensure that everything is popu... | [
"def",
"populate_all_metadata",
"(",
")",
":",
"for",
"Metadata",
"in",
"registry",
".",
"values",
"(",
")",
":",
"InstanceMetadata",
"=",
"Metadata",
".",
"_meta",
".",
"get_model",
"(",
"'modelinstance'",
")",
"if",
"InstanceMetadata",
"is",
"not",
"None",
... | Create metadata instances for all models in seo_models if empty.
Once you have created a single metadata instance, this will not run.
This is because it is a potentially slow operation that need only be
done once. If you want to ensure that everything is populated, run the
populate_metad... | [
"Create",
"metadata",
"instances",
"for",
"all",
"models",
"in",
"seo_models",
"if",
"empty",
".",
"Once",
"you",
"have",
"created",
"a",
"single",
"metadata",
"instance",
"this",
"will",
"not",
"run",
".",
"This",
"is",
"because",
"it",
"is",
"a",
"potent... | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/management/__init__.py#L30-L41 | train |
willhardy/django-seo | rollyourown/seo/systemviews.py | SystemViews.populate | def populate(self):
""" Populate this list with all views that take no arguments.
"""
from django.conf import settings
from django.core import urlresolvers
self.append(("", ""))
urlconf = settings.ROOT_URLCONF
resolver = urlresolvers.RegexURLResolver(r'^/', urlco... | python | def populate(self):
""" Populate this list with all views that take no arguments.
"""
from django.conf import settings
from django.core import urlresolvers
self.append(("", ""))
urlconf = settings.ROOT_URLCONF
resolver = urlresolvers.RegexURLResolver(r'^/', urlco... | [
"def",
"populate",
"(",
"self",
")",
":",
"from",
"django",
".",
"conf",
"import",
"settings",
"from",
"django",
".",
"core",
"import",
"urlresolvers",
"self",
".",
"append",
"(",
"(",
"\"\"",
",",
"\"\"",
")",
")",
"urlconf",
"=",
"settings",
".",
"RO... | Populate this list with all views that take no arguments. | [
"Populate",
"this",
"list",
"with",
"all",
"views",
"that",
"take",
"no",
"arguments",
"."
] | 3089686a3c490091315860979ad15ef2527c3e3e | https://github.com/willhardy/django-seo/blob/3089686a3c490091315860979ad15ef2527c3e3e/rollyourown/seo/systemviews.py#L43-L65 | train |
geomet/geomet | geomet/util.py | block_splitter | def block_splitter(data, block_size):
"""
Creates a generator by slicing ``data`` into chunks of ``block_size``.
>>> data = range(10)
>>> list(block_splitter(data, 2))
[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]
If ``data`` cannot be evenly divided by ``block_size``, the last block will
simpl... | python | def block_splitter(data, block_size):
"""
Creates a generator by slicing ``data`` into chunks of ``block_size``.
>>> data = range(10)
>>> list(block_splitter(data, 2))
[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]
If ``data`` cannot be evenly divided by ``block_size``, the last block will
simpl... | [
"def",
"block_splitter",
"(",
"data",
",",
"block_size",
")",
":",
"buf",
"=",
"[",
"]",
"for",
"i",
",",
"datum",
"in",
"enumerate",
"(",
"data",
")",
":",
"buf",
".",
"append",
"(",
"datum",
")",
"if",
"len",
"(",
"buf",
")",
"==",
"block_size",
... | Creates a generator by slicing ``data`` into chunks of ``block_size``.
>>> data = range(10)
>>> list(block_splitter(data, 2))
[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]
If ``data`` cannot be evenly divided by ``block_size``, the last block will
simply be the remainder of the data. Example:
>>> ... | [
"Creates",
"a",
"generator",
"by",
"slicing",
"data",
"into",
"chunks",
"of",
"block_size",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/util.py#L19-L57 | train |
geomet/geomet | geomet/util.py | round_geom | def round_geom(geom, precision=None):
"""Round coordinates of a geometric object to given precision."""
if geom['type'] == 'Point':
x, y = geom['coordinates']
xp, yp = [x], [y]
if precision is not None:
xp = [round(v, precision) for v in xp]
yp = [round(v, precisi... | python | def round_geom(geom, precision=None):
"""Round coordinates of a geometric object to given precision."""
if geom['type'] == 'Point':
x, y = geom['coordinates']
xp, yp = [x], [y]
if precision is not None:
xp = [round(v, precision) for v in xp]
yp = [round(v, precisi... | [
"def",
"round_geom",
"(",
"geom",
",",
"precision",
"=",
"None",
")",
":",
"if",
"geom",
"[",
"'type'",
"]",
"==",
"'Point'",
":",
"x",
",",
"y",
"=",
"geom",
"[",
"'coordinates'",
"]",
"xp",
",",
"yp",
"=",
"[",
"x",
"]",
",",
"[",
"y",
"]",
... | Round coordinates of a geometric object to given precision. | [
"Round",
"coordinates",
"of",
"a",
"geometric",
"object",
"to",
"given",
"precision",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/util.py#L77-L112 | train |
geomet/geomet | geomet/util.py | flatten_multi_dim | def flatten_multi_dim(sequence):
"""Flatten a multi-dimensional array-like to a single dimensional sequence
(as a generator).
"""
for x in sequence:
if (isinstance(x, collections.Iterable)
and not isinstance(x, six.string_types)):
for y in flatten_multi_dim(x):
... | python | def flatten_multi_dim(sequence):
"""Flatten a multi-dimensional array-like to a single dimensional sequence
(as a generator).
"""
for x in sequence:
if (isinstance(x, collections.Iterable)
and not isinstance(x, six.string_types)):
for y in flatten_multi_dim(x):
... | [
"def",
"flatten_multi_dim",
"(",
"sequence",
")",
":",
"for",
"x",
"in",
"sequence",
":",
"if",
"(",
"isinstance",
"(",
"x",
",",
"collections",
".",
"Iterable",
")",
"and",
"not",
"isinstance",
"(",
"x",
",",
"six",
".",
"string_types",
")",
")",
":",... | Flatten a multi-dimensional array-like to a single dimensional sequence
(as a generator). | [
"Flatten",
"a",
"multi",
"-",
"dimensional",
"array",
"-",
"like",
"to",
"a",
"single",
"dimensional",
"sequence",
"(",
"as",
"a",
"generator",
")",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/util.py#L115-L125 | train |
geomet/geomet | geomet/tool.py | cli | def cli(input, verbose, quiet, output_format, precision, indent):
"""Convert text read from the first positional argument, stdin, or
a file to GeoJSON and write to stdout."""
verbosity = verbose - quiet
configure_logging(verbosity)
logger = logging.getLogger('geomet')
# Handle the case of file... | python | def cli(input, verbose, quiet, output_format, precision, indent):
"""Convert text read from the first positional argument, stdin, or
a file to GeoJSON and write to stdout."""
verbosity = verbose - quiet
configure_logging(verbosity)
logger = logging.getLogger('geomet')
# Handle the case of file... | [
"def",
"cli",
"(",
"input",
",",
"verbose",
",",
"quiet",
",",
"output_format",
",",
"precision",
",",
"indent",
")",
":",
"verbosity",
"=",
"verbose",
"-",
"quiet",
"configure_logging",
"(",
"verbosity",
")",
"logger",
"=",
"logging",
".",
"getLogger",
"(... | Convert text read from the first positional argument, stdin, or
a file to GeoJSON and write to stdout. | [
"Convert",
"text",
"read",
"from",
"the",
"first",
"positional",
"argument",
"stdin",
"or",
"a",
"file",
"to",
"GeoJSON",
"and",
"write",
"to",
"stdout",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/tool.py#L83-L116 | train |
geomet/geomet | geomet/wkb.py | _get_geom_type | def _get_geom_type(type_bytes):
"""Get the GeoJSON geometry type label from a WKB type byte string.
:param type_bytes:
4 byte string in big endian byte order containing a WKB type number.
It may also contain a "has SRID" flag in the high byte (the first type,
since this is big endian by... | python | def _get_geom_type(type_bytes):
"""Get the GeoJSON geometry type label from a WKB type byte string.
:param type_bytes:
4 byte string in big endian byte order containing a WKB type number.
It may also contain a "has SRID" flag in the high byte (the first type,
since this is big endian by... | [
"def",
"_get_geom_type",
"(",
"type_bytes",
")",
":",
"# slice off the high byte, which may contain the SRID flag",
"high_byte",
"=",
"type_bytes",
"[",
"0",
"]",
"if",
"six",
".",
"PY3",
":",
"high_byte",
"=",
"bytes",
"(",
"[",
"high_byte",
"]",
")",
"has_srid",... | Get the GeoJSON geometry type label from a WKB type byte string.
:param type_bytes:
4 byte string in big endian byte order containing a WKB type number.
It may also contain a "has SRID" flag in the high byte (the first type,
since this is big endian byte order), indicated as 0x20. If the SR... | [
"Get",
"the",
"GeoJSON",
"geometry",
"type",
"label",
"from",
"a",
"WKB",
"type",
"byte",
"string",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkb.py#L110-L147 | train |
geomet/geomet | geomet/wkb.py | dumps | def dumps(obj, big_endian=True):
"""
Dump a GeoJSON-like `dict` to a WKB string.
.. note::
The dimensions of the generated WKB will be inferred from the first
vertex in the GeoJSON `coordinates`. It will be assumed that all
vertices are uniform. There are 4 types:
- 2D (X, ... | python | def dumps(obj, big_endian=True):
"""
Dump a GeoJSON-like `dict` to a WKB string.
.. note::
The dimensions of the generated WKB will be inferred from the first
vertex in the GeoJSON `coordinates`. It will be assumed that all
vertices are uniform. There are 4 types:
- 2D (X, ... | [
"def",
"dumps",
"(",
"obj",
",",
"big_endian",
"=",
"True",
")",
":",
"geom_type",
"=",
"obj",
"[",
"'type'",
"]",
"meta",
"=",
"obj",
".",
"get",
"(",
"'meta'",
",",
"{",
"}",
")",
"exporter",
"=",
"_dumps_registry",
".",
"get",
"(",
"geom_type",
... | Dump a GeoJSON-like `dict` to a WKB string.
.. note::
The dimensions of the generated WKB will be inferred from the first
vertex in the GeoJSON `coordinates`. It will be assumed that all
vertices are uniform. There are 4 types:
- 2D (X, Y): 2-dimensional geometry
- Z (X, Y,... | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"dict",
"to",
"a",
"WKB",
"string",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkb.py#L177-L246 | train |
geomet/geomet | geomet/wkb.py | loads | def loads(string):
"""
Construct a GeoJSON `dict` from WKB (`string`).
The resulting GeoJSON `dict` will include the SRID as an integer in the
`meta` object. This was an arbitrary decision made by `geomet, the
discussion of which took place here:
https://github.com/geomet/geomet/issues/28.
... | python | def loads(string):
"""
Construct a GeoJSON `dict` from WKB (`string`).
The resulting GeoJSON `dict` will include the SRID as an integer in the
`meta` object. This was an arbitrary decision made by `geomet, the
discussion of which took place here:
https://github.com/geomet/geomet/issues/28.
... | [
"def",
"loads",
"(",
"string",
")",
":",
"# noqa",
"string",
"=",
"iter",
"(",
"string",
")",
"# endianness = string[0:1]",
"endianness",
"=",
"as_bin_str",
"(",
"take",
"(",
"1",
",",
"string",
")",
")",
"if",
"endianness",
"==",
"BIG_ENDIAN",
":",
"big_e... | Construct a GeoJSON `dict` from WKB (`string`).
The resulting GeoJSON `dict` will include the SRID as an integer in the
`meta` object. This was an arbitrary decision made by `geomet, the
discussion of which took place here:
https://github.com/geomet/geomet/issues/28.
In order to be consistent with... | [
"Construct",
"a",
"GeoJSON",
"dict",
"from",
"WKB",
"(",
"string",
")",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkb.py#L249-L331 | train |
geomet/geomet | geomet/wkb.py | _header_bytefmt_byteorder | def _header_bytefmt_byteorder(geom_type, num_dims, big_endian, meta=None):
"""
Utility function to get the WKB header (endian byte + type header), byte
format string, and byte order string.
"""
dim = _INT_TO_DIM_LABEL.get(num_dims)
if dim is None:
pass # TODO: raise
type_byte_str =... | python | def _header_bytefmt_byteorder(geom_type, num_dims, big_endian, meta=None):
"""
Utility function to get the WKB header (endian byte + type header), byte
format string, and byte order string.
"""
dim = _INT_TO_DIM_LABEL.get(num_dims)
if dim is None:
pass # TODO: raise
type_byte_str =... | [
"def",
"_header_bytefmt_byteorder",
"(",
"geom_type",
",",
"num_dims",
",",
"big_endian",
",",
"meta",
"=",
"None",
")",
":",
"dim",
"=",
"_INT_TO_DIM_LABEL",
".",
"get",
"(",
"num_dims",
")",
"if",
"dim",
"is",
"None",
":",
"pass",
"# TODO: raise",
"type_by... | Utility function to get the WKB header (endian byte + type header), byte
format string, and byte order string. | [
"Utility",
"function",
"to",
"get",
"the",
"WKB",
"header",
"(",
"endian",
"byte",
"+",
"type",
"header",
")",
"byte",
"format",
"string",
"and",
"byte",
"order",
"string",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkb.py#L339-L376 | train |
geomet/geomet | geomet/wkb.py | _dump_point | def _dump_point(obj, big_endian, meta):
"""
Dump a GeoJSON-like `dict` to a point WKB string.
:param dict obj:
GeoJson-like `dict` object.
:param bool big_endian:
If `True`, data values in the generated WKB will be represented using
big endian byte order. Else, little endian.
... | python | def _dump_point(obj, big_endian, meta):
"""
Dump a GeoJSON-like `dict` to a point WKB string.
:param dict obj:
GeoJson-like `dict` object.
:param bool big_endian:
If `True`, data values in the generated WKB will be represented using
big endian byte order. Else, little endian.
... | [
"def",
"_dump_point",
"(",
"obj",
",",
"big_endian",
",",
"meta",
")",
":",
"coords",
"=",
"obj",
"[",
"'coordinates'",
"]",
"num_dims",
"=",
"len",
"(",
"coords",
")",
"wkb_string",
",",
"byte_fmt",
",",
"_",
"=",
"_header_bytefmt_byteorder",
"(",
"'Point... | Dump a GeoJSON-like `dict` to a point WKB string.
:param dict obj:
GeoJson-like `dict` object.
:param bool big_endian:
If `True`, data values in the generated WKB will be represented using
big endian byte order. Else, little endian.
:param dict meta:
Metadata associated with... | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"dict",
"to",
"a",
"point",
"WKB",
"string",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkb.py#L379-L411 | train |
geomet/geomet | geomet/wkb.py | _dump_linestring | def _dump_linestring(obj, big_endian, meta):
"""
Dump a GeoJSON-like `dict` to a linestring WKB string.
Input parameters and output are similar to :func:`_dump_point`.
"""
coords = obj['coordinates']
vertex = coords[0]
# Infer the number of dimensions from the first vertex
num_dims = le... | python | def _dump_linestring(obj, big_endian, meta):
"""
Dump a GeoJSON-like `dict` to a linestring WKB string.
Input parameters and output are similar to :func:`_dump_point`.
"""
coords = obj['coordinates']
vertex = coords[0]
# Infer the number of dimensions from the first vertex
num_dims = le... | [
"def",
"_dump_linestring",
"(",
"obj",
",",
"big_endian",
",",
"meta",
")",
":",
"coords",
"=",
"obj",
"[",
"'coordinates'",
"]",
"vertex",
"=",
"coords",
"[",
"0",
"]",
"# Infer the number of dimensions from the first vertex",
"num_dims",
"=",
"len",
"(",
"vert... | Dump a GeoJSON-like `dict` to a linestring WKB string.
Input parameters and output are similar to :func:`_dump_point`. | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"dict",
"to",
"a",
"linestring",
"WKB",
"string",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkb.py#L414-L434 | train |
geomet/geomet | geomet/wkb.py | _dump_multipoint | def _dump_multipoint(obj, big_endian, meta):
"""
Dump a GeoJSON-like `dict` to a multipoint WKB string.
Input parameters and output are similar to :funct:`_dump_point`.
"""
coords = obj['coordinates']
vertex = coords[0]
num_dims = len(vertex)
wkb_string, byte_fmt, byte_order = _header_... | python | def _dump_multipoint(obj, big_endian, meta):
"""
Dump a GeoJSON-like `dict` to a multipoint WKB string.
Input parameters and output are similar to :funct:`_dump_point`.
"""
coords = obj['coordinates']
vertex = coords[0]
num_dims = len(vertex)
wkb_string, byte_fmt, byte_order = _header_... | [
"def",
"_dump_multipoint",
"(",
"obj",
",",
"big_endian",
",",
"meta",
")",
":",
"coords",
"=",
"obj",
"[",
"'coordinates'",
"]",
"vertex",
"=",
"coords",
"[",
"0",
"]",
"num_dims",
"=",
"len",
"(",
"vertex",
")",
"wkb_string",
",",
"byte_fmt",
",",
"b... | Dump a GeoJSON-like `dict` to a multipoint WKB string.
Input parameters and output are similar to :funct:`_dump_point`. | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"dict",
"to",
"a",
"multipoint",
"WKB",
"string",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkb.py#L463-L489 | train |
geomet/geomet | geomet/wkb.py | _dump_multilinestring | def _dump_multilinestring(obj, big_endian, meta):
"""
Dump a GeoJSON-like `dict` to a multilinestring WKB string.
Input parameters and output are similar to :funct:`_dump_point`.
"""
coords = obj['coordinates']
vertex = coords[0][0]
num_dims = len(vertex)
wkb_string, byte_fmt, byte_ord... | python | def _dump_multilinestring(obj, big_endian, meta):
"""
Dump a GeoJSON-like `dict` to a multilinestring WKB string.
Input parameters and output are similar to :funct:`_dump_point`.
"""
coords = obj['coordinates']
vertex = coords[0][0]
num_dims = len(vertex)
wkb_string, byte_fmt, byte_ord... | [
"def",
"_dump_multilinestring",
"(",
"obj",
",",
"big_endian",
",",
"meta",
")",
":",
"coords",
"=",
"obj",
"[",
"'coordinates'",
"]",
"vertex",
"=",
"coords",
"[",
"0",
"]",
"[",
"0",
"]",
"num_dims",
"=",
"len",
"(",
"vertex",
")",
"wkb_string",
",",... | Dump a GeoJSON-like `dict` to a multilinestring WKB string.
Input parameters and output are similar to :funct:`_dump_point`. | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"dict",
"to",
"a",
"multilinestring",
"WKB",
"string",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkb.py#L492-L522 | train |
geomet/geomet | geomet/wkb.py | _dump_multipolygon | def _dump_multipolygon(obj, big_endian, meta):
"""
Dump a GeoJSON-like `dict` to a multipolygon WKB string.
Input parameters and output are similar to :funct:`_dump_point`.
"""
coords = obj['coordinates']
vertex = coords[0][0][0]
num_dims = len(vertex)
wkb_string, byte_fmt, byte_order ... | python | def _dump_multipolygon(obj, big_endian, meta):
"""
Dump a GeoJSON-like `dict` to a multipolygon WKB string.
Input parameters and output are similar to :funct:`_dump_point`.
"""
coords = obj['coordinates']
vertex = coords[0][0][0]
num_dims = len(vertex)
wkb_string, byte_fmt, byte_order ... | [
"def",
"_dump_multipolygon",
"(",
"obj",
",",
"big_endian",
",",
"meta",
")",
":",
"coords",
"=",
"obj",
"[",
"'coordinates'",
"]",
"vertex",
"=",
"coords",
"[",
"0",
"]",
"[",
"0",
"]",
"[",
"0",
"]",
"num_dims",
"=",
"len",
"(",
"vertex",
")",
"w... | Dump a GeoJSON-like `dict` to a multipolygon WKB string.
Input parameters and output are similar to :funct:`_dump_point`. | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"dict",
"to",
"a",
"multipolygon",
"WKB",
"string",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkb.py#L525-L559 | train |
geomet/geomet | geomet/wkb.py | _load_point | def _load_point(big_endian, type_bytes, data_bytes):
"""
Convert byte data for a Point to a GeoJSON `dict`.
:param bool big_endian:
If `True`, interpret the ``data_bytes`` in big endian order, else
little endian.
:param str type_bytes:
4-byte integer (as a binary string) indicat... | python | def _load_point(big_endian, type_bytes, data_bytes):
"""
Convert byte data for a Point to a GeoJSON `dict`.
:param bool big_endian:
If `True`, interpret the ``data_bytes`` in big endian order, else
little endian.
:param str type_bytes:
4-byte integer (as a binary string) indicat... | [
"def",
"_load_point",
"(",
"big_endian",
",",
"type_bytes",
",",
"data_bytes",
")",
":",
"endian_token",
"=",
"'>'",
"if",
"big_endian",
"else",
"'<'",
"if",
"type_bytes",
"==",
"WKB_2D",
"[",
"'Point'",
"]",
":",
"coords",
"=",
"struct",
".",
"unpack",
"(... | Convert byte data for a Point to a GeoJSON `dict`.
:param bool big_endian:
If `True`, interpret the ``data_bytes`` in big endian order, else
little endian.
:param str type_bytes:
4-byte integer (as a binary string) indicating the geometry type
(Point) and the dimensions (2D, Z, ... | [
"Convert",
"byte",
"data",
"for",
"a",
"Point",
"to",
"a",
"GeoJSON",
"dict",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkb.py#L595-L633 | train |
geomet/geomet | geomet/wkt.py | dumps | def dumps(obj, decimals=16):
"""
Dump a GeoJSON-like `dict` to a WKT string.
"""
try:
geom_type = obj['type']
exporter = _dumps_registry.get(geom_type)
if exporter is None:
_unsupported_geom_type(geom_type)
# Check for empty cases
if geom_type == 'Ge... | python | def dumps(obj, decimals=16):
"""
Dump a GeoJSON-like `dict` to a WKT string.
"""
try:
geom_type = obj['type']
exporter = _dumps_registry.get(geom_type)
if exporter is None:
_unsupported_geom_type(geom_type)
# Check for empty cases
if geom_type == 'Ge... | [
"def",
"dumps",
"(",
"obj",
",",
"decimals",
"=",
"16",
")",
":",
"try",
":",
"geom_type",
"=",
"obj",
"[",
"'type'",
"]",
"exporter",
"=",
"_dumps_registry",
".",
"get",
"(",
"geom_type",
")",
"if",
"exporter",
"is",
"None",
":",
"_unsupported_geom_type... | Dump a GeoJSON-like `dict` to a WKT string. | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"dict",
"to",
"a",
"WKT",
"string",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L57-L100 | train |
geomet/geomet | geomet/wkt.py | loads | def loads(string):
"""
Construct a GeoJSON `dict` from WKT (`string`).
"""
sio = StringIO.StringIO(string)
# NOTE: This is not the intended purpose of `tokenize`, but it works.
tokens = (x[1] for x in tokenize.generate_tokens(sio.readline))
tokens = _tokenize_wkt(tokens)
geom_type_or_sri... | python | def loads(string):
"""
Construct a GeoJSON `dict` from WKT (`string`).
"""
sio = StringIO.StringIO(string)
# NOTE: This is not the intended purpose of `tokenize`, but it works.
tokens = (x[1] for x in tokenize.generate_tokens(sio.readline))
tokens = _tokenize_wkt(tokens)
geom_type_or_sri... | [
"def",
"loads",
"(",
"string",
")",
":",
"sio",
"=",
"StringIO",
".",
"StringIO",
"(",
"string",
")",
"# NOTE: This is not the intended purpose of `tokenize`, but it works.",
"tokens",
"=",
"(",
"x",
"[",
"1",
"]",
"for",
"x",
"in",
"tokenize",
".",
"generate_to... | Construct a GeoJSON `dict` from WKT (`string`). | [
"Construct",
"a",
"GeoJSON",
"dict",
"from",
"WKT",
"(",
"string",
")",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L111-L150 | train |
geomet/geomet | geomet/wkt.py | _tokenize_wkt | def _tokenize_wkt(tokens):
"""
Since the tokenizer treats "-" and numeric strings as separate values,
combine them and yield them as a single token. This utility encapsulates
parsing of negative numeric values from WKT can be used generically in all
parsers.
"""
negative = False
for t in... | python | def _tokenize_wkt(tokens):
"""
Since the tokenizer treats "-" and numeric strings as separate values,
combine them and yield them as a single token. This utility encapsulates
parsing of negative numeric values from WKT can be used generically in all
parsers.
"""
negative = False
for t in... | [
"def",
"_tokenize_wkt",
"(",
"tokens",
")",
":",
"negative",
"=",
"False",
"for",
"t",
"in",
"tokens",
":",
"if",
"t",
"==",
"'-'",
":",
"negative",
"=",
"True",
"continue",
"else",
":",
"if",
"negative",
":",
"yield",
"'-%s'",
"%",
"t",
"else",
":",... | Since the tokenizer treats "-" and numeric strings as separate values,
combine them and yield them as a single token. This utility encapsulates
parsing of negative numeric values from WKT can be used generically in all
parsers. | [
"Since",
"the",
"tokenizer",
"treats",
"-",
"and",
"numeric",
"strings",
"as",
"separate",
"values",
"combine",
"them",
"and",
"yield",
"them",
"as",
"a",
"single",
"token",
".",
"This",
"utility",
"encapsulates",
"parsing",
"of",
"negative",
"numeric",
"value... | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L153-L170 | train |
geomet/geomet | geomet/wkt.py | _round_and_pad | def _round_and_pad(value, decimals):
"""
Round the input value to `decimals` places, and pad with 0's
if the resulting value is less than `decimals`.
:param value:
The value to round
:param decimals:
Number of decimals places which should be displayed after the rounding.
:return... | python | def _round_and_pad(value, decimals):
"""
Round the input value to `decimals` places, and pad with 0's
if the resulting value is less than `decimals`.
:param value:
The value to round
:param decimals:
Number of decimals places which should be displayed after the rounding.
:return... | [
"def",
"_round_and_pad",
"(",
"value",
",",
"decimals",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"int",
")",
"and",
"decimals",
"!=",
"0",
":",
"# if we get an int coordinate and we have a non-zero value for",
"# `decimals`, we want to create a float to pad out.",
... | Round the input value to `decimals` places, and pad with 0's
if the resulting value is less than `decimals`.
:param value:
The value to round
:param decimals:
Number of decimals places which should be displayed after the rounding.
:return:
str of the rounded value | [
"Round",
"the",
"input",
"value",
"to",
"decimals",
"places",
"and",
"pad",
"with",
"0",
"s",
"if",
"the",
"resulting",
"value",
"is",
"less",
"than",
"decimals",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L177-L200 | train |
geomet/geomet | geomet/wkt.py | _dump_point | def _dump_point(obj, decimals):
"""
Dump a GeoJSON-like Point object to WKT.
:param dict obj:
A GeoJSON-like `dict` representing a Point.
:param int decimals:
int which indicates the number of digits to display after the
decimal point when formatting coordinates.
:returns:
... | python | def _dump_point(obj, decimals):
"""
Dump a GeoJSON-like Point object to WKT.
:param dict obj:
A GeoJSON-like `dict` representing a Point.
:param int decimals:
int which indicates the number of digits to display after the
decimal point when formatting coordinates.
:returns:
... | [
"def",
"_dump_point",
"(",
"obj",
",",
"decimals",
")",
":",
"coords",
"=",
"obj",
"[",
"'coordinates'",
"]",
"pt",
"=",
"'POINT (%s)'",
"%",
"' '",
".",
"join",
"(",
"_round_and_pad",
"(",
"c",
",",
"decimals",
")",
"for",
"c",
"in",
"coords",
")",
... | Dump a GeoJSON-like Point object to WKT.
:param dict obj:
A GeoJSON-like `dict` representing a Point.
:param int decimals:
int which indicates the number of digits to display after the
decimal point when formatting coordinates.
:returns:
WKT representation of the input GeoJ... | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"Point",
"object",
"to",
"WKT",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L203-L219 | train |
geomet/geomet | geomet/wkt.py | _dump_linestring | def _dump_linestring(obj, decimals):
"""
Dump a GeoJSON-like LineString object to WKT.
Input parameters and return value are the LINESTRING equivalent to
:func:`_dump_point`.
"""
coords = obj['coordinates']
ls = 'LINESTRING (%s)'
ls %= ', '.join(' '.join(_round_and_pad(c, decimals)
... | python | def _dump_linestring(obj, decimals):
"""
Dump a GeoJSON-like LineString object to WKT.
Input parameters and return value are the LINESTRING equivalent to
:func:`_dump_point`.
"""
coords = obj['coordinates']
ls = 'LINESTRING (%s)'
ls %= ', '.join(' '.join(_round_and_pad(c, decimals)
... | [
"def",
"_dump_linestring",
"(",
"obj",
",",
"decimals",
")",
":",
"coords",
"=",
"obj",
"[",
"'coordinates'",
"]",
"ls",
"=",
"'LINESTRING (%s)'",
"ls",
"%=",
"', '",
".",
"join",
"(",
"' '",
".",
"join",
"(",
"_round_and_pad",
"(",
"c",
",",
"decimals",... | Dump a GeoJSON-like LineString object to WKT.
Input parameters and return value are the LINESTRING equivalent to
:func:`_dump_point`. | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"LineString",
"object",
"to",
"WKT",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L222-L233 | train |
geomet/geomet | geomet/wkt.py | _dump_polygon | def _dump_polygon(obj, decimals):
"""
Dump a GeoJSON-like Polygon object to WKT.
Input parameters and return value are the POLYGON equivalent to
:func:`_dump_point`.
"""
coords = obj['coordinates']
poly = 'POLYGON (%s)'
rings = (', '.join(' '.join(_round_and_pad(c, decimals)
... | python | def _dump_polygon(obj, decimals):
"""
Dump a GeoJSON-like Polygon object to WKT.
Input parameters and return value are the POLYGON equivalent to
:func:`_dump_point`.
"""
coords = obj['coordinates']
poly = 'POLYGON (%s)'
rings = (', '.join(' '.join(_round_and_pad(c, decimals)
... | [
"def",
"_dump_polygon",
"(",
"obj",
",",
"decimals",
")",
":",
"coords",
"=",
"obj",
"[",
"'coordinates'",
"]",
"poly",
"=",
"'POLYGON (%s)'",
"rings",
"=",
"(",
"', '",
".",
"join",
"(",
"' '",
".",
"join",
"(",
"_round_and_pad",
"(",
"c",
",",
"decim... | Dump a GeoJSON-like Polygon object to WKT.
Input parameters and return value are the POLYGON equivalent to
:func:`_dump_point`. | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"Polygon",
"object",
"to",
"WKT",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L236-L250 | train |
geomet/geomet | geomet/wkt.py | _dump_multipoint | def _dump_multipoint(obj, decimals):
"""
Dump a GeoJSON-like MultiPoint object to WKT.
Input parameters and return value are the MULTIPOINT equivalent to
:func:`_dump_point`.
"""
coords = obj['coordinates']
mp = 'MULTIPOINT (%s)'
points = (' '.join(_round_and_pad(c, decimals)
... | python | def _dump_multipoint(obj, decimals):
"""
Dump a GeoJSON-like MultiPoint object to WKT.
Input parameters and return value are the MULTIPOINT equivalent to
:func:`_dump_point`.
"""
coords = obj['coordinates']
mp = 'MULTIPOINT (%s)'
points = (' '.join(_round_and_pad(c, decimals)
... | [
"def",
"_dump_multipoint",
"(",
"obj",
",",
"decimals",
")",
":",
"coords",
"=",
"obj",
"[",
"'coordinates'",
"]",
"mp",
"=",
"'MULTIPOINT (%s)'",
"points",
"=",
"(",
"' '",
".",
"join",
"(",
"_round_and_pad",
"(",
"c",
",",
"decimals",
")",
"for",
"c",
... | Dump a GeoJSON-like MultiPoint object to WKT.
Input parameters and return value are the MULTIPOINT equivalent to
:func:`_dump_point`. | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"MultiPoint",
"object",
"to",
"WKT",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L253-L267 | train |
geomet/geomet | geomet/wkt.py | _dump_multilinestring | def _dump_multilinestring(obj, decimals):
"""
Dump a GeoJSON-like MultiLineString object to WKT.
Input parameters and return value are the MULTILINESTRING equivalent to
:func:`_dump_point`.
"""
coords = obj['coordinates']
mlls = 'MULTILINESTRING (%s)'
linestrs = ('(%s)' % ', '.join(' '.... | python | def _dump_multilinestring(obj, decimals):
"""
Dump a GeoJSON-like MultiLineString object to WKT.
Input parameters and return value are the MULTILINESTRING equivalent to
:func:`_dump_point`.
"""
coords = obj['coordinates']
mlls = 'MULTILINESTRING (%s)'
linestrs = ('(%s)' % ', '.join(' '.... | [
"def",
"_dump_multilinestring",
"(",
"obj",
",",
"decimals",
")",
":",
"coords",
"=",
"obj",
"[",
"'coordinates'",
"]",
"mlls",
"=",
"'MULTILINESTRING (%s)'",
"linestrs",
"=",
"(",
"'(%s)'",
"%",
"', '",
".",
"join",
"(",
"' '",
".",
"join",
"(",
"_round_a... | Dump a GeoJSON-like MultiLineString object to WKT.
Input parameters and return value are the MULTILINESTRING equivalent to
:func:`_dump_point`. | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"MultiLineString",
"object",
"to",
"WKT",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L270-L282 | train |
geomet/geomet | geomet/wkt.py | _dump_multipolygon | def _dump_multipolygon(obj, decimals):
"""
Dump a GeoJSON-like MultiPolygon object to WKT.
Input parameters and return value are the MULTIPOLYGON equivalent to
:func:`_dump_point`.
"""
coords = obj['coordinates']
mp = 'MULTIPOLYGON (%s)'
polys = (
# join the polygons in the mul... | python | def _dump_multipolygon(obj, decimals):
"""
Dump a GeoJSON-like MultiPolygon object to WKT.
Input parameters and return value are the MULTIPOLYGON equivalent to
:func:`_dump_point`.
"""
coords = obj['coordinates']
mp = 'MULTIPOLYGON (%s)'
polys = (
# join the polygons in the mul... | [
"def",
"_dump_multipolygon",
"(",
"obj",
",",
"decimals",
")",
":",
"coords",
"=",
"obj",
"[",
"'coordinates'",
"]",
"mp",
"=",
"'MULTIPOLYGON (%s)'",
"polys",
"=",
"(",
"# join the polygons in the multipolygon",
"', '",
".",
"join",
"(",
"# join the rings in a poly... | Dump a GeoJSON-like MultiPolygon object to WKT.
Input parameters and return value are the MULTIPOLYGON equivalent to
:func:`_dump_point`. | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"MultiPolygon",
"object",
"to",
"WKT",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L285-L311 | train |
geomet/geomet | geomet/wkt.py | _dump_geometrycollection | def _dump_geometrycollection(obj, decimals):
"""
Dump a GeoJSON-like GeometryCollection object to WKT.
Input parameters and return value are the GEOMETRYCOLLECTION equivalent to
:func:`_dump_point`.
The WKT conversions for each geometry in the collection are delegated to
their respective funct... | python | def _dump_geometrycollection(obj, decimals):
"""
Dump a GeoJSON-like GeometryCollection object to WKT.
Input parameters and return value are the GEOMETRYCOLLECTION equivalent to
:func:`_dump_point`.
The WKT conversions for each geometry in the collection are delegated to
their respective funct... | [
"def",
"_dump_geometrycollection",
"(",
"obj",
",",
"decimals",
")",
":",
"gc",
"=",
"'GEOMETRYCOLLECTION (%s)'",
"geoms",
"=",
"obj",
"[",
"'geometries'",
"]",
"geoms_wkt",
"=",
"[",
"]",
"for",
"geom",
"in",
"geoms",
":",
"geom_type",
"=",
"geom",
"[",
"... | Dump a GeoJSON-like GeometryCollection object to WKT.
Input parameters and return value are the GEOMETRYCOLLECTION equivalent to
:func:`_dump_point`.
The WKT conversions for each geometry in the collection are delegated to
their respective functions. | [
"Dump",
"a",
"GeoJSON",
"-",
"like",
"GeometryCollection",
"object",
"to",
"WKT",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L314-L331 | train |
geomet/geomet | geomet/wkt.py | _load_point | def _load_point(tokens, string):
"""
:param tokens:
A generator of string tokens for the input WKT, begining just after the
geometry type. The geometry type is consumed before we get to here. For
example, if :func:`loads` is called with the input 'POINT(0.0 1.0)',
``tokens`` woul... | python | def _load_point(tokens, string):
"""
:param tokens:
A generator of string tokens for the input WKT, begining just after the
geometry type. The geometry type is consumed before we get to here. For
example, if :func:`loads` is called with the input 'POINT(0.0 1.0)',
``tokens`` woul... | [
"def",
"_load_point",
"(",
"tokens",
",",
"string",
")",
":",
"if",
"not",
"next",
"(",
"tokens",
")",
"==",
"'('",
":",
"raise",
"ValueError",
"(",
"INVALID_WKT_FMT",
"%",
"string",
")",
"coords",
"=",
"[",
"]",
"try",
":",
"for",
"t",
"in",
"tokens... | :param tokens:
A generator of string tokens for the input WKT, begining just after the
geometry type. The geometry type is consumed before we get to here. For
example, if :func:`loads` is called with the input 'POINT(0.0 1.0)',
``tokens`` would generate the following values:
.. ... | [
":",
"param",
"tokens",
":",
"A",
"generator",
"of",
"string",
"tokens",
"for",
"the",
"input",
"WKT",
"begining",
"just",
"after",
"the",
"geometry",
"type",
".",
"The",
"geometry",
"type",
"is",
"consumed",
"before",
"we",
"get",
"to",
"here",
".",
"Fo... | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L334-L363 | train |
geomet/geomet | geomet/wkt.py | _load_linestring | def _load_linestring(tokens, string):
"""
Has similar inputs and return value to to :func:`_load_point`, except is
for handling LINESTRING geometry.
:returns:
A GeoJSON `dict` LineString representation of the WKT ``string``.
"""
if not next(tokens) == '(':
raise ValueError(INVAL... | python | def _load_linestring(tokens, string):
"""
Has similar inputs and return value to to :func:`_load_point`, except is
for handling LINESTRING geometry.
:returns:
A GeoJSON `dict` LineString representation of the WKT ``string``.
"""
if not next(tokens) == '(':
raise ValueError(INVAL... | [
"def",
"_load_linestring",
"(",
"tokens",
",",
"string",
")",
":",
"if",
"not",
"next",
"(",
"tokens",
")",
"==",
"'('",
":",
"raise",
"ValueError",
"(",
"INVALID_WKT_FMT",
"%",
"string",
")",
"# a list of lists",
"# each member list represents a point",
"coords",... | Has similar inputs and return value to to :func:`_load_point`, except is
for handling LINESTRING geometry.
:returns:
A GeoJSON `dict` LineString representation of the WKT ``string``. | [
"Has",
"similar",
"inputs",
"and",
"return",
"value",
"to",
"to",
":",
"func",
":",
"_load_point",
"except",
"is",
"for",
"handling",
"LINESTRING",
"geometry",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L366-L395 | train |
geomet/geomet | geomet/wkt.py | _load_polygon | def _load_polygon(tokens, string):
"""
Has similar inputs and return value to to :func:`_load_point`, except is
for handling POLYGON geometry.
:returns:
A GeoJSON `dict` Polygon representation of the WKT ``string``.
"""
open_parens = next(tokens), next(tokens)
if not open_parens == ... | python | def _load_polygon(tokens, string):
"""
Has similar inputs and return value to to :func:`_load_point`, except is
for handling POLYGON geometry.
:returns:
A GeoJSON `dict` Polygon representation of the WKT ``string``.
"""
open_parens = next(tokens), next(tokens)
if not open_parens == ... | [
"def",
"_load_polygon",
"(",
"tokens",
",",
"string",
")",
":",
"open_parens",
"=",
"next",
"(",
"tokens",
")",
",",
"next",
"(",
"tokens",
")",
"if",
"not",
"open_parens",
"==",
"(",
"'('",
",",
"'('",
")",
":",
"raise",
"ValueError",
"(",
"INVALID_WK... | Has similar inputs and return value to to :func:`_load_point`, except is
for handling POLYGON geometry.
:returns:
A GeoJSON `dict` Polygon representation of the WKT ``string``. | [
"Has",
"similar",
"inputs",
"and",
"return",
"value",
"to",
"to",
":",
"func",
":",
"_load_point",
"except",
"is",
"for",
"handling",
"POLYGON",
"geometry",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L398-L446 | train |
geomet/geomet | geomet/wkt.py | _load_multipoint | def _load_multipoint(tokens, string):
"""
Has similar inputs and return value to to :func:`_load_point`, except is
for handling MULTIPOINT geometry.
:returns:
A GeoJSON `dict` MultiPoint representation of the WKT ``string``.
"""
open_paren = next(tokens)
if not open_paren == '(':
... | python | def _load_multipoint(tokens, string):
"""
Has similar inputs and return value to to :func:`_load_point`, except is
for handling MULTIPOINT geometry.
:returns:
A GeoJSON `dict` MultiPoint representation of the WKT ``string``.
"""
open_paren = next(tokens)
if not open_paren == '(':
... | [
"def",
"_load_multipoint",
"(",
"tokens",
",",
"string",
")",
":",
"open_paren",
"=",
"next",
"(",
"tokens",
")",
"if",
"not",
"open_paren",
"==",
"'('",
":",
"raise",
"ValueError",
"(",
"INVALID_WKT_FMT",
"%",
"string",
")",
"coords",
"=",
"[",
"]",
"pt... | Has similar inputs and return value to to :func:`_load_point`, except is
for handling MULTIPOINT geometry.
:returns:
A GeoJSON `dict` MultiPoint representation of the WKT ``string``. | [
"Has",
"similar",
"inputs",
"and",
"return",
"value",
"to",
"to",
":",
"func",
":",
"_load_point",
"except",
"is",
"for",
"handling",
"MULTIPOINT",
"geometry",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L449-L489 | train |
geomet/geomet | geomet/wkt.py | _load_multipolygon | def _load_multipolygon(tokens, string):
"""
Has similar inputs and return value to to :func:`_load_point`, except is
for handling MULTIPOLYGON geometry.
:returns:
A GeoJSON `dict` MultiPolygon representation of the WKT ``string``.
"""
open_paren = next(tokens)
if not open_paren == '... | python | def _load_multipolygon(tokens, string):
"""
Has similar inputs and return value to to :func:`_load_point`, except is
for handling MULTIPOLYGON geometry.
:returns:
A GeoJSON `dict` MultiPolygon representation of the WKT ``string``.
"""
open_paren = next(tokens)
if not open_paren == '... | [
"def",
"_load_multipolygon",
"(",
"tokens",
",",
"string",
")",
":",
"open_paren",
"=",
"next",
"(",
"tokens",
")",
"if",
"not",
"open_paren",
"==",
"'('",
":",
"raise",
"ValueError",
"(",
"INVALID_WKT_FMT",
"%",
"string",
")",
"polygons",
"=",
"[",
"]",
... | Has similar inputs and return value to to :func:`_load_point`, except is
for handling MULTIPOLYGON geometry.
:returns:
A GeoJSON `dict` MultiPolygon representation of the WKT ``string``. | [
"Has",
"similar",
"inputs",
"and",
"return",
"value",
"to",
"to",
":",
"func",
":",
"_load_point",
"except",
"is",
"for",
"handling",
"MULTIPOLYGON",
"geometry",
"."
] | b82d7118113ab723751eba3de5df98c368423c2b | https://github.com/geomet/geomet/blob/b82d7118113ab723751eba3de5df98c368423c2b/geomet/wkt.py#L492-L517 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.