Ejemplo n.º 1
0
 def test_hashing(self):
     base = Sentinel('base')
     a_dict = {base: True}
     self.assertEquals(a_dict[Sentinel('base')], True)
     self.assertEquals(a_dict[base], True)
     self.assertNotIn(Sentinel('foo'), a_dict)
     self.assertNotIn('base', a_dict)
Ejemplo n.º 2
0
from xblock.exceptions import InvalidScopeError, NoSuchDefinition
from xblock.fields import Field, BlockScope, Scope, UserScope, Sentinel
from xblock.field_data import FieldData

from openedx.core.djangoapps.xblock.learning_context.manager import get_learning_context_impl
from openedx.core.djangolib.blockstore_cache import (
    get_bundle_version_files_cached,
    get_bundle_draft_files_cached,
)

log = logging.getLogger(__name__)

ActiveBlock = namedtuple('ActiveBlock', ['olx_hash', 'changed_fields'])

DELETED = Sentinel(
    'DELETED'
)  # Special value indicating a field was reset to its default value
CHILDREN_INCLUDES = Sentinel(
    'CHILDREN_INCLUDES'
)  # Key for a pseudo-field that stores the XBlock's children info

MAX_DEFINITIONS_LOADED = 100  # How many of the most recently used XBlocks' field data to keep in memory at max.


class BlockInstanceUniqueKey(object):
    """
    An empty object used as a unique key for each XBlock instance, see
    get_weak_key_for_block() and BlockstoreFieldData._get_active_block(). Every
    XBlock instance will get a unique one of these keys, even if they are
    otherwise identical. Its purpose is similar to `id(block)`.
    """
Ejemplo n.º 3
0
 def test_equality(self):
     base = Sentinel('base')
     self.assertEquals(base, base)
     self.assertEquals(base, Sentinel('base'))
     self.assertNotEquals(base, Sentinel('foo'))
     self.assertNotEquals(base, 'base')
Ejemplo n.º 4
0
import logging

from xblock.exceptions import InvalidScopeError, NoSuchDefinition
from xblock.fields import Field, BlockScope, Scope, UserScope, Sentinel
from xblock.field_data import FieldData

from openedx.core.djangolib.blockstore_cache import (
    get_bundle_version_files_cached,
    get_bundle_draft_files_cached,
)

log = logging.getLogger(__name__)

ActiveBlock = namedtuple('ActiveBlock', ['olx_hash', 'changed_fields'])

DELETED = Sentinel('DELETED')  # Special value indicating a field was reset to its default value

MAX_DEFINITIONS_LOADED = 100  # How many of the most recently used XBlocks' field data to keep in memory at max.


class BlockInstanceUniqueKey(object):
    """
    An empty object used as a unique key for each XBlock instance, see
    get_weak_key_for_block() and BlockstoreFieldData._get_active_block(). Every
    XBlock instance will get a unique one of these keys, even if they are
    otherwise identical. Its purpose is similar to `id(block)`.
    """


def get_weak_key_for_block(block):
    """