Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1776)

Unified Diff: dfvfs/resolver/cache.py

Issue 329840043: [dfvfs] Made Unicode strings the default #204 and updated docstrings #182 (Closed)
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: dfvfs/resolver/cache.py
diff --git a/dfvfs/resolver/cache.py b/dfvfs/resolver/cache.py
index 313719b28bb2bbbd921a1d92675405a34dcee16b..b05213c47d0959ae0fce164212b566555632acda 100644
--- a/dfvfs/resolver/cache.py
+++ b/dfvfs/resolver/cache.py
@@ -1,17 +1,19 @@
# -*- coding: utf-8 -*-
"""The resolver objects cache."""
+from __future__ import unicode_literals
+
from dfvfs.lib import errors
class ObjectsCacheValue(object):
- """Class that implements the resolver object cache value."""
+ """Resolver object cache value."""
def __init__(self, vfs_object):
"""Initializes the resolver objects cache value object.
Args:
- vfs_object: the cached VFS object.
+ vfs_object (object): VFS object to cache.
"""
super(ObjectsCacheValue, self).__init__()
self._reference_count = 0
@@ -19,7 +21,7 @@ class ObjectsCacheValue(object):
@property
def reference_count(self):
- """The reference count."""
+ """int: reference count."""
return self._reference_count
def DecrementReferenceCount(self):
@@ -29,7 +31,7 @@ class ObjectsCacheValue(object):
RuntimeError: if the reference count is 0.
"""
if self._reference_count == 0:
- raise RuntimeError(u'Unable to decrement a reference count of 0.')
+ raise RuntimeError('Unable to decrement a reference count of 0.')
self._reference_count -= 1
@@ -43,20 +45,20 @@ class ObjectsCacheValue(object):
class ObjectsCache(object):
- """Class that implements the resolver object cache."""
+ """Resolver object cache."""
def __init__(self, maximum_number_of_cached_values):
"""Initializes the resolver objects cache object.
Args:
- maximum_number_of_cached_values: the maximum number of cached values.
+ maximum_number_of_cached_values (int): maximum number of cached values.
Raises:
ValueError: when the maximum number of cached objects is 0 or less.
"""
if maximum_number_of_cached_values <= 0:
raise ValueError(
- u'Invalid maximum number of cached objects value zero or less.')
+ 'Invalid maximum number of cached objects value zero or less.')
super(ObjectsCache, self).__init__()
self._maximum_number_of_cached_values = maximum_number_of_cached_values
@@ -68,19 +70,19 @@ class ObjectsCache(object):
This method ignores the cache value reference count.
Args:
- identifier: string that identifies the VFS object.
- vfs_object: the VFS object to cache.
+ identifier (str): VFS object identifier.
+ vfs_object (object): VFS object to cache.
Raises:
CacheFullError: if he maximum number of cached values is reached.
KeyError: if the VFS object already is cached.
"""
if identifier in self._values:
- raise KeyError(u'Object already cached for identifier: {0:s}'.format(
+ raise KeyError('Object already cached for identifier: {0:s}'.format(
identifier))
if len(self._values) == self._maximum_number_of_cached_values:
- raise errors.CacheFullError(u'Maximum number of cached values reached.')
+ raise errors.CacheFullError('Maximum number of cached values reached.')
self._values[identifier] = ObjectsCacheValue(vfs_object)
@@ -95,11 +97,10 @@ class ObjectsCache(object):
"""Retrieves the cache value based on the identifier.
Args:
- identifier: string that identifies the VFS object.
+ identifier (str): VFS object identifier.
Returns:
- The cache value object (instance of ObjectsCacheValue) or
- None if not cached.
+ ObjectsCacheValue: cache value object or None if not cached.
Raises:
RuntimeError: if the cache value is missing.
@@ -110,19 +111,18 @@ class ObjectsCache(object):
"""Retrieves the cache value for the cached object.
Args:
- vfs_object: the VFS object that was cached.
+ vfs_object (object): VFS object that was cached.
Returns:
- A tuple of the string that identifies the VFS object and
- the cache value object (instance of ObjectsCacheValue) or
- None if not cached.
+ tuple[str, ObjectsCacheValue]: identifier and cache value object or
+ (None, None) if not cached.
Raises:
RuntimeError: if the cache value is missing.
"""
for identifier, cache_value in iter(self._values.items()):
if not cache_value:
- raise RuntimeError(u'Missing cache value.')
+ raise RuntimeError('Missing cache value.')
if cache_value.vfs_object == vfs_object:
return identifier, cache_value
@@ -135,10 +135,10 @@ class ObjectsCache(object):
This method ignores the cache value reference count.
Args:
- identifier: string that identifies the VFS object.
+ identifier (str): VFS object identifier.
Returns:
- The cached VFS object or None if not cached.
+ object: cached VFS object or None if not cached.
"""
cache_value = self._values.get(identifier, None)
if not cache_value:
@@ -152,19 +152,19 @@ class ObjectsCache(object):
This method increments the cache value reference count.
Args:
- identifier: string that identifies the VFS object.
+ identifier (str): VFS object identifier.
Raises:
KeyError: if the VFS object is not found in the cache.
RuntimeError: if the cache value is missing.
"""
if identifier not in self._values:
- raise KeyError(u'Missing cached object for identifier: {0:s}'.format(
+ raise KeyError('Missing cached object for identifier: {0:s}'.format(
identifier))
cache_value = self._values[identifier]
if not cache_value:
- raise RuntimeError(u'Missing cache value for identifier: {0:s}'.format(
+ raise RuntimeError('Missing cache value for identifier: {0:s}'.format(
identifier))
cache_value.IncrementReferenceCount()
@@ -175,19 +175,19 @@ class ObjectsCache(object):
This method decrements the cache value reference count.
Args:
- identifier: string that identifies the VFS object.
+ identifier (str): VFS object identifier.
Raises:
KeyError: if the VFS object is not found in the cache.
RuntimeError: if the cache value is missing.
"""
if identifier not in self._values:
- raise KeyError(u'Missing cached object for identifier: {0:s}'.format(
+ raise KeyError('Missing cached object for identifier: {0:s}'.format(
identifier))
cache_value = self._values[identifier]
if not cache_value:
- raise RuntimeError(u'Missing cache value for identifier: {0:s}'.format(
+ raise RuntimeError('Missing cache value for identifier: {0:s}'.format(
identifier))
cache_value.DecrementReferenceCount()
@@ -198,13 +198,13 @@ class ObjectsCache(object):
This method ignores the cache value reference count.
Args:
- identifier: string that identifies the VFS object.
+ identifier (str): VFS object identifier.
Raises:
KeyError: if the VFS object is not found in the cache.
"""
if identifier not in self._values:
- raise KeyError(u'Missing cached object for identifier: {0:s}'.format(
+ raise KeyError('Missing cached object for identifier: {0:s}'.format(
identifier))
del self._values[identifier]
@@ -213,13 +213,13 @@ class ObjectsCache(object):
"""Sets the maximum number of cached values.
Args:
- maximum_number_of_cached_values: the maximum number of cached values.
+ maximum_number_of_cached_values (int): maximum number of cached values.
Raises:
ValueError: when the maximum number of cached objects is 0 or less.
"""
if maximum_number_of_cached_values <= 0:
raise ValueError(
- u'Invalid maximum number of cached objects value zero or less.')
+ 'Invalid maximum number of cached objects value zero or less.')
self._maximum_number_of_cached_values = maximum_number_of_cached_values

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b