pymensago/iscmds.py
def usercard(conn: ServerConnection, owner: utils.MAddress, start_index: int, 
	end_index: int) -> RetVal:
	'''Obtains a user's keycard'''
	
	if not owner.is_valid():
		return RetVal(ErrBadValue, 'invalid owner address')
	
	status = conn.send_message({
		'Action': 'USERCARD',
		'Data': {
			'Owner': owner.as_string(),
			'Start-Index': str(start_index),
			'End-Index': str(end_index)
		}
	})
	if status.error():
		return status

	response = conn.read_response(server_response)
	if response.error():
		return response
	
	data_size = int(response['Data']['Total-Size'])
	status = conn.send_message({'Action':'TRANSFER'})
	if status.error():
		return status

	chunks = list()
	tempstr = conn.read()
	data_read = len(tempstr)
	chunks.append(tempstr)
	while data_read < data_size:
		tempstr = conn.read()
		data_read = data_read + len(tempstr)
		chunks.append(tempstr)

	if data_read != data_size:
		return RetVal(ErrServerError, 'Mismatch in size of data returned from server')
	
	# Now that the data has been downloaded, we put it together and split it properly. 
	entry_strings = ''.join(chunks).split('----- END USER ENTRY -----\r\n')
	if entry_strings[-1] == '':
		entry_strings.pop()
	
	card = Keycard()
	card.type = 'User'
	for entrystr in entry_strings:
		if entrystr.startswith('----- BEGIN USER ENTRY -----\r\n'):
			entry = UserEntry()
			status = entry.set(entrystr[29:].encode())
			if status.error():
				return status
			card.entries.append(entry)
	
	return RetVal().set_value('card', card)
Obtains a user's keycard
Obtains a user's keycard
Obtains a user ' s keycard
def usercard(conn: ServerConnection, owner: utils.MAddress, start_index: int, 
	end_index: int) -> RetVal:
	if not owner.is_valid():
		return RetVal(ErrBadValue, 'invalid owner address')
	status = conn.send_message({
		'Action': 'USERCARD',
		'Data': {
			'Owner': owner.as_string(),
			'Start-Index': str(start_index),
			'End-Index': str(end_index)
		}
	})
	if status.error():
		return status
	response = conn.read_response(server_response)
	if response.error():
		return response
	data_size = int(response['Data']['Total-Size'])
	status = conn.send_message({'Action':'TRANSFER'})
	if status.error():
		return status
	chunks = list()
	tempstr = conn.read()
	data_read = len(tempstr)
	chunks.append(tempstr)
	while data_read < data_size:
		tempstr = conn.read()
		data_read = data_read + len(tempstr)
		chunks.append(tempstr)
	if data_read != data_size:
		return RetVal(ErrServerError, 'Mismatch in size of data returned from server')
	entry_strings = ''.join(chunks).split('----- END USER ENTRY -----\r\n')
	if entry_strings[-1] == '':
		entry_strings.pop()
	card = Keycard()
	card.type = 'User'
	for entrystr in entry_strings:
		if entrystr.startswith('----- BEGIN USER ENTRY -----\r\n'):
			entry = UserEntry()
			status = entry.set(entrystr[29:].encode())
			if status.error():
				return status
			card.entries.append(entry)
	return RetVal().set_value('card', card)
def usercard ( conn : ServerConnection , owner : utils . MAddress , start_index : int , end_index : int ) -> RetVal : if not owner . is_valid ( ) : return RetVal ( ErrBadValue , 'invalid owner address' ) status = conn . send_message ( { 'Action' : 'USERCARD' , 'Data' : { 'Owner' : owner . as_string ( ) , 'Start-Index' : str ( start_index ) , 'End-Index' : str ( end_index ) } } ) if status . error ( ) : return status response = conn . read_response ( server_response ) if response . error ( ) : return response data_size = int ( response [ 'Data' ] [ 'Total-Size' ] ) status = conn . send_message ( { 'Action' : 'TRANSFER' } ) if status . error ( ) : return status chunks = list ( ) tempstr = conn . read ( ) data_read = len ( tempstr ) chunks . append ( tempstr ) while data_read < data_size : tempstr = conn . read ( ) data_read = data_read + len ( tempstr ) chunks . append ( tempstr ) if data_read != data_size : return RetVal ( ErrServerError , 'Mismatch in size of data returned from server' ) entry_strings = '' . join ( chunks ) . split ( '----- END USER ENTRY -----\r\n' ) if entry_strings [ - 1 ] == '' : entry_strings . pop ( ) card = Keycard ( ) card . type = 'User' for entrystr in entry_strings : if entrystr . startswith ( '----- BEGIN USER ENTRY -----\r\n' ) : entry = UserEntry ( ) status = entry . set ( entrystr [ 29 : ] . encode ( ) ) if status . error ( ) : return status card . entries . append ( entry ) return RetVal ( ) . set_value ( 'card' , card )
Obtains a user's keycard
Obtains a user ' s keycard
'''Obtains a user's keycard''' # Now that the data has been downloaded, we put it together and split it properly. 
conn
ServerConnection
owner
utils.MAddress
start_index
int
end_index
int