text
stringlengths
0
828
""""""
if (
namespaces in ['exslt', 're'] or
(regexp and not namespaces)
):
namespaces = {'re': ""http://exslt.org/regular-expressions""}
if single_use:
node = self._xml.xpath(path)
else:
xpe = self.xpath_evaluator(
namespaces=namespaces,
regexp=regexp,
smart_strings=smart_strings
)
node = xpe(path)
if len(node) == 1:
node = node[0]
if len(node):
return self.__class__(node)
else:
return Literal(node)
return node"
4252,"def xpath_evaluator(self, namespaces=None, regexp=False, smart_strings=True):
u""""""Creates an XPathEvaluator instance for an ElementTree or an Element.
:returns: ``XPathEvaluator`` instance
""""""
return etree.XPathEvaluator(
self._xml,
namespaces=namespaces,
regexp=regexp,
smart_strings=smart_strings
)"
4253,"def get_last_modified_date(*args, **kwargs):
""""""Returns the date of the last modified Note or Release.
For use with Django's last_modified decorator.
""""""
try:
latest_note = Note.objects.latest()
latest_release = Release.objects.latest()
except ObjectDoesNotExist:
return None
return max(latest_note.modified, latest_release.modified)"
4254,"def using_ios_stash():
''' returns true if sys path hints the install is running on ios '''
print('detected install path:')
print(os.path.dirname(__file__))
module_names = set(sys.modules.keys())
return 'stash' in module_names or 'stash.system' in module_names"
4255,"def pad_bin_image_to_shape(image, shape):
""""""
Padd image to size :shape: with zeros
""""""
h, w = shape
ih, iw = image.shape
assert ih <= h
assert iw <= w
if iw < w:
result = numpy.hstack((image, numpy.zeros((ih, w - iw), bool)))
else:
result = image
if ih < h:
result = numpy.vstack((result, numpy.zeros((h - ih, w), bool)))
return result"
4256,"def best_convolution(bin_template, bin_image,
tollerance=0.5, overlap_table=OVERLAP_TABLE):
""""""
Selects and applies the best convolution method to find template in image.
Returns a list of matches in (width, height, x offset, y offset)
format (where the x and y offsets are from the top left corner).
As the images are binary images, we can utilise the extra bit space in the
float64's by cutting the image into tiles and stacking them into variable
grayscale values.
This allows converting a sparse binary image into a dense(r) grayscale one.
""""""
template_sum = numpy.count_nonzero(bin_template)
th, tw = bin_template.shape
ih, iw = bin_image.shape
if template_sum == 0 or th == 0 or tw == 0:
# If we don't have a template
return []
if th > ih or tw > iw:
# If the template is bigger than the image
return []
# How many cells can we split the image into?
max_vert_cells = ih // th
max_hor_cells = iw // th
# Try to work out how many times we can stack the image
usable_factors = {n: factors for n, factors in overlap_table.iteritems()
if ((template_sum + 1) ** (n)) < ACCURACY_LIMIT}
overlap_options = [(factor, n // factor)