# Path: cherrypy/_cpcompat.py
#     def ntob(n, encoding='ISO-8859-1'):
#     def ntou(n, encoding='ISO-8859-1'):
#     def tonative(n, encoding='ISO-8859-1'):
#     def ntob(n, encoding='ISO-8859-1'):
#     def ntou(n, encoding='ISO-8859-1'):
#     def tonative(n, encoding='ISO-8859-1'):
# def assert_native(n):
# def base64_decode(n, encoding='ISO-8859-1'):
#     def sorted(i):
#     def reversed(x):
#     def get_daemon(t):
#     def set_daemon(t, val):
#     def get_daemon(t):
#     def set_daemon(t, val):
#     def HTTPDate(timeval=None):
#     def unquote_qs(atom, encoding, errors='strict'):
#     def unquote_qs(atom, encoding, errors='strict'):
#         def json_decode(s):
#         def _json_encode(s):
#         def json_encode(value):
#     def random20():
#     def random20():
#     def next(i):
#     def __get_daemon(self):
#     def __set_daemon(self, daemon):
# class SetDaemonProperty:
# 
# Path: cherrypy/lib/lockfile.py
# class LockError(Exception):
# class UnlockError(LockError):
# class LockFile(object):
# class SystemLockFile(object):
# class WindowsLockFile(SystemLockFile):
# class UnixLockFile(SystemLockFile):
#     def __init__(self, path):
#     def __init__(self, path):
#     def release(self):
#     def remove(self):
#     def __init__(self, path):
#     def release(self):
#     def remove(self):
#     def _unlock_file(self):
#     def _lock_file(self):
#     def _unlock_file(self):
#     def _lock_file(self):


import sys
import datetime
import os
import time
import threading
import types
import cherrypy
        import memcache
from cherrypy._cpcompat import copyitems, pickle, random20, unicodestr
from cherrypy.lib import httputil
from cherrypy.lib import lockfile
    def _get_file_path(self):
        f = os.path.join(self.storage_path, self.SESSION_PREFIX + self.id)
        if not os.path.abspath(f).startswith(self.storage_path):
            raise cherrypy.HTTPError(400, "Invalid session id in cookie.")
        return f

    def _exists(self):
        path = self._get_file_path()
        return os.path.exists(path)

    def _load(self, path=None):
        assert self.locked, "The session load without being locked.  Check your tools' priority levels."
        if path is None:
            path = self._get_file_path()
        try:
            f = open(path, "rb")
            try:
                return pickle.load(f)
            finally:
                f.close()
        except (IOError, EOFError):
            e = sys.exc_info()[1]
            if self.debug:
                cherrypy.log("Error loading the session pickle: %s" % e, 'TOOLS.SESSIONS')
            return None

    def _save(self, expiration_time):
        assert self.locked, "The session was saved without being locked.  Check your tools' priority levels."
        f = open(self._get_file_path(), "wb")
        try:

# Path: cherrypy/_cpcompat.py
#     def ntob(n, encoding='ISO-8859-1'):
#     def ntou(n, encoding='ISO-8859-1'):
#     def tonative(n, encoding='ISO-8859-1'):
#     def ntob(n, encoding='ISO-8859-1'):
#     def ntou(n, encoding='ISO-8859-1'):
#     def tonative(n, encoding='ISO-8859-1'):
# def assert_native(n):
# def base64_decode(n, encoding='ISO-8859-1'):
#     def sorted(i):
#     def reversed(x):
#     def get_daemon(t):
#     def set_daemon(t, val):
#     def get_daemon(t):
#     def set_daemon(t, val):
#     def HTTPDate(timeval=None):
#     def unquote_qs(atom, encoding, errors='strict'):
#     def unquote_qs(atom, encoding, errors='strict'):
#         def json_decode(s):
#         def _json_encode(s):
#         def json_encode(value):
#     def random20():
#     def random20():
#     def next(i):
#     def __get_daemon(self):
#     def __set_daemon(self, daemon):
# class SetDaemonProperty:
# 
# Path: cherrypy/lib/lockfile.py
# class LockError(Exception):
# class UnlockError(LockError):
# class LockFile(object):
# class SystemLockFile(object):
# class WindowsLockFile(SystemLockFile):
# class UnixLockFile(SystemLockFile):
#     def __init__(self, path):
#     def __init__(self, path):
#     def release(self):
#     def remove(self):
#     def __init__(self, path):
#     def release(self):
#     def remove(self):
#     def _unlock_file(self):
#     def _lock_file(self):
#     def _unlock_file(self):
#     def _lock_file(self):


# Path: cherrypy/lib/sessions.py
import sys
import datetime
import os
import time
import threading
import types
import cherrypy
        import memcache
from cherrypy._cpcompat import copyitems, pickle, random20, unicodestr
from cherrypy.lib import httputil
from cherrypy.lib import lockfile

    def _get_file_path(self):
        f = os.path.join(self.storage_path, self.SESSION_PREFIX + self.id)
        if not os.path.abspath(f).startswith(self.storage_path):
            raise cherrypy.HTTPError(400, "Invalid session id in cookie.")
        return f

    def _exists(self):
        path = self._get_file_path()
        return os.path.exists(path)

    def _load(self, path=None):
        assert self.locked, "The session load without being locked.  Check your tools' priority levels."
        if path is None:
            path = self._get_file_path()
        try:
            f = open(path, "rb")
            try:
                return pickle.load(f)
            finally:
                f.close()
        except (IOError, EOFError):
            e = sys.exc_info()[1]
            if self.debug:
                cherrypy.log("Error loading the session pickle: %s" % e, 'TOOLS.SESSIONS')
            return None

    def _save(self, expiration_time):
        assert self.locked, "The session was saved without being locked.  Check your tools' priority levels."
        f = open(self._get_file_path(), "wb")
        try:

            pickle.dump((self._data, expiration_time), f, self.pickle_protocol)