本文整理汇总了Python中railgun.common.lazy_i18n.lazy_gettext函数的典型用法代码示例。如果您正苦于以下问题:Python lazy_gettext函数的具体用法?Python lazy_gettext怎么用?Python lazy_gettext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了lazy_gettext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: do_run
def do_run(self):
try:
self.detail = []
covered = set()
for obj in CsvSchema.LoadCSV(self.schema, self.csvdata):
# each record should be sent to all check classes, to see
# what classes it covered
for i, c in enumerate(self.check_classes):
if c(obj):
covered.add(i)
# total up score by len(covered) / total_classes
self.score = 100.0 * len(covered) / len(self.check_classes)
self.brief = lazy_gettext(
'%(rate).2f%% rules (%(cover)s out of %(total)s) covered',
cover=len(covered), total=len(self.check_classes),
rate=self.score
)
# build more detailed report
for i, c in enumerate(self.check_classes):
if i in covered:
self.detail.append(lazy_gettext(
'COVERED: %(checker)s',
checker=self.getDescription(c)
))
else:
self.detail.append(lazy_gettext(
'NOT COVERED: %(checker)s',
checker=self.getDescription(c)
))
except KeyError, ex:
raise ScorerFailure(
brief=lazy_gettext('CSV data does not match schema.'),
detail=[ex.args[0]]
)
开发者ID:sunxingfa,项目名称:railgun,代码行数:34,代码来源:scorer.py
示例2: compile
def compile(self):
"""Validate the user submitted url address at compile stage.
The url address will be tested with the configured regex patterns
loaded from :attr:`BaseHost.compiler_params`.
Refer to :ref:`hwnetapi` for more details about the rules.
"""
if self.config['urlrule']:
p = re.compile(self.config['urlrule'])
if not p.match(self.config['remote_addr']):
raise NetApiAddressRejected(compile_error=lazy_gettext(
'Address "%(url)s" does not match pattern "%(rule)s"',
url=self.config['remote_addr'], rule=self.config['urlrule']
))
if self.config['iprule']:
domain = urllib.splitport(
urllib.splithost(
urllib.splittype(self.config['remote_addr'])[1]
)[0]
)[0]
# get ip from domain
try:
ipaddr = socket.gethostbyname(domain)
except Exception:
logger.exception(
'Could not get ip address for domain "%s".' % domain)
ipaddr = '<invalid>'
# ip not match, skip
p = re.compile(self.config['iprule'])
if not p.match(ipaddr):
raise NetApiAddressRejected(compile_error=lazy_gettext(
'IP address "%(ip)s" does not match pattern "%(rule)s"',
ip=ipaddr, rule=self.config['iprule']
))
开发者ID:heyLinsir,项目名称:railgun,代码行数:34,代码来源:host.py
示例3: __init__
def __init__(self, score):
super(JavaScore, self).__init__(lazy_gettext("Functionality Scorer"))
self.score = score
self.brief = lazy_gettext("%(rate).2f%% rules (%(cover)s out of %(total)s) covered", cover=1, total=1, rate=100)
self.detail = [
lazy_gettext("%(rate).2f%% rules (%(cover)s out of %(total)s) covered", cover=1, total=1, rate=100)
]
开发者ID:xin-xinhanggao,项目名称:railgun,代码行数:9,代码来源:scorer.py
示例4: do_run
def do_run(self):
if type(self.filelist) == type("a"):
ph_out = self.filelist
self.detail = []
warning = 0
l = ph_out.split("\n")
for x in l:
if x[:6] == "[WARN]":
warning += 1
self.detail.append(x)
self.score = 100.0 - warning * self.errcost
if self.score < 0.0:
self.score = 0.0
total_file = 1
if warning > 0:
self.brief = lazy_gettext(
"%(trouble)d problem(s) found in %(file)d file(s)", trouble=warning, file=total_file
)
else:
self.brief = lazy_gettext("All files passed Google code style check")
if self.logs != None:
self.logs.saveCodeStyle(
str(self.score) + "\n" + str(self.brief) + "\n" + GetTextStringList(self.detail)
)
return
guide = pep8.StyleGuide()
guide.options.show_source = True
guide.options.report = Pep8DetailReport(guide.options)
result = guide.check_files(self.filelist)
# Each error consumes 1 point.
errcount = result.count_errors()
self.score = 100.0 - errcount * self.errcost
if self.score < 0.0:
self.score = 0.0
# format the brief report
total_file = len(self.filelist)
if errcount > 0:
self.brief = lazy_gettext(
"%(trouble)d problem(s) found in %(file)d file(s)", trouble=errcount, file=total_file
)
else:
self.brief = lazy_gettext("All files passed PEP8 code style check")
# format detailed reports
self.detail = result.build_report()
if self.logs != None:
self.logs.saveCodeStyle(str(self.score) + "\n" + str(self.brief) + "\n" + GetTextStringList(self.detail))
开发者ID:xin-xinhanggao,项目名称:railgun,代码行数:51,代码来源:scorer.py
示例5: addSkip
def addSkip(self, test, reason):
super(UnitTestScorerDetailResult, self).addSkip(test, reason)
self.details.append(lazy_gettext(
'SKIP: %(test)s: %(reason)s.',
test=self.getDescription(test),
reason=reason
))
开发者ID:heyLinsir,项目名称:railgun,代码行数:7,代码来源:utility.py
示例6: addExpectedFailure
def addExpectedFailure(self, test, err):
super(UnitTestScorerDetailResult, self).addExpectedFailure(test, err)
self.details.append(lazy_gettext(
'EXPECTED FAIL: %(test)s.\n%(error)s',
test=self.getDescription(test),
error=self._exc_info_to_string(err, test)
))
开发者ID:heyLinsir,项目名称:railgun,代码行数:7,代码来源:utility.py
示例7: __init__
def __init__(self, schema, csvdata, check_classes=None):
super(InputClassScorer, self).__init__(
name=lazy_gettext('InputClass Scorer'),
schema=schema,
csvdata=csvdata,
check_classes=check_classes,
)
开发者ID:sunxingfa,项目名称:railgun,代码行数:7,代码来源:scorer.py
示例8: addError
def addError(self, test, err):
super(UnitTestScorerDetailResult, self).addError(test, err)
self.details.append(lazy_gettext(
'ERROR: %(test)s.\n%(error)s',
test=self.getDescription(test),
error=self._exc_info_to_string(err, test)
))
开发者ID:heyLinsir,项目名称:railgun,代码行数:7,代码来源:utility.py
示例9: parseString
def parseString(self, value):
try:
return self.fromString(value)
except Exception:
raise ValueError(lazy_gettext(
'Cannot convert "%(value)s" to %(type)s.',
value=value, type=self.__class__.__name__
))
开发者ID:heyLinsir,项目名称:railgun,代码行数:8,代码来源:csvdata.py
示例10: check_require
def check_require(self, collector):
"""Check whether this schema is marked as `REQUIRE` but the object
does not exist. All the children schema will also be notified.
"""
if self.exist_rule == SchemaExistRule.REQUIRE and not self.exist:
collector.addError(lazy_gettext(
'%(schema)s is required but the object does not exist or '
'could not be loaded.',
schema=self.get_description()
))
elif self.exist_rule == SchemaExistRule.DENY and self.exist:
collector.addError(lazy_gettext(
'%(schema)s is denied but the object exists.',
schema=self.get_description()
))
else:
collector.addSuccess()
开发者ID:heyLinsir,项目名称:railgun,代码行数:17,代码来源:objschema.py
示例11: api_handin_proclog
def api_handin_proclog(uuid):
"""Store the process outputs for a given submission.
This api view is usually requested after the reports of the corresponding
submission has been stored, so it would not change either the score or
the state of the submission.
If the submission state is still `Pending` or `Running`, indicating that
the reports have not been stored (probably the process exited abnormally
before report the score), the state will be updated to `Rejected`.
This view will compare `uuid` in POST object to the `uuid` argument.
If they are not equal, the operation will be rejected, since it is
likely to be an attack.
:route: /api/handin/proclog/<uuid>/
:payload:
.. code-block:: python
{"uuid": uuid of submission,
"exitcode": The exitcode of the process,
"stdout": The standard output of the process,
"stderr": The standard error output of the process}
:param uuid: The uuid of submission.
:type uuid: :class:`str`
:return: ``OK`` if succeeded, error messages otherwise.
"""
obj = request.payload
# check uuid, so that we can prevent replay attack
if obj['uuid'] != uuid:
return 'uuid mismatch, do not attack'
# load the handin object, and report error if not exist
handin = Handin.query.filter(Handin.uuid == uuid).first()
if not handin:
return 'requested submission not found'
# if handin.state != 'Accepted' and handin.state != 'Rejected',
# the process must have exited without report the score.
# mark such handin as "Rejected"
if handin.state != 'Accepted' and handin.state != 'Rejected':
handin.state = 'Rejected'
handin.result = lazy_gettext('Process exited before reporting score.')
handin.partials = []
try:
handin.exitcode = obj['exitcode']
handin.stdout = obj['stdout']
handin.stderr = obj['stderr']
db.session.commit()
except Exception:
app.logger.exception('Cannot log proccess of submission(%s).' % uuid)
return 'update database failed'
return 'OK'
开发者ID:heyLinsir,项目名称:railgun,代码行数:58,代码来源:api.py
示例12: LoadCSV
def LoadCSV(cls, iterable):
"""Get iterable objects from given line `iterable` object."""
rdr = csv.reader(iterable)
# parse the header line
headers = {k: i for i, k in enumerate(next(rdr))}
field_getter = {}
for k, v in cls.__dict__.iteritems():
if isinstance(v, CsvField):
field_name = v.name if v.name else k
if field_name in headers:
# set the getter to fetch Nth column of a row
# where N = headers[k]
field_getter[k] = (
lambda row, key=field_name, col=v: (
col.parseString(row[headers[key]])
)
)
elif v.has_default:
# not exist in CSV, if has default, use default value
field_getter[k] = lambda row, val=v: val.default
else:
# not exist, no default, raise KeyError
raise KeyError(lazy_gettext(
'Field "%(field)s" not found in CSV data.',
field=field_name
))
# Yield object from CSV one by one
for row in rdr:
if not row:
continue
obj = cls()
for f, g in field_getter.iteritems():
setattr(obj, f, g(row))
yield obj
开发者ID:heyLinsir,项目名称:railgun,代码行数:37,代码来源:csvdata.py
示例13: __init__
def __init__(self, **kwargs):
super(RunnerPermissionError, self).__init__(lazy_gettext(
'File permissions of the runner is wrong.'
), **kwargs)
开发者ID:heyLinsir,项目名称:railgun,代码行数:4,代码来源:errors.py
示例14: addUnexpectedSuccess
def addUnexpectedSuccess(self, test):
super(UnitTestScorerDetailResult, self).addUnexpectedSuccess(test)
self.details.append(lazy_gettext(
'UNEXPECTED SUCCESS: %(test)s.',
test=self.getDescription(test)
))
开发者ID:heyLinsir,项目名称:railgun,代码行数:6,代码来源:utility.py
示例15: addSuccess
def addSuccess(self, test):
super(UnitTestScorerDetailResult, self).addSuccess(test)
self.details.append(lazy_gettext(
'PASSED: %(test)s.',
test=self.getDescription(test)
))
开发者ID:heyLinsir,项目名称:railgun,代码行数:6,代码来源:utility.py
注:本文中的railgun.common.lazy_i18n.lazy_gettext函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论