<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sign(allocate_quota_request):
 """Obtains a signature for an operation in a `AllocateQuotaRequest` Args: op (:class:`endpoints_management.gen.servicecontrol_v1_messages.Operation`):
 an operation used in a `AllocateQuotaRequest` Returns: string: a secure hash generated from the operation """

    if not isinstance(allocate_quota_request, sc_messages.AllocateQuotaRequest):
        raise ValueError(u'Invalid request')
    op = allocate_quota_request.allocateOperation
    if op is None or op.methodName is None or op.consumerId is None:
        logging.error(u'Bad %s: not initialized => not signed', allocate_quota_request)
        raise ValueError(u'allocate_quota request must be initialized with an operation')
    md5 = hashlib.md5()
    md5.update(op.methodName.encode('utf-8'))
    md5.update(b'\x00')
    md5.update(op.consumerId.encode('utf-8'))
    if op.labels:
        signing.add_dict_to_hash(md5, encoding.MessageToPyValue(op.labels))
    for value_set in op.quotaMetrics:
        md5.update(b'\x00')
        md5.update(value_set.metricName.encode('utf-8'))
        for mv in value_set.metricValues:
            metric_value.update_hash(md5, mv)

    md5.update(b'\x00')
    return md5.digest()