def __init__(self, usersign, note=None): self.usersign = unicode(usersign) self.note = note if self.note: self.note = unicode(self.note) self._password = None self.roles = set()
def recipe(args): """Create or update a recipe with the recipe text on stdin: <recipe>""" try: recipe_name = args[0] except IndexError: usage('you must include a recipe name') from tiddlyweb.model.recipe import Recipe new_recipe = Recipe(recipe_name) content = sys.stdin.read() _put(new_recipe, unicode(content, 'UTF-8'), 'text')
def tiddler(args): """Import a single tiddler into an existing bag from stdin: <bag> <tiddler>""" try: bag_name, tiddler_name = args[0:3] except (IndexError, ValueError): usage('you must include a tiddler and bag name') from tiddlyweb.model.tiddler import Tiddler new_tiddler = Tiddler(tiddler_name) new_tiddler.bag = bag_name content = sys.stdin.read() _put(new_tiddler, unicode(content, 'UTF-8'), 'text')
def bag(args): """Create or update a bag with the json text on stdin: <bag>""" try: bag_name = args[0] except IndexError: usage('you must include a bag name') from tiddlyweb.model.bag import Bag new_bag = Bag(bag_name) content = sys.stdin.read() if not len(content): content = '{"policy":{}}' _put(new_bag, unicode(content, 'UTF-8'), 'json')
def fields_as(self, tiddler): """ Turn extended :py:class:`tiddler <tiddlyweb.model.tiddler.Tiddler>` fields into RFC 822-style header strings. """ fields = [] for key in tiddler.fields: if hasattr(tiddler, key): raise TiddlerFormatError( 'reserved key "%s" in fields of tiddler: %s' % (key, tiddler.title)) # XXX: TiddlyWiki legacy remnant? if not key.startswith('server.'): value = unicode(tiddler.fields[key]) fields.append('%s: %s' % (key, value.replace('\n', '\\n'))) return fields
def fields_as(self, tiddler): """ Turn extended :py:class:`tiddler <tiddlyweb.model.tiddler.Tiddler>` fields into RFC 822-style header strings. """ fields = [] for key in tiddler.fields: try: if hasattr(tiddler, key): raise TiddlerFormatError( 'reserved key "%s" in fields of tiddler: %s' % (key, tiddler.title)) except UnicodeEncodeError: pass # XXX: TiddlyWiki legacy remnant? if not key.startswith('server.'): value = unicode(tiddler.fields[key]) fields.append('%s: %s' % (key, value.replace('\n', '\\n'))) return fields
def parse_for_filters(query_string, environ=None): """ Take a string that looks like a ``CGI`` query string and parse it for filters. Return a tuple of a list of filter functions and a string of whatever was in the query string that did not result in a filter. """ if environ is None: environ = {} if ';' in query_string: strings = query_string.split(';') else: strings = query_string.split('&') filters = [] leftovers = [] for string in strings: query = parse_qs(string) try: key, value = list(query.items())[0] # We need to adapt to different types from the # query_string. It changes per Python version, # and per store (because of Python version). # Sometimes we will already be unicode here, # sometimes not. try: argument = unicode(value[0], 'UTF-8') except TypeError: argument = value[0] func = FILTER_PARSERS[key](argument) filters.append((func, (key, argument), environ)) except (KeyError, IndexError, ValueError): leftovers.append(string) leftovers = ';'.join(leftovers) return filters, leftovers
def parse_for_filters(query_string, environ=None): """ Take a string that looks like a ``CGI`` query string and parse it for filters. Return a tuple of a list of filter functions and a string of whatever was in the query string that did not result in a filter. """ if environ is None: environ = {} if ';' in query_string: strings = query_string.split(';') else: strings = query_string.split('&') filters = [] leftovers = [] for string in strings: query = parse_qs(string) try: key, value = list(query.items())[0] # We need to adapt to different types from the # query_string. It changes per Python version, # and per store (because of Python version). # Sometimes we will already be unicode here, # sometimes not. try: argument = unicode(value[0], 'UTF-8') except TypeError: argument = value[0] func = FILTER_PARSERS[key](argument) filters.append((func, (key, argument), environ)) except(KeyError, IndexError, ValueError): leftovers.append(string) leftovers = ';'.join(leftovers) return filters, leftovers
def current_timestring(): """ Translate the current UTC time into a TiddlyWiki conformat timestring. """ time_object = datetime.utcnow() return unicode(time_object.strftime('%Y%m%d%H%M%S'))
def add_role(self, role): """ Add the named ``role`` (a string) to this user. """ self.roles.add(unicode(role))