下面的Python 3代码显示插入或移除的USB设备的 # Auth login function
login(email, password) {
// If user is already logged in return true.
if (auth.loggedIn()) return Promise.resolve(true);
const credentials = btoa(`${email}:${password}`);
// Request to login
return axios({
method: "post",
url: `${SERVER_URL}/api/v1/accounts/login/`,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Basic ${credentials}`
}
}).then(response => {
// Save token to local storage
if (response.data.token) {
localStorage.auth_token = response.data.token;
} else {
// To Do-- throw error if server fails to return one
}
return Promise.resolve(true);
});
}
。
我宁愿在export function* authorize({
email,
password,
isRegistering,
firstName,
lastName
}) {
// We send an action that tells Redux we're sending a request
yield put({ type: SENDING_REQUEST, sending: true });
// We then try to register or log in the user, depending on the request
try {
let response;
// For either log in or registering, we call the proper function in the `auth`
// module, which is asynchronous. Because we're using generators, we can work
// as if it's synchronous because we pause execution until the call is done
// with `yield`!
if (isRegistering) {
response = yield call(
register,
email,
password,
firstName,
lastName
);
} else {
response = yield call(login, email, password);
}
return response;
} catch (error) {
// If we get an error we send Redux the appropriate action and return
yield put({
type: REQUEST_ERROR,
error: error.response.data,
sending: false
});
return false;
} finally {
// When done, we tell Redux we're not in the middle of a request any more
yield put({ type: SENDING_REQUEST, sending: false });
}
}
循环中获得describe("login function", () => {
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
localStorage.clear();
});
afterEach(() => {
// We need to clear mocks
// and remove tokens from local storage to prevent
// us from staying logged in
mock.restore();
});
test("Check that exception thrown on server error", () => {
// Mock loggedin function to throw error
mock.onPost().reply(500);
Test that error is uncaught.
expect(() => {
auth.login("test@example.com", "pass").then(value => {
console.log(value);
});
}).toThrow();
});
});
属性,也不愿使用DEVTYPE
。
DEVTYPE
答案 0 :(得分:3)
如果pyudev
不能满足您的需求,建议您改用evdev
。它有更好的文档记录,更易于使用。
from evdev import InputDevice,list_devices
devices = [InputDevice(fn) for fn in list_devices()]
for dev in devices:
print (dev.fn, dev.name)
/dev/input/event12 HDA Intel PCH HDMI/DP,pcm=3
/dev/input/event11 HDA Intel PCH Front Headphone
/dev/input/event10 HDA Intel PCH Line Out
/dev/input/event9 HDA Intel PCH Rear Mic
/dev/input/event8 HDA Intel PCH Front Mic
/dev/input/event7 RDing FootSwitch3F1.
/dev/input/event6 USB OPTICAL MOUSE
/dev/input/event5 BTC USB Multimedia Keyboard
/dev/input/event4 BTC USB Multimedia Keyboard
/dev/input/event3 Video Bus
/dev/input/event2 Power Button
/dev/input/event1 Sleep Button
/dev/input/event0 Power Button