瀏覽代碼

Check for invalid commands in Sink.send_command

Any command sent with send_command could be invalid.  It makes sense for
that method to throw an exception if the command isn't recognized so I
don't have to duplicate that effort in the methods for all commands
introduced after firmware version 1.0.  This commit moves the command
validity checking to Sink.send_command.
Clara Hobbs 7 年之前
父節點
當前提交
a4d94131d6
共有 1 個文件被更改,包括 5 次插入3 次删除
  1. 5
    3
      pdbuddy/__init__.py

+ 5
- 3
pdbuddy/__init__.py 查看文件

@@ -67,6 +67,11 @@ class Sink:
67 67
 
68 68
         # Remove the echoed command and prompt
69 69
         answer = answer[1:-1]
70
+
71
+        # Raise an exception if the command wasn't recognized
72
+        if len(answer) and answer[0] == cmd.strip().split()[0] + b" ?":
73
+            raise KeyError("command not found")
74
+
70 75
         return answer
71 76
 
72 77
     def close(self):
@@ -167,9 +172,6 @@ class Sink:
167 172
             elif value[0] == b"disabled":
168 173
                 return False
169 174
             else:
170
-                # If the command is unknown to the Sink, raise a KeyError
171
-                if value[0] == b"output ?":
172
-                    raise KeyError("command not found")
173 175
                 # If unexpected text is returned, raise an exception indicating a
174 176
                 # firmware error
175 177
                 raise ValueError("unknown output state")

Loading…
取消
儲存