from __future__ import absolute_import

from xblock.runtime import KeyValueStore

class SessionKeyValueStore(KeyValueStore):
    def __init__(self, request):
        self._session = request.session

    def get(self, key):
        return self._session[tuple(key)]

    def set(self, key, value):
        self._session[tuple(key)] = value

    def delete(self, key):
        del self._session[tuple(key)]

    def has(self, key):
        return tuple(key) in self._session

from __future__ import absolute_import

from xblock.runtime import KeyValueStore


def stringify(key):
    return repr(tuple(key))


class SessionKeyValueStore(KeyValueStore):
    def __init__(self, request):
        self._session = request.session

    def get(self, key):
        return self._session[stringify(key)]

    def set(self, key, value):
        self._session[stringify(key)] = value

    def delete(self, key):
        del self._session[stringify(key)]

    def has(self, key):
        return stringify(key) in self._session

Use strings instead of tuples as keys in SessionKeyValueStore
Use strings instead of tuples as keys in SessionKeyValueStore

Some Django packages expect only strings as keys in the user session,
and it is also a recommended practice in the Django manual.

  from __future__ import absolute_import
  
  from xblock.runtime import KeyValueStore
+ 
+ 
+ def stringify(key):
+     return repr(tuple(key))
+ 
  
  class SessionKeyValueStore(KeyValueStore):
      def __init__(self, request):
          self._session = request.session
  
      def get(self, key):
-         return self._session[tuple(key)]
+         return self._session[stringify(key)]
  
      def set(self, key, value):
-         self._session[tuple(key)] = value
+         self._session[stringify(key)] = value
  
      def delete(self, key):
-         del self._session[tuple(key)]
+         del self._session[stringify(key)]
  
      def has(self, key):
-         return tuple(key) in self._session
+         return stringify(key) in self._session
  
Use strings instead of tuples as keys in SessionKeyValueStore
## Code Before:
from __future__ import absolute_import

from xblock.runtime import KeyValueStore

class SessionKeyValueStore(KeyValueStore):
    def __init__(self, request):
        self._session = request.session

    def get(self, key):
        return self._session[tuple(key)]

    def set(self, key, value):
        self._session[tuple(key)] = value

    def delete(self, key):
        del self._session[tuple(key)]

    def has(self, key):
        return tuple(key) in self._session

## Instruction:
Use strings instead of tuples as keys in SessionKeyValueStore
## Code After:
from __future__ import absolute_import

from xblock.runtime import KeyValueStore


def stringify(key):
    return repr(tuple(key))


class SessionKeyValueStore(KeyValueStore):
    def __init__(self, request):
        self._session = request.session

    def get(self, key):
        return self._session[stringify(key)]

    def set(self, key, value):
        self._session[stringify(key)] = value

    def delete(self, key):
        del self._session[stringify(key)]

    def has(self, key):
        return stringify(key) in self._session
