#NEWLINE# def updated_topology_description( topology_description , server_description ) : #NEWLINE# #INDENT# 'Return an updated copy of a TopologyDescription.\n\n    :Parameters:\n      - `topology_description`: the current TopologyDescription\n      - `server_description`: a new ServerDescription that resulted from\n        an ismaster call\n\n    Called after attempting (successfully or not) to call ismaster on the\n    server at server_description.address. Does not modify topology_description.\n    ' #NEWLINE# address = server_description . address #NEWLINE# topology_type = topology_description . topology_type #NEWLINE# set_name = topology_description . replica_set_name #NEWLINE# max_set_version = topology_description . max_set_version #NEWLINE# max_election_id = topology_description . max_election_id #NEWLINE# server_type = server_description . server_type #NEWLINE# sds = topology_description . server_descriptions ( ) #NEWLINE# sds [ address ] = server_description #NEWLINE# if ( topology_type == TOPOLOGY_TYPE . Single ) : #NEWLINE# #INDENT# return TopologyDescription ( TOPOLOGY_TYPE . Single , sds , set_name , max_set_version , max_election_id ) #NEWLINE# #UNINDENT# if ( topology_type == TOPOLOGY_TYPE . Unknown ) : #NEWLINE# #INDENT# if ( server_type == SERVER_TYPE . Standalone ) : #NEWLINE# #INDENT# sds . pop ( address ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( server_type not in ( SERVER_TYPE . Unknown , SERVER_TYPE . RSGhost ) ) : #NEWLINE# #INDENT# topology_type = _SERVER_TYPE_TO_TOPOLOGY_TYPE [ server_type ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( topology_type == TOPOLOGY_TYPE . Sharded ) : #NEWLINE# #INDENT# if ( server_type not in ( SERVER_TYPE . Mongos , SERVER_TYPE . Unknown ) ) : #NEWLINE# #INDENT# sds . pop ( address ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( topology_type == TOPOLOGY_TYPE . ReplicaSetNoPrimary ) : #NEWLINE# #INDENT# if ( server_type in ( SERVER_TYPE . Standalone , SERVER_TYPE . Mongos ) ) : #NEWLINE# #INDENT# sds . pop ( address ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( server_type == SERVER_TYPE . RSPrimary ) : #NEWLINE# #INDENT# ( topology_type , set_name , max_set_version , max_election_id ) = _update_rs_from_primary ( sds , set_name , server_description , max_set_version , max_election_id ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( server_type in ( SERVER_TYPE . RSSecondary , SERVER_TYPE . RSArbiter , SERVER_TYPE . RSOther ) ) : #NEWLINE# #INDENT# ( topology_type , set_name ) = _update_rs_no_primary_from_member ( sds , set_name , server_description ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( topology_type == TOPOLOGY_TYPE . ReplicaSetWithPrimary ) : #NEWLINE# #INDENT# if ( server_type in ( SERVER_TYPE . Standalone , SERVER_TYPE . Mongos ) ) : #NEWLINE# #INDENT# sds . pop ( address ) #NEWLINE# topology_type = _check_has_primary ( sds ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( server_type == SERVER_TYPE . RSPrimary ) : #NEWLINE# #INDENT# ( topology_type , set_name , max_set_version , max_election_id ) = _update_rs_from_primary ( sds , set_name , server_description , max_set_version , max_election_id ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( server_type in ( SERVER_TYPE . RSSecondary , SERVER_TYPE . RSArbiter , SERVER_TYPE . RSOther ) ) : #NEWLINE# #INDENT# topology_type = _update_rs_with_primary_from_member ( sds , set_name , server_description ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# topology_type = _check_has_primary ( sds ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return TopologyDescription ( topology_type , sds , set_name , max_set_version , max_election_id )