-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery refactored master branch #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,19 +39,17 @@ def __init__(self, commands): | |
|
|
||
| # Traverses the list of available commands | ||
| def traverse(self, tokens, tree): | ||
| 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 | ||
|
|
||
| # Returns a list of possible commands that match the partial command that the user has entered | ||
| def complete(self, text, state): | ||
|
|
@@ -182,23 +180,20 @@ def send(self,data,socket): | |
|
|
||
| #Receive network data | ||
| def recv(self,size,socket): | ||
| 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 | ||
|
Comment on lines
-185
to
+196
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| #Create new UDP socket on ip, bound to port | ||
| def createNewListener(self,ip,port): | ||
|
|
@@ -225,39 +220,39 @@ def sender(self): | |
|
|
||
| #Parse a URL, return the host and the page | ||
| def parseURL(self,url): | ||
| 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) | ||
|
Comment on lines
-228
to
+235
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| #Pull the name of the device type from a device type string | ||
| #The device type string looks like: 'urn:schemas-upnp-org:device:WANDevice:1' | ||
| def parseDeviceTypeName(self,string): | ||
| delim1 = 'device:' | ||
| delim2 = ':' | ||
| delim1 = 'device:' | ||
| if delim1 in string and not string.endswith(delim1): | ||
| delim2 = ':' | ||
|
|
||
| if delim1 in string and not string.endswith(delim1): | ||
| return string.split(delim1)[1].split(delim2,1)[0] | ||
| return False | ||
| return string.split(delim1)[1].split(delim2,1)[0] | ||
| return False | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| #Pull the name of the service type from a service type string | ||
| #The service type string looks like: 'urn:schemas-upnp-org:service:Layer3Forwarding:1' | ||
| def parseServiceTypeName(self,string): | ||
| delim1 = 'service:' | ||
| delim2 = ':' | ||
| delim1 = 'service:' | ||
| if delim1 in string and not string.endswith(delim1): | ||
| delim2 = ':' | ||
|
|
||
| if delim1 in string and not string.endswith(delim1): | ||
| return string.split(delim1)[1].split(delim2,1)[0] | ||
| return False | ||
| return string.split(delim1)[1].split(delim2,1)[0] | ||
| return False | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| #Pull the header info for the specified HTTP header - case insensitive | ||
| def parseHeader(self,data,header): | ||
|
|
@@ -280,18 +275,18 @@ def parseHeader(self,data,header): | |
|
|
||
| #Extract the contents of a single XML tag from the data | ||
| def extractSingleTag(self,data,tag): | ||
| 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 | ||
|
Comment on lines
-283
to
+289
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| #Parses SSDP notify and reply packets, and populates the ENUM_HOSTS dict | ||
| def parseSSDPInfo(self,data,showUniq,verbose): | ||
|
|
@@ -1649,10 +1644,7 @@ def parseCliOpts(argc,argv,hp): | |
|
|
||
| #Toggle boolean values | ||
| def toggleVal(val): | ||
| if val: | ||
| return False | ||
| else: | ||
| return True | ||
| return not val | ||
|
Comment on lines
-1652
to
+1647
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| #Prompt for user input | ||
| def getUserInput(hp,shellPrompt): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
CmdCompleter.traverserefactored with the following changes:use-fstring-for-concatenation)This removes the following comments ( why? ):