comparison MoinMoin/wikiutil.py @ 1355:a796d366f176

wikiutil.(un)quoteName for (un)quoting names in wiki markup, fix quoting bug
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 20 Aug 2006 20:58:49 +0200
parents 544b931cd965
children 563bfe02b04f
comparison
equal deleted inserted replaced
1354:26949e36ca0b 1355:a796d366f176
488 self._put_meta() # sync cache 488 self._put_meta() # sync cache
489 finally: 489 finally:
490 self.wlock.release() 490 self.wlock.release()
491 491
492 492
493 # Quoting of wiki names, file names, etc. (in the wiki markup) -----------------------------------
494
495 QUOTE_CHARS = u"'\""
496
497 def quoteName(name):
498 """ put quotes around a given name """
499 for quote_char in QUOTE_CHARS:
500 if quote_char not in name:
501 return u"%s%s%s" % (quote_char, name, quote_char)
502 else:
503 return name # XXX we need to be able to escape the quote char for worst case
504
505 def unquoteName(name):
506 """ if there are quotes around the name, strip them """
507 for quote_char in QUOTE_CHARS:
508 if quote_char == name[0] == name[-1]:
509 return name[1:-1]
510 else:
511 return name
512
493 ############################################################################# 513 #############################################################################
494 ### InterWiki 514 ### InterWiki
495 ############################################################################# 515 #############################################################################
496 INTERWIKI_PAGE = "InterWikiMap" 516 INTERWIKI_PAGE = "InterWikiMap"
497 517
592 try: 612 try:
593 wikiname, rest = wikiurl.split("/", 1) # for what is this used? 613 wikiname, rest = wikiurl.split("/", 1) # for what is this used?
594 except ValueError: 614 except ValueError:
595 wikiname, rest = 'Self', wikiurl 615 wikiname, rest = 'Self', wikiurl
596 first_char = rest[0] 616 first_char = rest[0]
597 if first_char in "'\"": # quoted pagename 617 if first_char in QUOTE_CHARS: # quoted pagename
598 pagename_linktext = rest[1:].split(first_char, 1) 618 pagename_linktext = rest[1:].split(first_char, 1)
599 else: # not quoted, split on whitespace 619 else: # not quoted, split on whitespace
600 pagename_linktext = rest.split(None, 1) 620 pagename_linktext = rest.split(None, 1)
601 if len(pagename_linktext) == 1: 621 if len(pagename_linktext) == 1:
602 pagename, linktext = pagename_linktext[0], "" 622 pagename, linktext = pagename_linktext[0], ""
820 """ return markup that can be used as link to page <pagename> """ 840 """ return markup that can be used as link to page <pagename> """
821 from MoinMoin.parser.text_moin_wiki import Parser 841 from MoinMoin.parser.text_moin_wiki import Parser
822 if re.match(Parser.word_rule + "$", pagename): 842 if re.match(Parser.word_rule + "$", pagename):
823 return pagename 843 return pagename
824 else: 844 else:
825 return u'["%s"]' % pagename 845 return u'["%s"]' % pagename # XXX use quoteName(pagename) later
826 846
827 ############################################################################# 847 #############################################################################
828 ### mimetype support 848 ### mimetype support
829 ############################################################################# 849 #############################################################################
830 import mimetypes 850 import mimetypes
858 MIMETYPES_spoil_mapping = {} # inverse mapping of above 878 MIMETYPES_spoil_mapping = {} # inverse mapping of above
859 for key, value in MIMETYPES_sanitize_mapping.items(): 879 for key, value in MIMETYPES_sanitize_mapping.items():
860 MIMETYPES_spoil_mapping[value] = key 880 MIMETYPES_spoil_mapping[value] = key
861 881
862 882
863 # mimetype stuff ------------------------------------------------------------
864 class MimeType(object): 883 class MimeType(object):
865 """ represents a mimetype like text/plain """ 884 """ represents a mimetype like text/plain """
866 885
867 def __init__(self, mimestr=None, filename=None): 886 def __init__(self, mimestr=None, filename=None):
868 self.major = self.minor = None # sanitized mime type and subtype 887 self.major = self.minor = None # sanitized mime type and subtype