Ejemplo n.º 1
0
 def __init__(self, defaults, errors=None, use_all_keys=False,
              error_formatters=None, error_class='error',
              add_attributes=None, listener=None,
              auto_error_formatter=None,
              text_as_default=False, encoding=None, prefix_error=True):
     RewritingParser.__init__(self)
     self.source = None
     self.lines = None
     self.source_pos = None
     self.defaults = defaults
     self.in_textarea = None
     self.last_textarea_name = None
     self.in_select = None
     self.skip_next = False        
     self.errors = errors or {}
     if isinstance(self.errors, (str, unicode)):
         self.errors = {None: self.errors}
     self.in_error = None
     self.skip_error = False
     self.use_all_keys = use_all_keys
     self.used_keys = {}
     self.used_errors = {}
     if error_formatters is None:
         self.error_formatters = default_formatter_dict
     else:
         self.error_formatters = error_formatters
     self.error_class = error_class
     self.add_attributes = add_attributes or {}
     self.listener = listener
     self.auto_error_formatter = auto_error_formatter
     self.text_as_default = text_as_default
     self.encoding = encoding
     self.prefix_error = prefix_error
Ejemplo n.º 2
0
 def __init__(self, defaults, errors=None, use_all_keys=False,
              error_formatters=None, error_class='error',
              add_attributes=None, listener=None,
              auto_error_formatter=None,
              text_as_default=False, encoding=None, prefix_error=True):
     RewritingParser.__init__(self)
     self.source = None
     self.lines = None
     self.source_pos = None
     self.defaults = defaults
     self.in_textarea = None
     self.last_textarea_name = None
     self.in_select = None
     self.skip_next = False        
     self.errors = errors or {}
     if isinstance(self.errors, (str, unicode)):
         self.errors = {None: self.errors}
     self.in_error = None
     self.skip_error = False
     self.use_all_keys = use_all_keys
     self.used_keys = {}
     self.used_errors = {}
     if error_formatters is None:
         self.error_formatters = default_formatter_dict
     else:
         self.error_formatters = error_formatters
     self.error_class = error_class
     self.add_attributes = add_attributes or {}
     self.listener = listener
     self.auto_error_formatter = auto_error_formatter
     self.text_as_default = text_as_default
     self.encoding = encoding
     self.prefix_error = prefix_error
Ejemplo n.º 3
0
 def close(self):
     self.handle_misc(None)
     RewritingParser.close(self)
     unused_errors = self.errors.copy()
     for key in self.used_errors.keys():
         if key in unused_errors:
             del unused_errors[key]
     if self.auto_error_formatter:
         for key, value in unused_errors.items():
             error_message = self.auto_error_formatter(value)
             error_message = '<!-- for: %s -->\n%s' % (key, error_message)
             self.insert_at_marker(key, error_message)
         unused_errors = {}
     if self.use_all_keys:
         unused = self.defaults.copy()
         for key in self.used_keys.keys():
             if key in unused:
                 del unused[key]
         assert not unused, (
             "These keys from defaults were not used in the form: %s" %
             unused.keys())
         if unused_errors:
             error_text = []
             for key in unused_errors.keys():
                 error_text.append("%s: %s" % (key, self.errors[key]))
             assert False, ("These errors were not used in the form: %s" %
                            ', '.join(error_text))
     if self.encoding is not None:
         new_content = []
         for item in self._content:
             if isinstance(item, str):
                 item = item.decode(self.encoding)
             new_content.append(item)
         self._content = new_content
     self._text = self._get_text()
Ejemplo n.º 4
0
 def close(self):
     self.handle_misc(None)
     RewritingParser.close(self)
     unused_errors = self.errors.copy()
     for key in self.used_errors.keys():
         if unused_errors.has_key(key):
             del unused_errors[key]
     if self.auto_error_formatter:
         for key, value in unused_errors.items():
             error_message = self.auto_error_formatter(value)
             error_message = "<!-- for: %s -->\n%s" % (key, error_message)
             self.insert_at_marker(key, error_message)
         unused_errors = {}
     if self.use_all_keys:
         unused = self.defaults.copy()
         for key in self.used_keys.keys():
             if unused.has_key(key):
                 del unused[key]
         assert not unused, "These keys from defaults were not used in the form: %s" % unused.keys()
         if unused_errors:
             error_text = []
             for key in unused_errors.keys():
                 error_text.append("%s: %s" % (key, self.errors[key]))
             assert False, "These errors were not used in the form: %s" % ", ".join(error_text)
     if self.encoding is not None:
         new_content = []
         for item in self._content:
             if isinstance(item, str):
                 item = item.decode(self.encoding)
             new_content.append(item)
         self._content = new_content
     self._text = self._get_text()
Ejemplo n.º 5
0
 def __init__(
     self,
     defaults,
     errors=None,
     use_all_keys=False,
     error_formatters=None,
     error_class='error',
     add_attributes=None,
     listener=None,
     auto_error_formatter=None,
     text_as_default=False,
     checkbox_checked_if_present=False,
     encoding=None,
     prefix_error=True,
     force_defaults=True,
     skip_passwords=False,
     data_formencode_form=None,
     data_formencode_ignore=None,
 ):
     RewritingParser.__init__(self)
     self.source = None
     self.lines = None
     self.source_pos = None
     self.defaults = defaults
     self.in_textarea = None
     self.skip_textarea = False
     self.last_textarea_name = None
     self.in_select = None
     self.skip_next = False
     self.errors = errors or {}
     if isinstance(self.errors, basestring):
         self.errors = {None: self.errors}
     self.in_error = None
     self.skip_error = False
     self.use_all_keys = use_all_keys
     self.used_keys = set()
     self.used_errors = set()
     if error_formatters is None:
         self.error_formatters = default_formatter_dict
     else:
         self.error_formatters = error_formatters
     self.error_class = error_class
     self.add_attributes = add_attributes or {}
     self.listener = listener
     self.auto_error_formatter = auto_error_formatter
     self.text_as_default = text_as_default
     self.checkbox_checked_if_present = checkbox_checked_if_present
     self.encoding = encoding
     self.prefix_error = prefix_error
     self.force_defaults = force_defaults
     self.skip_passwords = skip_passwords
     self.data_formencode_form = data_formencode_form
     self.data_formencode_ignore = data_formencode_ignore
Ejemplo n.º 6
0
 def __init__(
     self,
     defaults,
     errors=None,
     use_all_keys=False,
     error_formatters=None,
     error_class="error",
     add_attributes=None,
     listener=None,
     auto_error_formatter=None,
     text_as_default=False,
     checkbox_checked_if_present=False,
     encoding=None,
     prefix_error=True,
     force_defaults=True,
     skip_passwords=False,
     data_formencode_form=None,
     data_formencode_ignore=None,
 ):
     RewritingParser.__init__(self)
     self.source = None
     self.lines = None
     self.source_pos = None
     self.defaults = defaults
     self.in_textarea = None
     self.skip_textarea = False
     self.last_textarea_name = None
     self.in_select = None
     self.skip_next = False
     self.errors = errors or {}
     if isinstance(self.errors, six.string_types):
         self.errors = {None: self.errors}
     self.in_error = None
     self.skip_error = False
     self.use_all_keys = use_all_keys
     self.used_keys = set()
     self.used_errors = set()
     if error_formatters is None:
         self.error_formatters = default_formatter_dict
     else:
         self.error_formatters = error_formatters
     self.error_class = error_class
     self.add_attributes = add_attributes or {}
     self.listener = listener
     self.auto_error_formatter = auto_error_formatter
     self.text_as_default = text_as_default
     self.checkbox_checked_if_present = checkbox_checked_if_present
     self.encoding = encoding
     self.prefix_error = prefix_error
     self.force_defaults = force_defaults
     self.skip_passwords = skip_passwords
     self.data_formencode_form = data_formencode_form
     self.data_formencode_ignore = data_formencode_ignore
Ejemplo n.º 7
0
 def close(self):
     self.handle_misc(None)
     RewritingParser.close(self)
     unused_errors = self.errors.copy()
     for key in self.used_errors:
         if key in unused_errors:
             del unused_errors[key]
     if self.auto_error_formatter:
         for key, value in unused_errors.items():
             error_message = self.auto_error_formatter(value)
             error_message = '<!-- for: %s -->\n%s' % (key, error_message)
             self.insert_at_marker(
                 key, error_message)
         unused_errors = {}
     if self.use_all_keys:
         unused = self.defaults.copy()
         for key in self.used_keys:
             if key in unused:
                 del unused[key]
         assert not unused, (
             "These keys from defaults were not used in the form: %s"
             % ', '.join(unused))
         if unused_errors:
             error_text = ['%s: %s' % (key, self.errors[key])
                 for key in sorted(unused_errors)]
             assert False, (
                 "These errors were not used in the form: %s"
                 % ', '.join(error_text))
     if self.encoding is not None:
         new_content = []
         for item in self._content:
             if (str is not str  # Python 2
                     and isinstance(item, str)):
                 item = item.decode(self.encoding)
             new_content.append(item)
         self._content = new_content
     self._text = self._get_text()
Ejemplo n.º 8
0
 def close(self):
     self.handle_misc(None)
     RewritingParser.close(self)
     self._text = self._get_text()
Ejemplo n.º 9
0
 def __init__(self, rename_func):
     RewritingParser.__init__(self)
     self.rename_func = rename_func
 def close(self):
     self.handle_misc(None)
     RewritingParser.close(self)
     self._text = self._get_text()
 def __init__(self, rename_func):
     RewritingParser.__init__(self)
     self.rename_func = rename_func