How to use the formencode.validators.URL function in FormEncode

To help you get started, we’ve selected a few FormEncode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Pylons / pylons / tests / test_units / test_decorator_validate.py View on Github external
# -*- coding: utf-8 -*-
import formencode
from formencode.htmlfill import html_quote
from paste.fixture import TestApp
from paste.registry import RegistryManager

from __init__ import TestWSGIController


def custom_error_formatter(error):
    return '<p><span class="pylons-error">%s</span></p>\n' % html_quote(error)

class NetworkForm(formencode.Schema):
    allow_extra_fields = True
    filter_extra_fields = True
    new_network = formencode.validators.URL(not_empty=True)

class HelloForm(formencode.Schema):
    hello = formencode.ForEach(formencode.validators.Int())

def make_validating_controller():
    from pylons.decorators import validate
    from pylons.controllers import WSGIController

    class ValidatingController(WSGIController):
        def new_network(self):
            return """

  <form method="POST" action="/dhcp/new_form">
    <table>
      <tbody><tr>
        <th>Network</th></tr></tbody></table></form>
github obeattie / pylons / tests / test_units / test_decorator_validate.py View on Github external
from pylons.decorators import validate

from pylons.controllers import WSGIController

from __init__ import ControllerWrap, SetupCacheGlobal, TestWSGIController

import formencode
from formencode.htmlfill import html_quote

def custom_error_formatter(error):
    return '<p><span class="pylons-error">%s</span></p>\n' % html_quote(error)

class NetworkForm(formencode.Schema):
    allow_extra_fields = True
    filter_extra_fields = True
    new_network = formencode.validators.URL(not_empty=True)

class HelloForm(formencode.Schema):
    hello = formencode.ForEach(formencode.validators.Int())

class ValidatingController(WSGIController):
    def new_network(self):
        return """

  <form method="POST" action="/dhcp/new_form">
    <table>
      <tbody><tr>
        <th>Network</th>
        <td>
          <input value="" type="text" name="new_network" id="new_network">
        </td>
      </tr></tbody></table></form>
github the-virtual-brain / tvb-framework / tvb / interfaces / web / controllers / settings_controller.py View on Github external
return str(value).encode('ascii')
        except UnicodeError:
            raise formencode.Invalid('Invalid ascii string %s' % value, '', None)


class SettingsForm(formencode.Schema):
    """
    Validate Settings Page inputs.
    """

    ADMINISTRATOR_NAME = formencode.All(validators.UnicodeString(not_empty=True), validators.PlainText())
    ADMINISTRATOR_PASSWORD = validators.UnicodeString(not_empty=True)
    ADMINISTRATOR_EMAIL = validators.Email(not_empty=True)

    WEB_SERVER_PORT = PortValidator()
    URL_WEB = validators.URL(not_empty=True, require_tld=False)

    SELECTED_DB = validators.UnicodeString(not_empty=True)
    URL_VALUE = validators.UnicodeString(not_empty=True)
    DEPLOY_CLUSTER = validators.Bool()
    CLUSTER_SCHEDULER = validators.UnicodeString(not_empty=True)

    TVB_STORAGE = validators.UnicodeString(not_empty=True)
    USR_DISK_SPACE = DiskSpaceValidator(not_empty=True)
    MATLAB_EXECUTABLE = MatlabValidator()
    MAXIMUM_NR_OF_THREADS = ThreadNrValidator()
    MAXIMUM_NR_OF_VERTICES_ON_SURFACE = SurfaceVerticesNrValidator()
    MAXIMUM_NR_OF_OPS_IN_RANGE = validators.Int(min=5, max=5000, not_empty=True)
github renxing / quora-python / forms.py View on Github external
class LoginForm(BaseForm):
    login = validators.String(not_empty=True,strip=True)
    password = validators.String(not_empty=True)

class RegisterForm(BaseForm):
    login = validators.String(not_empty=True,strip=True,min=4,max=20)
    email = validators.Email(not_empty=True,strip=True)
    name = validators.String(not_empty=True,strip=True)
    password = validators.String(not_empty=True)
    password_confirm = validators.String(not_empty=True)
    chained_validators = [validators.FieldsMatch('password', 'password_confirm')]

class SettingsForm(BaseForm):
    email = validators.Email(not_empty=True,strip=True)
    name = validators.String(not_empty=True,strip=True)
    blog = validators.URL(not_empty=True,strip=True)
    bio = validators.String(not_empty=True,max=300)
    
class AskForm(BaseForm):
    title = validators.String(not_empty=True,min=5,max=255,strip=True)
    body = validators.String()
    tags = validators.String(strip=True)

class AnswerForm(BaseForm):
    answer_body = validators.String(not_empty=True,min=2,strip=True)
github apache / allura / Allura / allura / webhooks.py View on Github external
if isinstance(value, M.Webhook):
            wh = value
        elif isinstance(value, ObjectId):
            wh = M.Webhook.query.get(_id=value)
        else:
            try:
                wh = M.Webhook.query.get(_id=ObjectId(value))
            except:
                pass
        if wh and wh.type == self.sender.type and wh.app_config_id == self.app.config._id:
            return wh
        raise Invalid(u'Invalid webhook', value, state)


class WebhookCreateForm(schema.Schema):
    url = fev.URL(not_empty=True)
    secret = fev.UnicodeString()


class WebhookEditForm(WebhookCreateForm):
    def __init__(self, sender, app):
        super(WebhookEditForm, self).__init__()
        self.add_field('webhook', WebhookValidator(
            sender=sender, app=app, not_empty=True))


class WebhookControllerMeta(type):
    def __call__(cls, sender, app, *args, **kw):
        """Decorate post handlers with a validator that references
        the appropriate webhook sender for this controller.
        """
        if hasattr(cls, 'create'):
github mediadrop / mediadrop / mediadrop / forms / admin / podcasts.py View on Github external
fields = [
        TextField('slug', label_text=N_('Permalink'), validator=NotEmpty, maxlength=50),
        TextField('title', label_text=N_('Title'), validator=TextField.validator(not_empty=True), maxlength=50),
        TextField('subtitle', label_text=N_('Subtitle'), maxlength=255),
        TextField('author_name', label_text=N_('Author Name'), validator=TextField.validator(not_empty=True), maxlength=50),
        TextField('author_email', label_text=N_('Author Email'), validator=email_validator(not_empty=True), maxlength=50),
        XHTMLTextArea('description', label_text=N_('Description'), attrs=dict(rows=5, cols=25)),
        ListFieldSet('details', suppress_label=True, legend=N_('Podcast Details:'), css_classes=['details_fieldset'], children=[
            SingleSelectField('explicit', label_text=N_('Explicit?'), options=explicit_options),
            SingleSelectField('category', label_text=N_('Category'), options=category_options),
            TextField('copyright', label_text=N_('Copyright'), maxlength=50),
        ]),
        ListFieldSet('feed', suppress_label=True, legend=N_('Advanced Options:'), css_classes=['details_fieldset'], template='/admin/podcasts/feed_fieldset.html', children=[
            TextField('feed_url', maxlength=50, label_text=N_('Your Feed URL'), attrs={'readonly': True}),
            TextField('itunes_url', validator=URL, label_text=N_('iTunes URL'), maxlength=80),
            TextField('feedburner_url', validator=URL, label_text=N_('Feedburner URL'), maxlength=80),
        ]),
        SubmitButton('save', default=N_('Save'), named_button=True, css_classes=['btn', 'blue', 'f-rgt']),
        SubmitButton('delete', default=N_('Delete'), named_button=True, css_classes=['btn']),
    ]
github apache / allura / Allura / allura / ext / admin / widgets.py View on Github external
label='Features',
            show_msg=False,
            show_button=False,
            append_to='bottom',
            extra_field_on_focus_name='feature',
            field=FeaturesField())
        icon = ew.FileField(label='Icon', attrs={'accept': 'image/*'},
                            validator=V.IconValidator())
        external_homepage = ew.InputField(field_type="text", label='Homepage',
                                          validator=fev.URL(add_http=True))
        video_url = ew.InputField(field_type="text", label="Video (YouTube)",
                                  validator=V.YouTubeConverter())
        support_page = ew.InputField(field_type="text", label='Support Page')
        support_page_url = ew.InputField(
            field_type="text", label='Support Page URL',
            validator=fev.URL(add_http=True, if_empty=''))
        removal = ew.InputField(field_type="text", label='Removal')
        moved_to_url = ew.InputField(
            field_type="text", label='Moved Project to URL',
            validator=fev.URL(add_http=True, if_empty=''))
        delete = ew.InputField(field_type="hidden", label='Delete')
        delete_icon = ew.InputField(field_type="hidden", label='Delete Icon')
        undelete = ew.InputField(field_type="hidden", label='Undelete')
        tracking_id = ew.InputField(
            field_type="text", label="Google Analytics ID",
            attrs=(dict(placeholder='UA-123456-0', pattern='UA-[0-9]+-[0-9]+')))
        twitter_handle = ew.InputField(
            field_type="text", label='Twitter Handle')
        facebook_page = ew.InputField(field_type="text", label='Facebook page',
                                      validator=fev.URL(add_http=True))
github apache / allura / Allura / allura / lib / validators.py View on Github external
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.

import json
import re
from bson import ObjectId
import formencode as fe
from formencode import validators as fev
from tg import tmpl_context as c
from . import helpers as h
from datetime import datetime


class URL(fev.URL):
    # allows use of IP address instead of domain name
    require_tld = False

    url_re = re.compile(r'''
        ^(http|https)://
        (?:[%:\w]*@)?                              # authenticator
        (?:                                        # ip or domain
        (?P(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|
        (?P[a-z0-9][a-z0-9\-]{,62}\.)*     # subdomain
        (?P[a-z]{2,63}|xn--[a-z0-9\-]{2,59})  # top level domain
        )
        (?::[0-9]{1,5})?                           # port
        # files/delims/etc
        (?P
github felinx / poweredsites / poweredsites / forms / base.py View on Github external
html = self._handler.render_string(template_name, **kwargs)
        if not self._result:
            html = htmlfill.render(
                                   html,
                                   defaults=self._values,
                                   errors=self._form_errors,
                                   encoding="utf8",
            )
        self._handler.finish(html)

    # post process hook
    def __after__(self):
        pass


class URL(validators.URL):
    url_re = re.compile(r'''
        ^(http|https)://
        (?:[%:\w]*@)?                           # authenticator
        (?P[a-z0-9][a-z0-9\-]{0,62}\.)* # (sub)domain - alpha followed by 62max chars (63 total)
        (?P[a-z]{2,})                      # TLD
        (?::[0-9]+)?                            # port

        # files/delims/etc
        (?P