You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/08/27 20:35:32 UTC
[allura] 07/16: [#8375] more formencode bytes fixes
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch db/8375
in repository https://gitbox.apache.org/repos/asf/allura.git
commit e70fbe52238a4ac58c0fe5315331dcd294edaf09
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Tue Aug 25 12:13:15 2020 -0400
[#8375] more formencode bytes fixes
---
Allura/allura/lib/validators.py | 8 +++++++-
Allura/allura/lib/widgets/discuss.py | 7 ++++++-
ForgeImporters/forgeimporters/base.py | 12 ++++++++++++
ForgeTracker/forgetracker/widgets/ticket_form.py | 2 +-
4 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/Allura/allura/lib/validators.py b/Allura/allura/lib/validators.py
index 9dd0c91..28c224b 100644
--- a/Allura/allura/lib/validators.py
+++ b/Allura/allura/lib/validators.py
@@ -84,6 +84,12 @@ class UnicodeString(fev.UnicodeString):
String = UnicodeString if str is str else fev.ByteString
+class FieldStorageUploadConverter(fev.FieldStorageUploadConverter):
+ # https://github.com/formencode/formencode/issues/101 local fix
+ def is_empty(self, value):
+ return value == b'' or super(FieldStorageUploadConverter, self).is_empty(value)
+
+
class Ming(fev.FancyValidator):
def __init__(self, cls, **kw):
@@ -290,7 +296,7 @@ class JsonConverter(fev.FancyValidator):
return obj
-class JsonFile(fev.FieldStorageUploadConverter):
+class JsonFile(FieldStorageUploadConverter):
"""Validates that a file is JSON and returns the deserialized Python object
diff --git a/Allura/allura/lib/widgets/discuss.py b/Allura/allura/lib/widgets/discuss.py
index 9338fbb..5abdf4b 100644
--- a/Allura/allura/lib/widgets/discuss.py
+++ b/Allura/allura/lib/widgets/discuss.py
@@ -40,6 +40,11 @@ class NullValidator(fev.FancyValidator):
def _from_python(self, value, state):
return value
+ # https://github.com/formencode/formencode/issues/101 local fix
+ def is_empty(self, value):
+ return value == b'' or super(NullValidator, self).is_empty(value)
+
+
# Discussion forms
@@ -206,7 +211,7 @@ class NewTopicPost(EditPost):
fields = super(NewTopicPost, self).fields
fields.append(ew.InputField(name='attachment', label='Attachment', field_type='file',
attrs={'multiple': 'True'},
- validator=fev.FieldStorageUploadConverter(if_missing=None)))
+ validator=v.FieldStorageUploadConverter(if_missing=None)))
return fields
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index ea87738..a37b8e3 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -73,6 +73,12 @@ class ProjectImportForm(schema.Schema):
neighborhood = fev.NotEmpty()
project_name = v.UnicodeString(not_empty=True, max=40)
+ # https://github.com/formencode/formencode/issues/101 local fix
+ def _value_is_iterator(self, value):
+ if isinstance(value, bytes):
+ return False
+ return super(ProjectImportForm, self)._value_is_iterator(value)
+
class ToolImportForm(schema.Schema):
@@ -81,6 +87,12 @@ class ToolImportForm(schema.Schema):
self.add_field('mount_point', v.MountPointValidator(tool_class))
mount_label = v.UnicodeString()
+ # https://github.com/formencode/formencode/issues/101 local fix
+ def _value_is_iterator(self, value):
+ if isinstance(value, bytes):
+ return False
+ return super(ToolImportForm, self)._value_is_iterator(value)
+
class ImportErrorHandler(object):
diff --git a/ForgeTracker/forgetracker/widgets/ticket_form.py b/ForgeTracker/forgetracker/widgets/ticket_form.py
index fa1ddd4..73eb753 100644
--- a/ForgeTracker/forgetracker/widgets/ticket_form.py
+++ b/ForgeTracker/forgetracker/widgets/ticket_form.py
@@ -124,7 +124,7 @@ class GenericTicketForm(ew.SimpleForm):
validator=fev.StringBool(),
attrs={'class': 'unlabeled'}),
ew.InputField(name='attachment', label='Attachment', field_type='file', attrs={
- 'multiple': 'True'}, validator=fev.FieldStorageUploadConverter(if_missing=None)),
+ 'multiple': 'True'}, validator=v.FieldStorageUploadConverter(if_missing=None)),
ffw.MarkdownEdit(name='comment', label='Comment',
attrs={'style': 'min-height:7em; width:97%'}),
ew.SubmitButton(label=self.submit_text, name='submit',