def _get_realm(self, realms, charset):
if realms:<EOL><INDENT>realm = realms[<NUM_LIT:0>]<EOL>ap_realms = self.in_properties.get("<STR_LIT>")<EOL>if ap_realms is not None:<EOL><INDENT>realms = (unicode(r, charset) for r in realms)<EOL>for ap_realm in ap_realms:<EOL><INDENT>if ap_realm in realms:<EOL><INDENT>realm = ap_realm<EOL>break<EOL><DEDENT><DEDENT><DEDENT>realm = realm.decode(charset)<EOL><DEDENT>else:<EOL><INDENT>realm = self.in_properties.get("<STR_LIT>")<EOL><DEDENT>if realm is not None:<EOL><INDENT>self.realm = realm<EOL>try:<EOL><INDENT>realm = realm.encode(charset)<EOL><DEDENT>except UnicodeError:<EOL><INDENT>logger.debug("<STR_LIT>"<EOL>.format(charset))<EOL>return Failure("<STR_LIT>")<EOL><DEDENT><DEDENT>return realm<EOL>
Choose a realm from the list specified by the server.

        :Parameters:
            - `realms`: the realm list.
            - `charset`: encoding of realms on the list.
        :Types:
            - `realms`: `list` of `bytes`
            - `charset`: `bytes`

        :return: the realm chosen or a failure indicator.
        :returntype: `bytes` or `Failure`