def get_payload(self, payload_class, payload_key = None,<EOL>specialize = False):
if self._payload is None:<EOL><INDENT>self.decode_payload()<EOL><DEDENT>if payload_class is None:<EOL><INDENT>if self._payload:<EOL><INDENT>payload = self._payload[<NUM_LIT:0>]<EOL>if specialize and isinstance(payload, XMLPayload):<EOL><INDENT>klass = payload_class_for_element_name(<EOL>payload.element.tag)<EOL>if klass is not XMLPayload:<EOL><INDENT>payload = klass.from_xml(payload.element)<EOL>self._payload[<NUM_LIT:0>] = payload<EOL><DEDENT><DEDENT>return payload<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>elements = payload_class._pyxmpp_payload_element_name<EOL>for i, payload in enumerate(self._payload):<EOL><INDENT>if isinstance(payload, XMLPayload):<EOL><INDENT>if payload_class is not XMLPayload:<EOL><INDENT>if payload.xml_element_name not in elements:<EOL><INDENT>continue<EOL><DEDENT>payload = payload_class.from_xml(payload.element)<EOL><DEDENT><DEDENT>elif not isinstance(payload, payload_class):<EOL><INDENT>continue<EOL><DEDENT>if payload_key is not None and payload_key != payload.handler_key():<EOL><INDENT>continue<EOL><DEDENT>self._payload[i] = payload<EOL>return payload<EOL><DEDENT>return None<EOL>
Get the first payload item matching the given class
        and optional key.

        Payloads may be addressed using a specific payload class or
        via the generic `XMLPayload` element, though the `XMLPayload`
        representation is available only as long as the element is not
        requested by a more specific type.

        :Parameters:
            - `payload_class`: requested payload class, a subclass of
              `StanzaPayload`. If `None` get the first payload in whatever
              class is available.
            - `payload_key`: optional key for additional match. When used
              with `payload_class` = `XMLPayload` this selects the element to
              match
            - `specialize`: If `True`, and `payload_class` is `None` then
              return object of a specialized `StanzaPayload` subclass whenever
              possible
        :Types:
            - `payload_class`: `StanzaPayload`
            - `specialize`: `bool`

        :Return: payload element found or `None`
        :Returntype: `StanzaPayload`