'Purge all undelivered messages from a queue specified by name.
An internal method to purge all undelivered messages from a queue
specified by name. If the queue does not exist a
:class:`qpid.messaging.exceptions.NotFound` exception is raised.
The queue message depth is first checked, and then the broker is
asked to purge that number of messages. The integer number of
messages requested to be purged is returned. The actual number of
messages purged may be different than the requested number of
messages to purge (see below).
Sometimes delivered messages are asked to be purged, but are not.
This case fails silently, which is the correct behavior when a
message that has been delivered to a different consumer, who has
not ACKed the message, and still has an active session with the
broker. Messages in that case are not safe for purging and will be
retained by the broker. The client is unable to change this
delivery behavior.
This is an internal method. External calls for purge functionality
should be done using :meth:`queue_purge`.
:param queue: the name of the queue to be purged
:type queue: str
:return: The number of messages requested to be purged.
:rtype: int
:raises: :class:`qpid.messaging.exceptions.NotFound` if the queue
being purged cannot be found.'

def _purge(self, queue):

    queue_to_purge = self._broker.getQueue(queue)
    if (queue_to_purge is None):
        error_text = u"NOT_FOUND    -    no    queue    '{0}'".format(queue)
        raise NotFound(code=404, text=error_text)
    message_count = queue_to_purge.values[u'msgDepth']
    if (message_count > 0):
        queue_to_purge.purge(message_count)
    return message_count
