Extracted code from flask session libary.
I extracted the code we needed from flask session library. I don't see any other way to fix werkzeug issue because:
- flask session project is no longer maintained and it's author doesn't respond to messages,
- we can't pin a version of a dependency.
Updated code uses new library (cachelib) maintained by pallets project, so we don't need do worry about werkzeug's version anymore.