text
stringlengths 0
828
|
---|
def anonymous_access(exc_obj):
|
"""""" Determine what to do with unauthenticated requests.
|
If the request has already been authenticated, does
|
nothing.
|
:param exc_obj: exception object to be thrown if anonymous
|
access is not permitted.
|
""""""
|
if request.user and request.user.is_authenticated():
|
# request is already authenticated
|
pass
|
elif self.allow_anonymous:
|
request.user = AnonymousUser()
|
else:
|
raise exc_obj
|
# first, make sure that the request carries `user` attribute
|
ensure_user_obj()
|
if self.authentication:
|
# authentication handler is configured
|
try:
|
self.authentication.authenticate(request)
|
except errors.Unauthorized, exc:
|
# http request doesn't carry any authentication information
|
anonymous_access(exc)
|
else:
|
# no authentication configured
|
anonymous_access(errors.Forbidden())"
|
4913,"def _check_permission(self, request):
|
"""""" Check user permissions.
|
:raises: Forbidden, if user doesn't have access to the resource.
|
""""""
|
if self.access_controller:
|
self.access_controller.check_perm(request, self)"
|
4914,"def print_devices_change_callback(devices, key, new):
|
""""""Print the reply from &devices() and highlight errors.""""""
|
dev = devices[key]
|
print('- ', new, ' ', dev)
|
if dev['type'] == QSType.unknown:
|
print("" ERR decoding"")
|
elif dev['value'] == -1:
|
dev("" ERR decoding: -1?"")
|
qcord = pyqwikswitch.decode_qwikcord(dev['data'][pyqwikswitch.QS_VALUE])
|
if qcord is not None:
|
print(' qwikcord (CTAVG, CTsum) = ' + str(qcord))"
|
4915,"def print_item_callback(item):
|
""""""Print an item callback, used by &listen.""""""
|
print('&listen [{}, {}={}]'.format(
|
item.get('cmd', ''),
|
item.get('id', ''),
|
item.get('data', '')))"
|
4916,"def main():
|
""""""Quick test for QSUsb class.""""""
|
import argparse
|
parser = argparse.ArgumentParser()
|
parser.add_argument('--url', help='QSUSB URL [http://127.0.0.1:2020]',
|
default='http://127.0.0.1:2020')
|
parser.add_argument('--file', help='a test file from /&devices')
|
parser.add_argument('--test_ids', help='List of test IDs',
|
default='@0c2700,@0ac2f0')
|
args = parser.parse_args()
|
if args.file:
|
with open(args.file) as data_file:
|
data = json.load(data_file)
|
qsusb = pyqwikswitch.QSDevices(
|
print_devices_change_callback, print_devices_change_callback)
|
print_bad_data(data)
|
qsusb.set_qs_values(data)
|
return
|
print('Execute a basic test on server: {}\n'.format(args.url))
|
def qs_to_value(key, new):
|
print("" --> New value: {}={}"".format(key, new))
|
qsusb = QSUsb(args.url, 1, qs_to_value)
|
print('Version: ' + qsusb.version())
|
qsusb.set_qs_values()
|
qsusb.listen(print_item_callback, timeout=5)
|
print(""Started listening"")
|
try:
|
# Do some test while listening
|
if args.test_ids and len(args.test_ids) > 0:
|
test_devices_set(qsusb.devices, args.test_ids.split(','))
|
print(""\n\nListening for 60 seconds (test buttons now)\n"")
|
sleep(60)
|
except KeyboardInterrupt:
|
pass
|
finally:
|
qsusb.stop() # Close all threads
|
print(""Stopped listening"")"
|
4917,"def get(self):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.