text
stringlengths
0
828
333,"def get_default_yaml_parsers(parser_finder: ParserFinder, conversion_finder: ConversionFinder) -> List[AnyParser]:
""""""
Utility method to return the default parsers able to parse an object from a file.
Note that MultifileObjectParser is not provided in this list, as it is already added in a hardcoded way in
RootParser
:return:
""""""
return [# yaml for any object
SingleFileParserFunction(parser_function=read_object_from_yaml,
streaming_mode=True,
supported_exts={'.yaml','.yml'},
supported_types={AnyObject},
),
# yaml for collection objects
SingleFileParserFunction(parser_function=read_collection_from_yaml,
custom_name='read_collection_from_yaml',
streaming_mode=True,
supported_exts={'.yaml','.yml'},
supported_types={Tuple, Dict, List, Set},
function_args={'conversion_finder': conversion_finder}
)
]"
334,"def pass_feature(*feature_names):
""""""Injects a feature instance into the kwargs
""""""
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
for name in feature_names:
kwargs[name] = feature_proxy(name)
return f(*args, **kwargs)
return wrapper
return decorator"
335,"def extract_tar(url, target_dir, additional_compression="""", remove_common_prefix=False, overwrite=False):
"""""" extract a targz and install to the target directory """"""
try:
if not os.path.exists(target_dir):
os.makedirs(target_dir)
tf = tarfile.TarFile.open(fileobj=download_to_bytesio(url))
if not os.path.exists(target_dir):
os.makedirs(target_dir)
common_prefix = os.path.commonprefix(tf.getnames())
if not common_prefix.endswith('/'):
common_prefix += ""/""
for tfile in tf.getmembers():
if remove_common_prefix:
tfile.name = tfile.name.replace(common_prefix, """", 1)
if tfile.name != """":
target_path = os.path.join(target_dir, tfile.name)
if target_path != target_dir and os.path.exists(target_path):
if overwrite:
remove_path(target_path)
else:
continue
tf.extract(tfile, target_dir)
except OSError:
e = sys.exc_info()[1]
raise ExtractException(str(e))
except IOError:
e = sys.exc_info()[1]
raise ExtractException(str(e))"
336,"def remove_path(target_path):
"""""" Delete the target path """"""
if os.path.isdir(target_path):
shutil.rmtree(target_path)
else:
os.unlink(target_path)"
337,"def ids(cls, values, itype=None):
'''
http://www.elasticsearch.org/guide/reference/query-dsl/ids-filter.html
Filters documents that only have the provided ids. Note, this filter does not require the _id field to be indexed since it works using the _uid field.
'''
instance = cls(ids={'values': values})
if itype is not None:
instance['ids']['type'] = itype
return instance"
338,"def geo_bounding_box(cls, field, top_left, bottom_right):
'''
http://www.elasticsearch.org/guide/reference/query-dsl/geo-bounding-box-filter.html
> bounds = ElasticFilter().geo_bounding_box('pin.location', [40.73, -74.1], [40.717, -73.99])
> bounds = ElasticFilter().geo_bounding_box('pin.location', dict(lat=40.73, lon=-74.1), dict(lat=40.717, lon=-73.99))
> bounds = ElasticFilter().geo_bounding_box('pin.location', ""40.73, -74.1"", ""40.717, -73.99"")
And geohash
> bounds = ElasticFilter().geo_bounding_box('pin.location', ""drm3btev3e86"", ""drm3btev3e86"")
'''
return cls(geo_bounding_box={field: {'top_left': top_left, 'bottom_right': bottom_right}})"
339,"def geo_distance(cls, field, center, distance, distance_type=None):
'''
http://www.elasticsearch.org/guide/reference/query-dsl/geo-distance-filter.html
Filters documents that include only hits that exists within a specific distance from a geo point.
field - Field name
center - Center point (Geo point)
distance - String for the distance
distance_type - (arc | plane) How to compute the distance. Can either be arc (better precision) or plane (faster). Defaults to arc
> bounds = ElasticFilter().geo_distance('pin.location', [40.73, -74.1], '300km')
'''