def extractpoline(line): """Remove quote and unescape line from po file. @param line: a quoted line from a po file (msgid or msgstr) """ extracted = quote.extractwithoutquotes(line, '"', '"', '\\', includeescapes=unescapehandler)[0] return extracted
def unquotefromdtd(source): """unquotes a quoted dtd definition""" # extract the string, get rid of quoting if len(source) == 0: source = '""' # The quote characters should be the first and last characters in the # string. Of course there could also be quote characters within the string. quotechar = source[0] extracted, quotefinished = quote.extractwithoutquotes(source, quotechar, quotechar, allowreentry=False) extracted = extracted.decode('utf-8') if quotechar == "'": extracted = extracted.replace("'", "'") extracted = extracted.replace(""", "\"") extracted = extracted.replace(""", "\"") # FIXME these should probably be handled with a lookup extracted = extracted.replace("»", u"»") extracted = extracted.replace("%", "%") extracted = extracted.replace("%", "%") extracted = extracted.replace("%", "%") #extracted = extracted.replace("<", "<") # Not really so useful. #extracted = extracted.replace(">", ">") # Not really so useful. return extracted
def extractpoline(line): """Remove quote and unescape line from po file. :param line: a quoted line from a po file (msgid or msgstr) .. deprecated:: 1.10 Replaced by :func:`unescape`. :func:`extractpoline` is kept to allow tests of correctness, and in case of external users. """ extracted = quote.extractwithoutquotes(line, '"', '"', '\\', includeescapes=unescapehandler)[0] return extracted
def unquotefromdtd(source): """unquotes a quoted dtd definition""" # extract the string, get rid of quoting if len(source) == 0: source = '""' quotechar = source[0] extracted, quotefinished = quote.extractwithoutquotes(source, quotechar, quotechar, allowreentry=False) if quotechar == "'" and "'" in extracted: extracted = extracted.replace("'", "'") # the quote characters should be the first and last characters in the string # of course there could also be quote characters within the string; not handled here return extracted
def unquotefromdtd(source): """unquotes a quoted dtd definition""" # extract the string, get rid of quoting if len(source) == 0: source = '""' # The quote characters should be the first and last characters in the # string. Of course there could also be quote characters within the string. quotechar = source[0] extracted, quotefinished = quote.extractwithoutquotes(source, quotechar, quotechar, allowreentry=False) extracted = extracted.decode('utf-8') if quotechar == "'": extracted = extracted.replace("'", "'") extracted = quote.entitydecode(extracted, _DTD_NAME2CODEPOINT) return extracted
def unquotefromdtd(source): """unquotes a quoted dtd definition""" # extract the string, get rid of quoting if len(source) == 0: source = '""' # The quote characters should be the first and last characters in the # string. Of course there could also be quote characters within the string. quotechar = source[0] extracted, quotefinished = quote.extractwithoutquotes(source, quotechar, quotechar, allowreentry=False) if quotechar == "'": extracted = extracted.replace("'", "'") return quote.entitydecode(extracted, _DTD_NAME2CODEPOINT)
def unquotefromdtd(source): """unquotes a quoted dtd definition""" # extract the string, get rid of quoting if len(source) == 0: source = '""' # The quote characters should be the first and last characters in the # string. Of course there could also be quote characters within the string. quotechar = source[0] extracted, quotefinished = quote.extractwithoutquotes(source, quotechar, quotechar, allowreentry=False) extracted = extracted.decode('utf-8') if quotechar == "'": extracted = extracted.replace("'", "'") extracted = extracted.replace(""", "\"") extracted = extracted.replace(""", "\"") # FIXME these should probably be handled with a lookup extracted = extracted.replace("»", "»") extracted = extracted.replace("%", "%") extracted = extracted.replace("%", "%") extracted = extracted.replace("%", "%") #extracted = extracted.replace("<", "<") # Not really so useful. #extracted = extracted.replace(">", ">") # Not really so useful. return extracted
def test_extractwithoutquotes_passfunc(): """tests the extractwithoutquotes function with a function for includeescapes as a parameter""" assert quote.extractwithoutquotes( "<test \\r \\n \\t \\\\>", "<", ">", "\\", 0, isnewlineortabescape ) == ("test r \\n \\t \\", False)
def test_extractwithoutquotes(): """tests the extractwithoutquotes function""" assert quote.extractwithoutquotes("the <quoted> part", "<", ">", "\\", 0) == ( "quoted", False, ) assert quote.extractwithoutquotes("the 'quoted' part", "'", "'", "\\", 0) == ( "quoted", False, ) assert quote.extractwithoutquotes( "the 'isn\\'t escaping fun' part", "'", "'", "\\", 0 ) == ("isn\\'t escaping fun", False) assert quote.extractwithoutquotes("the 'isn\\'t something ", "'", "'", "\\", 0) == ( "isn\\'t something ", True, ) assert quote.extractwithoutquotes("<quoted>\\", "<", ">", "\\", 0) == ( "quoted", False, ) assert quote.extractwithoutquotes("<quoted>\\\\<again>", "<", ">", "\\", 0) == ( "quotedagain", False, ) assert quote.extractwithoutquotes( "<quoted><again\\\\", "<", ">", "\\", 0, True ) == ("quotedagain\\\\", True) # don't include escapes... assert quote.extractwithoutquotes( "the 'isn\\'t escaping fun' part", "'", "'", "\\", 0, False ) == ("isn't escaping fun", False) assert quote.extractwithoutquotes( "the 'isn\\'t something ", "'", "'", "\\", 0, False ) == ("isn't something ", True) assert quote.extractwithoutquotes("<quoted\\", "<", ">", "\\", 0, False) == ( "quoted", True, ) assert quote.extractwithoutquotes( "<quoted><again\\\\", "<", ">", "\\", 0, False ) == ("quotedagain\\", True) # escaping of quote char assert quote.extractwithoutquotes("<quoted\\>", "<", ">", "\\", 0, False) == ( "quoted>", True, )
def test_extractwithoutquotes_passfunc(): """tests the extractwithoutquotes function with a function for includeescapes as a parameter""" assert quote.extractwithoutquotes("<test \\r \\n \\t \\\\>", "<", ">", "\\", 0, isnewlineortabescape) == ("test r \\n \\t \\", False)
def test_extractwithoutquotes(): """tests the extractwithoutquotes function""" assert quote.extractwithoutquotes("the <quoted> part", "<", ">", "\\", 0) == ("quoted", False) assert quote.extractwithoutquotes("the 'quoted' part", "'", "'", "\\", 0) == ("quoted", False) assert quote.extractwithoutquotes("the 'isn\\'t escaping fun' part", "'", "'", "\\", 0) == ("isn\\'t escaping fun", False) assert quote.extractwithoutquotes("the 'isn\\'t something ", "'", "'", "\\", 0) == ("isn\\'t something ", True) assert quote.extractwithoutquotes("<quoted>\\", "<", ">", "\\", 0) == ("quoted", False) assert quote.extractwithoutquotes("<quoted>\\\\<again>", "<", ">", "\\", 0) == ("quotedagain", False) assert quote.extractwithoutquotes("<quoted><again\\\\", "<", ">", "\\", 0, True) == ("quotedagain\\\\", True) # don't include escapes... assert quote.extractwithoutquotes("the 'isn\\'t escaping fun' part", "'", "'", "\\", 0, False) == ("isn't escaping fun", False) assert quote.extractwithoutquotes("the 'isn\\'t something ", "'", "'", "\\", 0, False) == ("isn't something ", True) assert quote.extractwithoutquotes("<quoted\\", "<", ">", "\\", 0, False) == ("quoted", True) assert quote.extractwithoutquotes("<quoted><again\\\\", "<", ">", "\\", 0, False) == ("quotedagain\\", True) # escaping of quote char assert quote.extractwithoutquotes("<quoted\\>", "<", ">", "\\", 0, False) == ("quoted>", True)