Conversation
| retVal = [] | ||
| retVal = [] | ||
|
|
||
| # If there are no commands, or no user input, return null | ||
| if tree is None or len(tokens) == 0: | ||
| retVal = [] | ||
| # If there is only one word, only auto-complete the primary commands | ||
| elif len(tokens) == 1: | ||
| retVal = [x+' ' for x in tree if x.startswith(tokens[0])] | ||
| # Else auto-complete for the sub-commands | ||
| elif tokens[0] in tree.keys(): | ||
| retVal = self.traverse(tokens[1:],tree[tokens[0]]) | ||
| # If there are no commands, or no user input, return null | ||
| if tree is None or len(tokens) == 0: | ||
| retVal = [] | ||
| elif len(tokens) == 1: | ||
| retVal = [f'{x} ' for x in tree if x.startswith(tokens[0])] | ||
| elif tokens[0] in tree.keys(): | ||
| retVal = self.traverse(tokens[1:],tree[tokens[0]]) | ||
|
|
||
| return retVal | ||
| return retVal |
There was a problem hiding this comment.
Function CmdCompleter.traverse refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
This removes the following comments ( why? ):
# If there is only one word, only auto-complete the primary commands
# Else auto-complete for the sub-commands
| if socket == False: | ||
| socket = self.ssock | ||
| if socket == False: | ||
| socket = self.ssock | ||
|
|
||
| if self.TIMEOUT: | ||
| socket.setblocking(0) | ||
| ready = select.select([socket], [], [], self.TIMEOUT)[0] | ||
| else: | ||
| socket.setblocking(1) | ||
| ready = True | ||
|
|
||
| try: | ||
| if ready: | ||
| return socket.recv(size) | ||
| else: | ||
| return False | ||
| except: | ||
| return False | ||
| if self.TIMEOUT: | ||
| socket.setblocking(0) | ||
| ready = select.select([socket], [], [], self.TIMEOUT)[0] | ||
| else: | ||
| socket.setblocking(1) | ||
| ready = True | ||
|
|
||
| try: | ||
| return socket.recv(size) if ready else False | ||
| except: | ||
| return False |
There was a problem hiding this comment.
Function upnp.recv refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| delim = '://' | ||
| host = False | ||
| page = False | ||
| delim = '://' | ||
| host = False | ||
| page = False | ||
|
|
||
| #Split the host and page | ||
| try: | ||
| (host,page) = url.split(delim)[1].split('/',1) | ||
| page = '/' + page | ||
| except: | ||
| #If '://' is not in the url, then it's not a full URL, so assume that it's just a relative path | ||
| page = url | ||
| #Split the host and page | ||
| try: | ||
| (host,page) = url.split(delim)[1].split('/',1) | ||
| page = f'/{page}' | ||
| except: | ||
| #If '://' is not in the url, then it's not a full URL, so assume that it's just a relative path | ||
| page = url | ||
|
|
||
| return (host,page) | ||
| return (host,page) |
There was a problem hiding this comment.
Function upnp.parseURL refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| return string.split(delim1)[1].split(delim2,1)[0] | ||
| return False | ||
| return string.split(delim1)[1].split(delim2,1)[0] | ||
| return False |
There was a problem hiding this comment.
Function upnp.parseDeviceTypeName refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| return string.split(delim1)[1].split(delim2,1)[0] | ||
| return False | ||
| return string.split(delim1)[1].split(delim2,1)[0] | ||
| return False |
There was a problem hiding this comment.
Function upnp.parseServiceTypeName refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| startTag = "<%s" % tag | ||
| endTag = "</%s>" % tag | ||
|
|
||
| try: | ||
| tmp = data.split(startTag)[1] | ||
| index = tmp.find('>') | ||
| if index != -1: | ||
| index += 1 | ||
| return tmp[index:].split(endTag)[0].strip() | ||
| except: | ||
| pass | ||
| return None | ||
| startTag = f"<{tag}" | ||
| endTag = f"</{tag}>" | ||
|
|
||
| try: | ||
| tmp = data.split(startTag)[1] | ||
| index = tmp.find('>') | ||
| if index != -1: | ||
| index += 1 | ||
| return tmp[index:].split(endTag)[0].strip() | ||
| except: | ||
| pass | ||
| return None |
There was a problem hiding this comment.
Function upnp.extractSingleTag refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| if val: | ||
| return False | ||
| else: | ||
| return True | ||
| return not val |
There was a problem hiding this comment.
Function toggleVal refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Simplify boolean if expression (
boolean-if-exp-identity) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast)
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!