1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
# -*- coding: utf-8 -*-
# Editobj3
# Copyright (C) 2007-2014 Jean-Baptiste LAMY
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from html import escape as escape
def html_escape(s): return escape(s).replace("\n", "<br/>")
def html_escape_arg(s): return escape(s).replace('"', """)
def html_js_escape(s): return escape(s).replace('"', '\\"').replace("\n", "\\n")
def js_escape(s): return s.replace('"', '\\"').replace("\n", "\\n")
NEED_UPDATES = set()
class User(object):
def __init__(self, name, password = ""):
self.name = name
self.password = password
self._obj2id = {}
self._id2obj = {}
self.next_id = 1
self.ws_handlers = []
self.urls = {}
USERS[name] = self
def __repr__(self): return "<%s %s>" % (self.__class__.__name__, self.name)
def get_user(self): return self
def obj2id(self, obj):
if not obj in self._obj2id:
self._obj2id[obj ] = str(self.next_id)
self._id2obj[str(self.next_id)] = obj
self.next_id += 1
return self._obj2id[obj]
def id2obj(self, id):
return self._id2obj[id]
def register_url(self, path, content):
self.urls[path] = content
def register_url_for_local_file(self, path, filename):
self.urls[path] = URLForLocalFile(filename)
class URLForLocalFile(object):
def __init__(self, filename):
self.filename = filename
USERS = {}
GUEST = User("guest")
|