# 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_
    assert_email_valid(u'bob@snow\u2603man.com')


def test_email_nonlocal():
    assert_email_not_valid(u'root@localhost')


def test_email_nonlocal_ok():
    assert_email_valid(u'root@localhost', {'nonlocal': False})


def test_email_altlocal():
    override = dict(local_part_pattern=re.compile(r'^bob$'))
    assert_email_valid('bob@bob.com', override)
    assert_email_not_valid('foo@bar.com', override)


def test_email_bogus():
    c64 = u'x' * 64
    c63 = u'x' * 63
    for addr in (u'bob@zig..', u'bob@', u'@bob.com', u'@', u'snork',
                 u'bob@zig:zag.com', u'bob@zig zag.com', u'bob@zig/zag.com',
                 u' @zig.com', u'\t\t@zag.com',
                 u'bob@%s.com' % c64,
                 u'bob@%s.%s.%s.%s.com' % (c63, c63, c63, c63),
                 u'foo.com', u'bob@bob_bob.com', u''):
        yield assert_email_not_valid, addr


def scalar(value):

# 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_

    assert_email_valid(u'bob@snow\u2603man.com')


def test_email_nonlocal():
    assert_email_not_valid(u'root@localhost')


def test_email_nonlocal_ok():
    assert_email_valid(u'root@localhost', {'nonlocal': False})


def test_email_altlocal():
    override = dict(local_part_pattern=re.compile(r'^bob$'))
    assert_email_valid('bob@bob.com', override)
    assert_email_not_valid('foo@bar.com', override)


def test_email_bogus():
    c64 = u'x' * 64
    c63 = u'x' * 63
    for addr in (u'bob@zig..', u'bob@', u'@bob.com', u'@', u'snork',
                 u'bob@zig:zag.com', u'bob@zig zag.com', u'bob@zig/zag.com',
                 u' @zig.com', u'\t\t@zag.com',
                 u'bob@%s.com' % c64,
                 u'bob@%s.%s.%s.%s.com' % (c63, c63, c63, c63),
                 u'foo.com', u'bob@bob_bob.com', u''):
        yield assert_email_not_valid, addr


def scalar(value):

    return String(value, name='test')