本文整理汇总了Python中mysite.base.unicode_sanity.utf8函数的典型用法代码示例。如果您正苦于以下问题:Python utf8函数的具体用法?Python utf8怎么用?Python utf8使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了utf8函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_do_mission_incorrectly_revdiff
def test_do_mission_incorrectly_revdiff(self):
orig_response = self.client.get(reverse(views.diffrecursive_get_original_tarball))
tfile = tarfile.open(fileobj=StringIO(orig_response.content), mode="r:gz")
diff = StringIO()
for fileinfo in tfile:
if not fileinfo.isfile():
continue
oldlines = tfile.extractfile(fileinfo).readlines()
newlines = []
for line in oldlines:
for old, new in view_helpers.DiffRecursiveMission.SUBSTITUTIONS:
line = line.replace(old, new)
newlines.append(line)
# We're very similar to test_do_mission-correctly, but here we
# switch newlines and oldlines, to create a reverse patch
diff.writelines(difflib.unified_diff(newlines, oldlines, "orig-" + fileinfo.name, fileinfo.name))
diff.seek(0)
diff.name = "foo.patch"
# Submit, and see if we get the same error message we expect.
error = self.client.post(reverse(views.diffrecursive_submit), {"diff": diff})
self.assert_(
(
"You submitted a patch that would revert the correct changes "
"back to the originals. You may have mixed the parameters for "
"diff, or performed a reverse patch." in utf8(error)
)
)
paulproteus = Person.objects.get(user__username="paulproteus")
self.assertEqual(
len(StepCompletion.objects.filter(step__name="diffpatch_diffrecursive", person=paulproteus)), 0
)
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:33,代码来源:tests.py
示例2: test_copy_paste_white_space_error
def test_copy_paste_white_space_error(self):
"""
A diff that is corrupted by the removal of white space while copying from terminal (mostly in the case of windows)
"""
try:
view_helpers.DiffSingleFileMission.validate_patch(self.make_copy_paste_error_patch())
except view_helpers.IncorrectPatch, e:
self.assert_('copy and paste from the terminal' in utf8(e))
开发者ID:florapdx,项目名称:oh-mainline,代码行数:8,代码来源:tests.py
示例3: test_backwards_diff
def test_backwards_diff(self):
"""
A backwards diff generates a special IncorrectPatch exception.
"""
try:
view_helpers.DiffSingleFileMission.validate_patch(self.make_swapped_patch())
except view_helpers.IncorrectPatch, e:
self.assert_("order of files passed to diff was flipped" in utf8(e))
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:8,代码来源:tests.py
示例4: test_diff_missing_headers
def test_diff_missing_headers(self):
"""
If a diff submission lacks headers, raise a special IncorrectPatch
exception with a hint that the headers should be included.
"""
try:
view_helpers.DiffSingleFileMission.validate_patch("I lack headers.")
except view_helpers.IncorrectPatch, e:
self.assert_("Make sure you are including the diff headers" in utf8(e))
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:9,代码来源:tests.py
示例5: test_remove_trailing_whitespace
def test_remove_trailing_whitespace(self):
"""
A diff that is corrupted by the removal of line-end whitespace
generates a special IncorrectPatch exception.
"""
try:
view_helpers.DiffSingleFileMission.validate_patch(self.make_patch_without_trailing_whitespace())
except view_helpers.IncorrectPatch, e:
self.assert_("removed the space" in utf8(e))
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:9,代码来源:tests.py
示例6: diffrecursive_submit
def diffrecursive_submit(request):
# Initialize data array and some default values.
data = {}
data['diffrecursive_form'] = forms.DiffRecursiveUploadForm()
data['diffrecursive_success'] = False
data['diffrecursive_error_message'] = ''
if request.method == 'POST':
form = forms.DiffRecursiveUploadForm(request.POST, request.FILES)
if form.is_valid():
try:
view_helpers.DiffRecursiveMission.validate_patch(form.cleaned_data['diff'].read())
set_mission_completed(request.user.get_profile(), 'diffpatch_diffrecursive')
data['diffrecursive_success'] = True
except view_helpers.IncorrectPatch, e:
data['diffrecursive_error_message'] = utf8(e)
else:
errors = list(form['diff'].errors)
if errors:
data['diffrecursive_error_message'] = (
data.get('diffrecursive_error_message', '') +
utf8(' '.join(errors)))
data['diffrecursive_form'] = form
开发者ID:CourtneyThurston,项目名称:oh-mainline,代码行数:22,代码来源:views.py
示例7: handle
def handle(self, *args, **options):
# This management command is called from the mission svn repositories
# as the pre-commit hook. It receives the repository path and transaction
# ID as arguments, and it receives a description of applicable lock
# tokens on stdin. Its environment and current directory are undefined.
if len(args) != 2:
raise CommandError, 'Exactly two arguments are expected.'
repo_path, txn_id = args
try:
view_helpers.SvnCommitMission.pre_commit_hook(repo_path, txn_id)
except view_helpers.IncorrectPatch, e:
sys.stderr.write('\n ' + utf8(e) + '\n\n')
raise CommandError, 'The commit failed to validate.'
开发者ID:CourtneyThurston,项目名称:oh-mainline,代码行数:14,代码来源:svn_precommit.py
示例8: upload
def upload(request):
# Initialize data array and some default values.
data = {}
data['create_form'] = forms.UploadForm()
data['create_success'] = False
data['what_was_wrong_with_the_tarball'] = ''
if request.method == 'POST':
form = forms.UploadForm(request.POST, request.FILES)
if form.is_valid():
try:
view_helpers.TarMission.check_tarfile(form.cleaned_data['tarfile'].read())
data['create_success'] = True
view_helpers.set_mission_completed(request.user.get_profile(), 'tar')
except view_helpers.IncorrectTarFile, e:
data['what_was_wrong_with_the_tarball'] = utf8(e)
data['create_form'] = form
开发者ID:CourtneyThurston,项目名称:oh-mainline,代码行数:16,代码来源:views.py
示例9: diffsingle_submit
def diffsingle_submit(request):
# Initialize data array and some default values.
data = {}
data['diffsingle_form'] = forms.DiffSingleUploadForm()
data['diffsingle_success'] = False
data['diffsingle_error_message'] = ''
if request.method == 'POST':
form = forms.DiffSingleUploadForm(request.POST)
if form.is_valid():
try:
view_helpers.DiffSingleFileMission.validate_patch(form.cleaned_data['diff'])
set_mission_completed(request.user.get_profile(), 'diffpatch_diffsingle')
data['diffsingle_success'] = True
except view_helpers.IncorrectPatch, e:
data['diffsingle_error_message'] = utf8(e)
data['diffsingle_form'] = form
开发者ID:CourtneyThurston,项目名称:oh-mainline,代码行数:16,代码来源:views.py
示例10: pip_list_submit
def pip_list_submit(request):
# Initialize data array and some default values.
data = {}
data['piplist_form'] = forms.PipListOutputForm()
data['piplist_success'] = False
data['piplist_error_message'] = ''
if request.method == 'POST':
form = forms.PipListOutputForm(request.POST)
if form.is_valid():
try:
view_helpers.validate_pip_list_output(
form.cleaned_data['piplist_output'])
set_mission_completed(
request.user.get_profile(), 'pipvirtualenv_piplist')
data['piplist_success'] = True
except view_helpers.IncorrectPipOutput, e:
data['piplist_error_message'] = utf8(e)
data['piplist_form'] = form
开发者ID:1234-,项目名称:oh-mainline,代码行数:18,代码来源:views.py
示例11: test_do_mission_incorrectly_leading_dot_slash_error_message
def test_do_mission_incorrectly_leading_dot_slash_error_message(self):
file_path = get_mission_test_data_path("diffpatch")
for i in range(1, 4):
filename = os.path.join(file_path, "leading_dot_slash_diff_" + str(i) + ".txt")
with open(filename) as f:
leading_dot_slash_diff = f.read()
try:
view_helpers.DiffRecursiveMission.validate_patch(leading_dot_slash_diff)
except view_helpers.IncorrectPatch, e:
self.assertEqual(
(
"The diff you submitted will not apply properly because "
'it has filename(s) starting with "./". Make sure that '
"when you run the diff command, you do not add "
'unnecessary "./" path prefixes. This is important '
"because it affects the arguments needed to run the "
"patch command for whoever applies the patch."
),
utf8(e),
)
else:
self.fail("no exception raised")
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:22,代码来源:tests.py
示例12: test_submit_nothing_causes_an_error
def test_submit_nothing_causes_an_error(self):
submit_response = self.client.post(reverse(views.diffrecursive_submit))
self.assertEqual(submit_response.status_code, 200)
self.assert_('No file was uploaded' in
utf8(submit_response))
开发者ID:JoseDiaz27,项目名称:oh-mainline,代码行数:5,代码来源:tests.py
示例13: test_produces_wrong_file
def test_produces_wrong_file(self):
try:
view_helpers.DiffSingleFileMission.validate_patch(
self.make_wrong_dest_patch())
except view_helpers.IncorrectPatch, e:
self.assert_('does not have the correct contents' in utf8(e))
开发者ID:JoseDiaz27,项目名称:oh-mainline,代码行数:6,代码来源:tests.py
示例14: test_not_single_file
def test_not_single_file(self):
try:
view_helpers.DiffSingleFileMission.validate_patch(
self.make_good_patch() * 2)
except view_helpers.IncorrectPatch, e:
self.assert_('affects more than one file' in utf8(e))
开发者ID:JoseDiaz27,项目名称:oh-mainline,代码行数:6,代码来源:tests.py
示例15: test_not_single_file
def test_not_single_file(self):
try:
controllers.DiffSingleFileMission.validate_patch(self.make_good_patch() * 2)
except controllers.IncorrectPatch, e:
self.assert_("affects more than one file" in utf8(e))
开发者ID:pselle,项目名称:oh-mainline,代码行数:5,代码来源:tests.py
注:本文中的mysite.base.unicode_sanity.utf8函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论