text stringlengths 0 828 |
|---|
:item: string to match |
:options: list of examples to test against |
:fuzzy: integer (out of 100) describing how close to match string |
:fname_match: use filename globbing to match files? |
:fuzzy_fragment: if not ``None``, will accept substring matches of |
at least ``fuzzy_fragment`` fuzziness |
:guess: if ``True``, shortcut for setting ``fuzzy`` and ``min_fragment`` |
to very lenient options |
''' |
matches = [] |
if guess: |
fuzzy = min(fuzzy,80) |
fuzzy_fragment = min(fuzzy_fragment,70) |
option_not_in = lambda item,match_list: all([x[0]!=item for x in match_list]) |
# Exact matches |
if item in options: |
matches += [(options[i],i,'exact',None) for i in xrange(len(options)) if options[i].lower()==item.lower()] |
# If we have exact matches, don't bother with fuzzy matching |
return matches |
# Filename-style matches |
if fname_match: |
matches += [(x,options.index(x),'fname',None) for x in fnmatch.filter(options,item) if option_not_in(x,matches)] |
# Fuzzy matches |
if fuzzy: |
sub_matches = [] |
for i in xrange(len(options)): |
r = fuzz.ratio(item.lower(),options[i].lower()) |
if r>=fuzzy and option_not_in(options[i],matches): |
sub_matches.append((r,i)) |
matches += [(options[x[1]],x[1],'fuzzy',x[0]) for x in sorted(sub_matches)] |
# Fragment matches |
if fuzzy_fragment: |
sub_matches = [] |
for i in xrange(len(options)): |
r = fuzz.partial_ratio(item.lower(),options[i].lower()) |
if r>=fuzzy_fragment and option_not_in(options[i],matches): |
sub_matches.append((r,i)) |
matches += [(options[x[1]],x[1],'fuzzy_fragment',x[0]) for x in sorted(sub_matches)] |
return matches" |
3903,"def best_match_from_list(item,options,fuzzy=90,fname_match=True,fuzzy_fragment=None,guess=False): |
'''Returns the best match from :meth:`matches_from_list` or ``None`` if no good matches''' |
matches = matches_from_list(item,options,fuzzy,fname_match,fuzzy_fragment,guess) |
if len(matches)>0: |
return matches[0] |
return None" |
3904,"def best_item_from_list(item,options,fuzzy=90,fname_match=True,fuzzy_fragment=None,guess=False): |
'''Returns just the best item, or ``None``''' |
match = best_match_from_list(item,options,fuzzy,fname_match,fuzzy_fragment,guess) |
if match: |
return match[0] |
return None" |
3905,"async def create_hlk_sw16_connection(port=None, host=None, |
disconnect_callback=None, |
reconnect_callback=None, loop=None, |
logger=None, timeout=None, |
reconnect_interval=None): |
""""""Create HLK-SW16 Client class."""""" |
client = SW16Client(host, port=port, |
disconnect_callback=disconnect_callback, |
reconnect_callback=reconnect_callback, |
loop=loop, logger=logger, |
timeout=timeout, reconnect_interval=reconnect_interval) |
await client.setup() |
return client" |
3906,"def _reset_timeout(self): |
""""""Reset timeout for date keep alive."""""" |
if self._timeout: |
self._timeout.cancel() |
self._timeout = self.loop.call_later(self.client.timeout, |
self.transport.close)" |
3907,"def reset_cmd_timeout(self): |
""""""Reset timeout for command execution."""""" |
if self._cmd_timeout: |
self._cmd_timeout.cancel() |
self._cmd_timeout = self.loop.call_later(self.client.timeout, |
self.transport.close)" |
3908,"def _handle_lines(self): |
""""""Assemble incoming data into per-line packets."""""" |
while b'\xdd' in self._buffer: |
linebuf, self._buffer = self._buffer.rsplit(b'\xdd', 1) |
line = linebuf[-19:] |
self._buffer += linebuf[:-19] |
if self._valid_packet(line): |
self._handle_raw_packet(line) |
else: |
self.logger.warning('dropping invalid data: %s', |
binascii.hexlify(line))" |
3909,"def _valid_packet(raw_packet): |
""""""Validate incoming packet."""""" |
if raw_packet[0:1] != b'\xcc': |
return False |
if len(raw_packet) != 19: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.