text
stringlengths 0
828
|
|---|
# create the parsing plan
|
pp = self.create_parsing_plan(item_type, obj, logger=self.logger)
|
# print('')
|
self.logger.debug('')
|
# parse
|
res = pp.execute(logger=self.logger, options=options)
|
# print('')
|
self.logger.debug('')
|
return res"
|
756,"def findSubCommand(args):
|
""""""
|
Given a list ['foo','bar', 'baz'], attempts to create a command name in the
|
format 'foo-bar-baz'. If that command exists, we run it. If it doesn't, we
|
check to see if foo-bar exists, in which case we run `foo-bar baz`. We keep
|
taking chunks off the end of the command name and adding them to the argument
|
list until we find a valid command name we can run.
|
This allows us to easily make git-style command drivers where for example we
|
have a driver script, foo, and subcommand scripts foo-bar and foo-baz, and when
|
the user types `foo bar foobar` we find the foo-bar script and run it as
|
`foo-bar foobar`
|
:param list|tuple args: list to try and convert to a command args pair
|
:returns: command and arguments list
|
:rtype: tuple
|
:raises StandardError: if the args can't be matched to an executable subcommand
|
""""""
|
# If the only command we find is the first element of args, we've found the
|
# driver script itself and re-executing it will cause an infinite loop, so
|
# don't even look at the first element on its own.
|
for n in range(len(args) - 1):
|
command = '-'.join(args[:(len(args) - n)])
|
commandArgs = args[len(args) - n:]
|
if isProgram(command):
|
return (command, commandArgs)
|
raise StandardError(""Could not find a %s subcommand executable"" % command)"
|
757,"def SpamsumDistance(ssA, ssB):
|
'''
|
returns the spamsum distance between ssA and ssB
|
if they use a different block size, assume maximum distance
|
otherwise returns the LevDistance
|
'''
|
mA = re.match('^(\d+)[:](.*)$', ssA)
|
mB = re.match('^(\d+)[:](.*)$', ssB)
|
if mA == None or mB == None:
|
raise ""do not appear to be spamsum signatures""
|
if mA.group(1) != mB.group(1):
|
return max([len(mA.group(2)), len(mB.group(2))])
|
else:
|
return LevDistance(mA.group(2), mB.group(2))"
|
758,"def terms(cls, tags, minimum_match=None):
|
'''
|
A query that match on any (configurable) of the provided terms. This is a simpler syntax query for using a bool query with several term queries in the should clauses. For example:
|
{
|
""terms"" : {
|
""tags"" : [ ""blue"", ""pill"" ],
|
""minimum_match"" : 1
|
}
|
}'''
|
instance = cls(terms={'tags': tags})
|
if minimum_match is not None:
|
instance['terms']['minimum_match'] = minimum_match
|
return instance"
|
759,"def field(cls, field, query, boost=None, enable_position_increments=None):
|
'''
|
A query that executes a query string against a specific field. It is a simplified version of query_string query (by setting the default_field to the field this query executed against). In its simplest form:
|
{
|
""field"" : {
|
""name.first"" : ""+something -else""
|
}
|
}
|
Most of the query_string parameters are allowed with the field query as well, in such a case, the query should be formatted as follows:
|
{
|
""field"" : {
|
""name.first"" : {
|
""query"" : ""+something -else"",
|
""boost"" : 2.0,
|
""enable_position_increments"": false
|
}
|
}
|
}
|
'''
|
instance = cls(field={field: {'query': query}})
|
if boost is not None:
|
instance['field']['boost'] = boost
|
if enable_position_increments is not None:
|
instance['field']['enable_position_increments'] = enable_position_increments
|
return instance"
|
760,"def match(cls, field, query, operator=None):
|
'''
|
A family of match queries that accept text/numerics/dates, analyzes it, and constructs a query out of it. For example:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.