# Path: flatland/schema/scalars.py
# class String(Scalar):
#     """A regular old Unicode string."""
# 
#     strip = True
#     """If true, strip leading and trailing whitespace during conversion."""
# 
#     def adapt(self, value):
#         """Return a Unicode representation.
# 
#         :returns: a ``unicode`` value or ``None``
# 
#         If :attr:`strip` is true, leading and trailing whitespace will be
#         removed.
# 
#         """
#         if value is None:
#             return None
#         elif self.strip:
#             return unicode(value).strip()
#         else:
#             return unicode(value)
# 
#     def serialize(self, value):
#         """Return a Unicode representation.
# 
#         :returns: a ``unicode`` value or ``u'' if *value* is ``None``
# 
#         If :attr:`strip` is true, leading and trailing whitespace will be
#         removed.
# 
#         """
#         if value is None:
#             return u''
#         elif self.strip:
#             return unicode(value).strip()
#         else:
#             return unicode(value)
# 
#     @property
#     def is_empty(self):
#         """True if the String is missing or has no value."""
#         return True if (not self.value and self.u == u'') else False


import re
from flatland import String
from flatland.validation import (
    IsEmail,
    HTTPURLValidator,
    URLCanonicalizer,
    URLValidator,
    )
from flatland.validation.network import _url_parts
from tests._util import eq_
    v = URLValidator()
    el = scalar('http://me:you@there/path#fragment')
    assert v.validate(el, None)
    assert not el.errors


def test_url_validator_schemes():
    v = URLValidator(allowed_schemes=(), blocked_scheme='X')
    el = scalar('http://me:you@there/path#fragment')
    assert not v.validate(el, None)
    eq_(el.errors, ['X'])

    v = URLValidator(allowed_schemes=('https',), blocked_scheme='X')
    el = scalar('http://me:you@there/path#fragment')
    assert not v.validate(el, None)
    eq_(el.errors, ['X'])


def test_url_validator_parts():
    v = URLValidator(allowed_parts=(), blocked_part='X')
    el = scalar('http://me:you@there/path#fragment')
    assert not v.validate(el, None)
    eq_(el.errors, ['X'])

    v = URLValidator(allowed_parts=_url_parts)
    el = scalar('http://me:you@there/path#fragment')
    assert v.validate(el, None)
    assert not el.errors

    v = URLValidator(allowed_parts=('scheme', 'netloc'))

# Path: flatland/schema/scalars.py
# class String(Scalar):
#     """A regular old Unicode string."""
# 
#     strip = True
#     """If true, strip leading and trailing whitespace during conversion."""
# 
#     def adapt(self, value):
#         """Return a Unicode representation.
# 
#         :returns: a ``unicode`` value or ``None``
# 
#         If :attr:`strip` is true, leading and trailing whitespace will be
#         removed.
# 
#         """
#         if value is None:
#             return None
#         elif self.strip:
#             return unicode(value).strip()
#         else:
#             return unicode(value)
# 
#     def serialize(self, value):
#         """Return a Unicode representation.
# 
#         :returns: a ``unicode`` value or ``u'' if *value* is ``None``
# 
#         If :attr:`strip` is true, leading and trailing whitespace will be
#         removed.
# 
#         """
#         if value is None:
#             return u''
#         elif self.strip:
#             return unicode(value).strip()
#         else:
#             return unicode(value)
# 
#     @property
#     def is_empty(self):
#         """True if the String is missing or has no value."""
#         return True if (not self.value and self.u == u'') else False


# Path: tests/validation/test_network.py
import re
from flatland import String
from flatland.validation import (
    IsEmail,
    HTTPURLValidator,
    URLCanonicalizer,
    URLValidator,
    )
from flatland.validation.network import _url_parts
from tests._util import eq_

    v = URLValidator()
    el = scalar('http://me:you@there/path#fragment')
    assert v.validate(el, None)
    assert not el.errors


def test_url_validator_schemes():
    v = URLValidator(allowed_schemes=(), blocked_scheme='X')
    el = scalar('http://me:you@there/path#fragment')
    assert not v.validate(el, None)
    eq_(el.errors, ['X'])

    v = URLValidator(allowed_schemes=('https',), blocked_scheme='X')
    el = scalar('http://me:you@there/path#fragment')
    assert not v.validate(el, None)
    eq_(el.errors, ['X'])


def test_url_validator_parts():
    v = URLValidator(allowed_parts=(), blocked_part='X')
    el = scalar('http://me:you@there/path#fragment')
    assert not v.validate(el, None)
    eq_(el.errors, ['X'])

    v = URLValidator(allowed_parts=_url_parts)
    el = scalar('http://me:you@there/path#fragment')
    assert v.validate(el, None)
    assert not el.errors

    v = URLValidator(allowed_parts=('scheme', 'netloc'))

    el = scalar('http://blarg')