code: def _parse_block_ref(cls, block_ref, deprecated=False):
          
  
          if deprecated and block_ref is None:
              return None
  
          if isinstance(block_ref, LocalId):
              return block_ref
  
          is_valid_deprecated = deprecated and cls.DEPRECATED_ALLOWED_ID_RE.match(block_ref)
          is_valid = cls.ALLOWED_ID_RE.match(block_ref)
  
          if is_valid or is_valid_deprecated:
              return block_ref
          else:
              raise InvalidKeyError(cls, block_ref)
docs: Given `block_ref`, tries to parse it into a valid block reference.
  
          Returns `block_ref` if it is valid.
  
          Raises:
              InvalidKeyError: if `block_ref` is invalid.