text
stringlengths
0
828
if isinstance(x, datetime.datetime) or isinstance(x, datetime.date):
return x.isoformat()
raise TypeError(""Unknown type"")"
3727,"def save(self, *args, **kwargs):
""""""
**uid**: :code:`party:{apcode}`
""""""
self.uid = 'party:{}'.format(slugify(self.ap_code))
if not self.slug:
if self.organization:
self.slug = slugify(self.organization.name)
else:
self.slug = slugify(self.label)
super(Party, self).save(*args, **kwargs)"
3728,"def parsed(self):
""""""Get the code object which represents the compiled Python file.
This property is cached and only parses the content once.
""""""
if not self._parsed:
self._parsed = compile(self.content, self.path, 'exec')
return self._parsed"
3729,"def get_version():
""""""
parse __init__.py for version number instead of importing the file
see http://stackoverflow.com/questions/458550/standard-way-to-embed-version-into-python-package
""""""
version_file = os.path.join(PKG, 'lib/version.py')
ver_str_line = open(version_file, ""rt"").read()
version_regex = r'^__version__ = [\'""]([^\'""]*)[\'""]'
mo = re.search(version_regex, ver_str_line, re.M)
if mo:
return mo.group(1)
else:
raise RuntimeError('Unable to find version string in %s.'
% (version_file,))"
3730,"def _chunk(iterable, size):
""""""Split an iterable into chunks of a fixed size.""""""
# We're going to use some star magic to chunk the iterable. We create a
# copy of the iterator size times, then pull a value from each to form a
# chunk. The last chunk may have some trailing Nones if the length of the
# iterable isn't a multiple of size, so we filter them out.
args = (iter(iterable),) * size
return (
# pylint: disable=star-args
itertools.takewhile(lambda x: x is not None, group)
for group in itertools.zip_longest(*args)
)"
3731,"def _matrix_add_column(matrix, column, default=0):
""""""Given a matrix as a list of lists, add a column to the right, filling in
with a default value if necessary.
""""""
height_difference = len(column) - len(matrix)
# The width of the matrix is the length of its longest row.
width = max(len(row) for row in matrix) if matrix else 0
# For now our offset is 0. We may need to shift our column down later.
offset = 0
# If we need extra rows, add them to the top of the matrix.
if height_difference > 0:
for _ in range(height_difference):
matrix.insert(0, [default] * width)
# If the column is shorter, we'll need to shift it down.
if height_difference < 0:
offset = -height_difference
#column = ([default] * offset) + column
for index, value in enumerate(column):
# The row index is the index in the column plus our offset.
row_index = index + offset
row = matrix[row_index]
# If this row is short, pad it with default values.
width_difference = width - len(row)
row.extend([default] * width_difference)
row.append(value)"
3732,"def vertical_graph(*args, sep='\n'):
r""""""Consume an iterable of integers and produce a vertical bar graph using
braille characters.
The graph is vertical in that its dependent axis is the vertical axis. Thus
each value is represented as a row running left to right, and values are
listed top to bottom.
If the iterable contains more than four integers, it will be chunked into
groups of four, separated with newlines by default.
>>> vertical_graph([1, 2, 3, 4])
'⣷⣄'
>>> vertical_graph([1, 2, 3, 4, 5, 6])
'⣷⣄\n⠛⠛⠓'
>>> print(vertical_graph([1, 2, 3, 4, 5, 6]))