コード例 #1
0
 def __init__(self, name, create=True, timeout=None, version=None):
     if not Cache.IsValidName(name):
         raise exceptions.CacheNameInvalid(
             '[{}] is not a valid persistent cache name.'.format(name))
     self.name = name
     del create  # Unused in __init__. Subclass constructors may use this.
     self.timeout = timeout
     self.version = version
コード例 #2
0
  def EncodeName(cls, name):
    r"""Returns name encoded for filesystem portability.

    A cache name may be a file path. The part after the rightmost of
    ('/', '\\') is encoded with Table.EncodeName().

    Args:
      name: The cache name string to encode.

    Raises:
      CacheNameInvalid: For invalid cache names.

    Returns:
      Name encoded for filesystem portability.
    """
    basename_index = max(name.rfind('/'), name.rfind('\\')) + 1
    if not name[basename_index:]:
      raise exceptions.CacheNameInvalid(
          'Cache name [{}] is invalid.'.format(name))
    return name[:basename_index] + Table.EncodeName(name[basename_index:])