text
stringlengths
0
828
""range1"" : {
""range"" : {
""field"" : ""field_name"",
""ranges"" : [
{ ""to"" : 50 },
{ ""from"" : 20, ""to"" : 70 },
{ ""from"" : 70, ""to"" : 120 },
{ ""from"" : 150 }
]
}
}
}
'''
self[facet_name] = {'range': {'field': field, 'ranges': []}}
for s in ranges:
if not isinstance(s, slice):
continue
entry = dict()
if s.start:
entry['from'] = s.start
if s.stop != -1:
entry['to'] = s.stop
self[facet_name]['range']['ranges'].append(entry)
return self"
1460,"def parse_gpx(gpx_element, gpxns=None):
""""""Parse a GPX file into a GpxModel.
Args:
gpx_element: The root <gpx> element of an XML document containing a
version attribute. GPX versions 1.0 and 1.1 are supported.
gpxns: The XML namespace for GPX in Clarke notation (i.e. delimited
by curly braces).
Returns:
A GpxModel representing the data from the supplies xml.
Raises:
ValueError: The supplied XML could not be parsed as GPX.
""""""
gpxns = gpxns if gpxns is not None else determine_gpx_namespace(gpx_element)
if gpx_element.tag != gpxns+'gpx':
raise ValueError(""No gpx root element"")
version = gpx_element.attrib['version']
if version == '1.0':
return parse_gpx_1_0(gpx_element, gpxns=gpxns)
elif version == '1.1':
return parse_gpx_1_1(gpx_element, gpxns=gpxns)
else:
raise ValueError(""Cannot parse GPX version {0}"".format(version))"
1461,"def backup_file(filename):
"""""" create a backup of the file desired """"""
if not os.path.exists(filename):
return
BACKUP_SUFFIX = "".sprinter.bak""
backup_filename = filename + BACKUP_SUFFIX
shutil.copyfile(filename, backup_filename)"
1462,"def inject(self, filename, content):
"""""" add the injection content to the dictionary """"""
# ensure content always has one trailing newline
content = _unicode(content).rstrip() + ""\n""
if filename not in self.inject_dict:
self.inject_dict[filename] = """"
self.inject_dict[filename] += content"
1463,"def commit(self):
"""""" commit the injections desired, overwriting any previous injections in the file. """"""
self.logger.debug(""Starting injections..."")
self.logger.debug(""Injections dict is:"")
self.logger.debug(self.inject_dict)
self.logger.debug(""Clear list is:"")
self.logger.debug(self.clear_set)
for filename, content in self.inject_dict.items():
content = _unicode(content)
self.logger.debug(""Injecting values into %s..."" % filename)
self.destructive_inject(filename, content)
for filename in self.clear_set:
self.logger.debug(""Clearing injection from %s..."" % filename)
self.destructive_clear(filename)"
1464,"def injected(self, filename):
"""""" Return true if the file has already been injected before. """"""
full_path = os.path.expanduser(filename)
if not os.path.exists(full_path):
return False
with codecs.open(full_path, 'r+', encoding=""utf-8"") as fh:
contents = fh.read()
return self.wrapper_match.search(contents) is not None"
1465,"def destructive_inject(self, filename, content):
""""""
Injects the injections desired immediately. This should
generally be run only during the commit phase, when no future
injections will be done.
""""""
content = _unicode(content)