MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / socket_set_role

Function socket_set_role

web/pgadmin/tools/psql/__init__.py:506–536  ·  view source on GitHub ↗

This function sets the role used to connect to server. :param data: User input from socket.

(data)

Source from the content-addressed store, hash-verified

504
505@sio.on('socket_set_role', namespace='/pty')
506def socket_set_role(data):
507 """
508 This function sets the role used to connect to server.
509 :param data: User input from socket.
510 """
511 try:
512 if request.sid in app.config['sessions']:
513 # checking if role contains special characters and quoting it.
514 if re.search('[^a-z0-9_]', data['role']):
515 data['role'] = data['role'].replace('"', '""')
516 data['role'] = '"{0}"'.format(data['role'])
517
518 input_data = "SET ROLE {0};".format(data['role'])
519 if _platform == 'win32':
520 app.config['sessions'][request.sid].write(
521 "{0}".format(input_data))
522 app.config['sessions'][request.sid].write("\r\n")
523 else:
524 os.write(app.config['sessions'][request.sid],
525 input_data.encode())
526 os.write(app.config['sessions'][request.sid], '\n'.encode())
527 except Exception:
528 # Delete socket id from sessions.
529 # request.sid: refer request.sid as socket id.
530 sio.emit('pty-output',
531 {
532 'result': gettext('Invalid session.\r\n'),
533 'error': True
534 },
535 namespace='/pty', room=request.sid)
536 del app.config['sessions'][request.sid]
537
538
539@sio.on('resize', namespace='/pty')

Callers

nothing calls this directly

Calls 4

gettextFunction · 0.85
searchMethod · 0.80
emitMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected