本文整理汇总了Python中translate.misc.quote.rstripeol函数的典型用法代码示例。如果您正苦于以下问题:Python rstripeol函数的具体用法?Python rstripeol怎么用?Python rstripeol使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rstripeol函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: convertline
def convertline(self, line):
returnline = u""
# handle multiline msgid if we're in one
if self.inmultilinemsgid:
msgid = quote.rstripeol(line).strip()
# see if there's more
self.inmultilinemsgid = (msgid[-1:] == '\\')
# if we're echoing...
if self.inecho:
returnline = line
# otherwise, this could be a comment
elif line.strip()[:1] == '#':
returnline = quote.rstripeol(line) + eol
else:
line = quote.rstripeol(line)
delimiter_char, delimiter_pos = self.personality.find_delimiter(line)
if quote.rstripeol(line)[-1:] == '\\':
self.inmultilinemsgid = True
if delimiter_pos == -1:
key = self.personality.key_strip(line)
delimiter = " %s " % self.personality.delimiters[0]
else:
key = self.personality.key_strip(line[:delimiter_pos])
# Calculate space around the equal sign
prespace = line[line.find(' ', len(key)):delimiter_pos]
postspacestart = len(line[delimiter_pos+1:])
postspaceend = len(line[delimiter_pos+1:].lstrip())
postspace = line[delimiter_pos+1:delimiter_pos+(postspacestart-postspaceend)+1]
delimiter = prespace + delimiter_char + postspace
if key in self.inputstore.locationindex and not self.inputstore.locationindex[key] is None:
unit = self.inputstore.locationindex[key]
if self.remove_untranslated and (unit.source == unit.target or
unit.isfuzzy() or
len(unit.target) == 0):
if unit.isfuzzy() and not self.includefuzzy or len(unit.target) == 0:
value = unit.source
returnline = u""
else:
if unit.isfuzzy() and not self.includefuzzy or len(unit.target) == 0:
value = unit.source
else:
value = unit.target
self.inecho = False
assert isinstance(value, unicode)
returnline = "%(key)s%(del)s%(value)s%(term)s%(eol)s" % \
{"key": "%s%s%s" % (self.personality.key_wrap_char,
key,
self.personality.key_wrap_char),
"del": delimiter,
"value": "%s%s%s" % (self.personality.value_wrap_char,
self.personality.encode(value),
self.personality.value_wrap_char),
"term": self.personality.pair_terminator,
"eol": eol,
}
else:
self.inecho = True
returnline = line + eol
assert isinstance(returnline, unicode)
return returnline
开发者ID:nickapos,项目名称:myBill,代码行数:60,代码来源:po2prop.py
示例2: convertline
def convertline(self, line):
line = unicode(line, 'utf-8')
returnline = ""
# handle multiline msgid if we're in one
if self.inmultilinemsgid:
# see if there's more
endpos = line.rfind("%s;" % self.quotechar)
# if there was no '; or the quote is escaped, we have to continue
if endpos >= 0 and line[endpos-1] != '\\':
self.inmultilinemsgid = False
# if we're echoing...
if self.inecho:
returnline = line
# otherwise, this could be a comment
elif line.strip()[:2] == '//' or line.strip()[:2] == '/*':
returnline = quote.rstripeol(line)+eol
else:
line = quote.rstripeol(line)
equalspos = line.find('=')
hashpos = line.find("#")
# if no equals, just repeat it
if equalspos == -1:
returnline = quote.rstripeol(line)+eol
elif 0 <= hashpos < equalspos:
# Assume that this is a '#' comment line
returnline = quote.rstripeol(line)+eol
# otherwise, this is a definition
else:
# now deal with the current string...
key = line[:equalspos].strip()
lookupkey = key.replace(" ", "")
# Calculate space around the equal sign
prespace = line[len(line[:equalspos].rstrip()):equalspos]
postspacestart = len(line[equalspos+1:])
postspaceend = len(line[equalspos+1:].lstrip())
postspace = line[equalspos+1:equalspos+(postspacestart-postspaceend)+1]
self.quotechar = line[equalspos+(postspacestart-postspaceend)+1]
inlinecomment_pos = line.rfind("%s;" % self.quotechar)
if inlinecomment_pos > -1:
inlinecomment = line[inlinecomment_pos+2:]
else:
inlinecomment = ""
if self.inputdict.has_key(lookupkey):
self.inecho = False
value = php.phpencode(self.inputdict[lookupkey], self.quotechar)
if isinstance(value, str):
value = value.decode('utf8')
returnline = key + prespace + "=" + postspace + self.quotechar + value + self.quotechar + ';' + inlinecomment + eol
else:
self.inecho = True
returnline = line+eol
# no string termination means carry string on to next line
endpos = line.rfind("%s;" % self.quotechar)
# if there was no '; or the quote is escaped, we have to continue
if endpos == -1 or line[endpos-1] == '\\':
self.inmultilinemsgid = True
if isinstance(returnline, unicode):
returnline = returnline.encode('utf-8')
return returnline
开发者ID:AndryulE,项目名称:kitsune,代码行数:59,代码来源:po2php.py
示例3: convertcomments
def convertcomments(self, thedtd, thepo):
entity = quote.rstripeol(thedtd.entity)
if len(entity) > 0:
thepo.addlocation(thedtd.entity)
for commenttype, comment in thedtd.comments:
# handle groups
if (commenttype == "locgroupstart"):
groupcomment = comment.replace('BEGIN', 'GROUP')
self.currentgroup = groupcomment
elif (commenttype == "locgroupend"):
groupcomment = comment.replace('END', 'GROUP')
self.currentgroup = None
# handle automatic comment
if commenttype == "automaticcomment":
thepo.addnote(comment, origin="developer")
# handle normal comments
else:
thepo.addnote(quote.stripcomment(comment), origin="developer")
# handle group stuff
if self.currentgroup is not None:
thepo.addnote(quote.stripcomment(self.currentgroup),
origin="translator")
if is_css_entity(entity):
thepo.addnote("Do not translate this. Only change the numeric values if you need this dialogue box to appear bigger",
origin="developer")
开发者ID:davedash,项目名称:translate,代码行数:25,代码来源:dtd2po.py
示例4: parse
def parse(self, propsrc):
"""Read the source of a properties file in and include them
as units."""
text, encoding = self.detect_encoding(propsrc, default_encodings=[self.personality.default_encoding, 'utf-8', 'utf-16'])
self.encoding = encoding
propsrc = text
newunit = propunit("", self.personality.name)
inmultilinevalue = False
for line in propsrc.split(u"\n"):
# handle multiline value if we're in one
line = quote.rstripeol(line)
if inmultilinevalue:
newunit.value += line.lstrip()
# see if there's more
inmultilinevalue = is_line_continuation(newunit.value)
# if we're still waiting for more...
if inmultilinevalue:
# strip the backslash
newunit.value = newunit.value[:-1]
if not inmultilinevalue:
# we're finished, add it to the list...
self.addunit(newunit)
newunit = propunit("", self.personality.name)
# otherwise, this could be a comment
# FIXME handle /* */ in a more reliable way
# FIXME handle // inline comments
elif (line.strip()[:1] in (u'#', u'!') or
line.strip()[:2] in (u"/*", u"//") or
line.strip()[:-2] == "*/"):
# add a comment
if line not in self.personality.drop_comments:
newunit.comments.append(line)
elif not line.strip():
# this is a blank line...
if str(newunit).strip():
self.addunit(newunit)
newunit = propunit("", self.personality.name)
else:
newunit.delimiter, delimiter_pos = self.personality.find_delimiter(line)
if delimiter_pos == -1:
newunit.name = self.personality.key_strip(line)
newunit.value = u""
self.addunit(newunit)
newunit = propunit("", self.personality.name)
else:
newunit.name = self.personality.key_strip(line[:delimiter_pos])
if is_line_continuation(line[delimiter_pos+1:].lstrip()):
inmultilinevalue = True
newunit.value = line[delimiter_pos+1:].lstrip()[:-1]
else:
newunit.value = self.personality.value_strip(line[delimiter_pos+1:])
self.addunit(newunit)
newunit = propunit("", self.personality.name)
# see if there is a leftover one...
if inmultilinevalue or len(newunit.comments) > 0:
self.addunit(newunit)
开发者ID:andynicholson,项目名称:translate,代码行数:58,代码来源:properties.py
示例5: getlocations
def getlocations(self):
"""Get a list of locations from sourcecomments in the PO unit
rtype: List
return: A list of the locations with '#: ' stripped
"""
locations = []
for sourcecomment in self.sourcecomments:
locations += quote.rstripeol(sourcecomment)[3:].split()
return locations
开发者ID:lehmannro,项目名称:translate,代码行数:11,代码来源:pypo.py
示例6: getlocations
def getlocations(self):
"""Get a list of locations from sourcecomments in the PO unit
rtype: List
return: A list of the locations with '#: ' stripped
"""
locations = []
for sourcecomment in self.sourcecomments:
locations += quote.rstripeol(sourcecomment)[3:].split()
for i, loc in enumerate(locations):
locations[i] = pocommon.unquote_plus(loc)
return locations
开发者ID:cc-archive,项目名称:pootle,代码行数:13,代码来源:pypo.py
示例7: parse
def parse(self, propsrc, personality="java"):
"""read the source of a properties file in and include them as units"""
newunit = propunit("", personality)
inmultilinevalue = False
propsrc = unicode(propsrc, default_encoding[personality])
for line in propsrc.split(u"\n"):
# handle multiline value if we're in one
line = quote.rstripeol(line)
if inmultilinevalue:
newunit.value += line.lstrip()
# see if there's more
inmultilinevalue = is_line_continuation(newunit.value)
# if we're still waiting for more...
if inmultilinevalue:
# strip the backslash
newunit.value = newunit.value[:-1]
if not inmultilinevalue:
# we're finished, add it to the list...
self.addunit(newunit)
newunit = propunit("", personality)
# otherwise, this could be a comment
elif line.strip()[:1] in (u'#', u'!'):
# add a comment
newunit.comments.append(line)
elif not line.strip():
# this is a blank line...
if str(newunit).strip():
self.addunit(newunit)
newunit = propunit("", personality)
else:
delimiter_char, delimiter_pos = find_delimiter(line)
if delimiter_pos == -1:
continue
# otherwise, this is a definition
else:
newunit.delimiter = delimiter_char
newunit.name = key_strip(line[:delimiter_pos])
newunit.value = line[delimiter_pos+1:].lstrip()
# backslash at end means carry string on to next line
if is_line_continuation(newunit.value):
inmultilinevalue = True
newunit.value = newunit.value[:-1]
else:
self.addunit(newunit)
newunit = propunit("", personality)
# see if there is a leftover one...
if inmultilinevalue or len(newunit.comments) > 0:
self.addunit(newunit)
开发者ID:lehmannro,项目名称:translate,代码行数:48,代码来源:properties.py
示例8: parse
def parse(self, input):
"""parses lines and adds them to the file"""
if not self.filename:
self.filename = getattr(input, 'name', '')
if hasattr(input, "read"):
src = input.read()
input.close()
else:
src = input
for line in src.split("\n"):
line = quote.rstripeol(line)
if not line:
continue
parts = line.split("\t")
thisline = ooline(parts)
self.addline(thisline)
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:16,代码来源:oo.py
示例9: _getmsgpartstr
def _getmsgpartstr(self, partname, partlines, partcomments=""):
if isinstance(partlines, dict):
partkeys = partlines.keys()
partkeys.sort()
return "".join(
[
self._getmsgpartstr("%s[%d]" % (partname, partkey), partlines[partkey], partcomments)
for partkey in partkeys
]
)
partstr = partname + " "
partstartline = 0
if len(partlines) > 0 and len(partcomments) == 0:
partstr += partlines[0]
partstartline = 1
elif len(partcomments) > 0:
if len(partlines) > 0 and len(unquotefrompo(partlines[:1])) == 0:
# if there is a blank leader line, it must come before the comment
partstr += partlines[0] + "\n"
# but if the whole string is blank, leave it in
if len(partlines) > 1:
partstartline += 1
else:
# All partcomments should start on a newline
partstr += '""\n'
# combine comments into one if more than one
if len(partcomments) > 1:
combinedcomment = []
for comment in partcomments:
comment = unquotefrompo([comment])
if comment.startswith("_:"):
comment = comment[len("_:") :]
if comment.endswith("\\n"):
comment = comment[: -len("\\n")]
# Before we used to strip. Necessary in some cases?
combinedcomment.append(comment)
partcomments = quoteforpo("_:%s" % "".join(combinedcomment))
# comments first, no blank leader line needed
partstr += "\n".join(partcomments)
partstr = quote.rstripeol(partstr)
else:
partstr += '""'
partstr += "\n"
# add the rest
for partline in partlines[partstartline:]:
partstr += partline + "\n"
return partstr
开发者ID:flyeven,项目名称:translate,代码行数:47,代码来源:pypo.py
示例10: query
def query(self, tmcontroller, unit):
query_str = unit.source
translation = []
err = c_int()
result = self.lt.translate_session_translate_text(
self.session, query_str,
self.source_lang, self.target_lang,
None, None, err
)
if result is None:
# TODO handle errors and cleanup errors
logging.warning("An error occured while getting a translation: %s" % err)
return
if not isinstance(result, unicode):
result = unicode(result, 'utf-8') # XXX: The encoding is just a guess
translation.append({
'source': query_str,
'target': quote.rstripeol(result),
#l10n: Try to keep this as short as possible. Feel free to transliterate in CJK languages for vertical display optimization.
'tmsource': _('libtranslate')
})
# TODO: drop any memory used by 'result'
self.emit('match-found', query_str, translation)
开发者ID:Ailick,项目名称:virtaal,代码行数:24,代码来源:libtranslate.py
示例11: parse
#.........这里部分代码省略.........
beforeentity = line[:entitypos].strip()
if beforeentity.startswith("#"):
self.hashprefix = beforeentity
self.entitypart = "start"
else:
self.unparsedlines.append(line)
if self.inentity:
if self.entitypart == "start":
# the entity definition
e = quote.findend(line, '<!ENTITY')
line = line[e:]
self.entitypart = "name"
self.entitytype = "internal"
if self.entitypart == "name":
s = 0
e = 0
while (e < len(line) and line[e].isspace()):
e += 1
self.space_pre_entity = ' ' * (e - s)
s = e
self.entity = ''
if (e < len(line) and line[e] == '%'):
self.entitytype = "external"
self.entityparameter = ""
e += 1
while (e < len(line) and line[e].isspace()):
e += 1
while (e < len(line) and not line[e].isspace()):
self.entity += line[e]
e += 1
s = e
assert quote.rstripeol(self.entity) == self.entity
while (e < len(line) and line[e].isspace()):
e += 1
self.space_pre_definition = ' ' * (e - s)
if self.entity:
if self.entitytype == "external":
self.entitypart = "parameter"
else:
self.entitypart = "definition"
# remember the start position and the quote character
if e == len(line):
self.entityhelp = None
e = 0
continue
elif self.entitypart == "definition":
self.entityhelp = (e, line[e])
self.instring = False
if self.entitypart == "parameter":
while (e < len(line) and line[e].isspace()):
e += 1
paramstart = e
while (e < len(line) and line[e].isalnum()):
e += 1
self.entityparameter += line[paramstart:e]
while (e < len(line) and line[e].isspace()):
e += 1
line = line[e:]
e = 0
if not line:
continue
if line[0] in ('"', "'"):
self.entitypart = "definition"
self.entityhelp = (e, line[e])
开发者ID:anukat2015,项目名称:translate,代码行数:67,代码来源:dtd.py
示例12: getlocations
def getlocations(self):
"""Return the entity as location (identifier)."""
assert quote.rstripeol(self.entity) == self.entity
return [self.entity]
开发者ID:anukat2015,项目名称:translate,代码行数:4,代码来源:dtd.py
示例13: convertline
def convertline(self, line):
line = unicode(line, 'utf-8')
returnline = ""
# handle multiline msgid if we're in one
if self.inmultilinemsgid:
# see if there's more
endpos = line.rfind("%s%s" % (self.quotechar, self.enddel))
# if there was no '; or the quote is escaped, we have to continue
if endpos >= 0 and line[endpos-1] != '\\':
self.inmultilinemsgid = False
# if we're echoing...
if self.inecho:
returnline = line
# otherwise, this could be a comment
elif line.strip()[:2] == '//' or line.strip()[:2] == '/*':
returnline = quote.rstripeol(line) + eol
elif line.find('array(') != -1:
self.inarray = True
self.prename = line[:line.find('=')].strip() + "->"
self.equaldel = "=>"
self.enddel = ","
returnline = quote.rstripeol(line) + eol
elif self.inarray and line.find(');') != -1:
self.inarray = False
self.equaldel = "="
self.enddel = ";"
self.prename = ""
returnline = quote.rstripeol(line) + eol
else:
line = quote.rstripeol(line)
equalspos = line.find(self.equaldel)
hashpos = line.find("#")
# if no equals, just repeat it
if equalspos == -1:
returnline = quote.rstripeol(line) + eol
elif 0 <= hashpos < equalspos:
# Assume that this is a '#' comment line
returnline = quote.rstripeol(line) + eol
# otherwise, this is a definition
else:
# now deal with the current string...
key = line[:equalspos].rstrip()
lookupkey = self.prename + key.lstrip()
# Calculate space around the equal sign
prespace = line[len(line[:equalspos].rstrip()):equalspos]
postspacestart = len(line[equalspos+len(self.equaldel):])
postspaceend = len(line[equalspos+len(self.equaldel):].lstrip())
postspace = line[equalspos+len(self.equaldel):equalspos+(postspacestart-postspaceend)+len(self.equaldel)]
self.quotechar = line[equalspos+(postspacestart-postspaceend)+len(self.equaldel)]
inlinecomment_pos = line.rfind("%s%s" % (self.quotechar,
self.enddel))
if inlinecomment_pos > -1:
inlinecomment = line[inlinecomment_pos+2:]
else:
inlinecomment = ""
if lookupkey in self.inputstore.locationindex:
unit = self.inputstore.locationindex[lookupkey]
if (unit.isfuzzy() and not self.includefuzzy) or len(unit.target) == 0:
value = unit.source
else:
value = unit.target
value = php.phpencode(value, self.quotechar)
self.inecho = False
if isinstance(value, str):
value = value.decode('utf8')
returnline = "%(key)s%(pre)s%(del)s%(post)s%(quote)s%(value)s%(quote)s%(enddel)s%(comment)s%(eol)s" % {
"key": key,
"pre": prespace, "del": self.equaldel,
"post": postspace,
"quote": self.quotechar, "value": value,
"enddel": self.enddel,
"comment": inlinecomment, "eol": eol,
}
else:
self.inecho = True
returnline = line + eol
# no string termination means carry string on to next line
endpos = line.rfind("%s%s" % (self.quotechar, self.enddel))
# if there was no '; or the quote is escaped, we have to
# continue
if endpos == -1 or line[endpos-1] == '\\':
self.inmultilinemsgid = True
if isinstance(returnline, unicode):
returnline = returnline.encode('utf-8')
return returnline
开发者ID:AshishNamdev,项目名称:verbatim,代码行数:85,代码来源:po2php.py
示例14: parse
def parse(self, propsrc):
"""Read the source of a properties file in and include them as units.
"""
text, encoding = self.detect_encoding(
propsrc, default_encodings=[self.personality.default_encoding,
'utf-8', 'utf-16'])
if not text and propsrc:
raise IOError("Cannot detect encoding for %s." % (self.filename or
"given string"))
self.encoding = encoding
propsrc = text
newunit = propunit("", self.personality.name)
inmultilinevalue = False
inmultilinecomment = False
for line in propsrc.split(u"\n"):
# handle multiline value if we're in one
line = quote.rstripeol(line)
if inmultilinevalue:
newunit.value += line.lstrip()
# see if there's more
inmultilinevalue = self.personality.is_line_continuation(
newunit.value)
# if we're still waiting for more...
if inmultilinevalue:
newunit.value = self.personality.strip_line_continuation(
newunit.value)
if not inmultilinevalue:
# we're finished, add it to the list...
newunit.value = self.personality.value_strip(newunit.value)
self.addunit(newunit)
newunit = propunit("", self.personality.name)
# otherwise, this could be a comment
# FIXME handle // inline comments
elif (inmultilinecomment or is_comment_one_line(line) or
is_comment_start(line) or is_comment_end(line)):
# add a comment
if line not in self.personality.drop_comments:
newunit.comments.append(line)
if is_comment_start(line):
inmultilinecomment = True
elif is_comment_end(line):
inmultilinecomment = False
elif not line.strip():
# this is a blank line...
if str(newunit).strip():
self.addunit(newunit)
newunit = propunit("", self.personality.name)
else:
newunit.delimiter, delimiter_pos = self.personality.find_delimiter(line)
if delimiter_pos == -1:
newunit.name = self.personality.key_strip(line)
newunit.value = u""
newunit.delimiter = u""
self.addunit(newunit)
newunit = propunit("", self.personality.name)
else:
newunit.name = self.personality.key_strip(line[:delimiter_pos])
if self.personality.is_line_continuation(
line[delimiter_pos+1:].lstrip()):
inmultilinevalue = True
newunit.value = line[delimiter_pos+1:].lstrip()[:-1]
newunit.value = self.personality.strip_line_continuation(
line[delimiter_pos+1:].lstrip())
else:
newunit.value = self.personality.value_strip(line[delimiter_pos+1:])
self.addunit(newunit)
newunit = propunit("", self.personality.name)
# see if there is a leftover one...
if inmultilinevalue or len(newunit.comments) > 0:
self.addunit(newunit)
开发者ID:translate,项目名称:translate,代码行数:72,代码来源:properties.py
注:本文中的translate.misc.quote.rstripeol函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论