How to use the followthemoney.types.common.PropertyType function in followthemoney

To help you get started, we’ve selected a few followthemoney 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 alephdata / followthemoney / followthemoney / types / registry.py View on Github external
def get(self, name):
        """For a given property type name, get its handling object."""
        # Allow transparent re-checking.
        if isinstance(name, PropertyType):
            return name
        return self._types.get(name)
github alephdata / followthemoney / followthemoney / types / iban.py View on Github external
from rdflib import URIRef  # type: ignore
from stdnum import iban  # type: ignore
from stdnum.exceptions import ValidationError  # type: ignore

from followthemoney.types.common import PropertyType
from followthemoney.util import sanitize_text, defer as _


class IbanType(PropertyType):
    name = "iban"
    group = "ibans"
    label = _("IBAN")
    plural = _("IBANs")
    matchable = True
    pivot = True

    def validate(self, text, **kwargs):
        text = sanitize_text(text)
        try:
            return iban.validate(text)
        except ValidationError:
            return False

    def clean_text(self, text, **kwargs):
        """Create a more clean, but still user-facing version of an
github alephdata / followthemoney / followthemoney / types / string.py View on Github external
from followthemoney.types.common import PropertyType
from followthemoney.util import defer as _
from followthemoney.util import MEGABYTE


class StringType(PropertyType):
    name = "string"
    label = _("Label")
    plural = _("Labels")
    matchable = False


class TextType(PropertyType):
    name = "text"
    label = _("Text")
    plural = _("Texts")
    matchable = False
    max_size = 30 * MEGABYTE

    def node_id(self, value):
        return None
github alephdata / followthemoney / followthemoney / types / string.py View on Github external
plural = _("Labels")
    matchable = False


class TextType(PropertyType):
    name = "text"
    label = _("Text")
    plural = _("Texts")
    matchable = False
    max_size = 30 * MEGABYTE

    def node_id(self, value):
        return None


class HTMLType(PropertyType):
    name = "html"
    label = _("HTML")
    plural = _("HTMLs")
    matchable = False
    max_size = 30 * MEGABYTE

    def node_id(self, value):
        return None
github alephdata / followthemoney / followthemoney / types / string.py View on Github external
from followthemoney.types.common import PropertyType
from followthemoney.util import defer as _
from followthemoney.util import MEGABYTE


class StringType(PropertyType):
    name = "string"
    label = _("Label")
    plural = _("Labels")
    matchable = False


class TextType(PropertyType):
    name = "text"
    label = _("Text")
    plural = _("Texts")
    matchable = False
    max_size = 30 * MEGABYTE

    def node_id(self, value):
        return None


class HTMLType(PropertyType):
    name = "html"
    label = _("HTML")
    plural = _("HTMLs")
    matchable = False
    max_size = 30 * MEGABYTE
github alephdata / followthemoney / followthemoney / types / ip.py View on Github external
from rdflib import URIRef  # type: ignore
from ipaddress import ip_address  # type: ignore

from followthemoney.types.common import PropertyType
from followthemoney.util import defer as _


class IpType(PropertyType):
    name = "ip"
    group = "ips"
    label = _("IP-Address")
    plural = _("IP-Addresses")
    matchable = True

    def validate(self, ip, **kwargs):
        """Check to see if this is a valid ip address."""
        try:
            ip_address(ip)
            return True
        except ValueError:
            return False

    def clean_text(self, text, **kwargs):
        """Create a more clean, but still user-facing version of an
github alephdata / followthemoney / followthemoney / types / json.py View on Github external
import json  # yay Python 3
from banal import ensure_list

from followthemoney.types.common import PropertyType
from followthemoney.util import sanitize_text, defer as _


class JsonType(PropertyType):
    name = "json"
    group = None
    label = _("Nested data")
    matchable = False

    def pack(self, obj):
        """Encode a given value to JSON."""
        # TODO: use a JSON encoder that handles more types?
        if obj is not None:
            return json.dumps(obj)

    def unpack(self, obj):
        """Decode a given JSON object."""
        if obj is None:
            return
        try:
github alephdata / followthemoney / followthemoney / types / email.py View on Github external
import re
import logging
from rdflib import URIRef  # type: ignore
from normality.cleaning import strip_quotes

from followthemoney.types.common import PropertyType
from followthemoney.types.domain import DomainType
from followthemoney.util import sanitize_text, defer as _

log = logging.getLogger(__name__)


class EmailType(PropertyType):
    EMAIL_REGEX = re.compile(r"^[^@\s]+@[^@\s]+\.\w+$")
    domains = DomainType()
    name = "email"
    group = "emails"
    label = _("E-Mail Address")
    plural = _("E-Mail Addresses")
    matchable = True
    pivot = True

    def validate(self, email, **kwargs):
        """Check to see if this is a valid email address."""
        # TODO: adopt email.utils.parseaddr
        email = sanitize_text(email)
        if email is None:
            return False
        if not self.EMAIL_REGEX.match(email):
github alephdata / followthemoney / followthemoney / types / mimetype.py View on Github external
from rdflib import URIRef  # type: ignore
from pantomime import normalize_mimetype, parse_mimetype  # type: ignore
from pantomime import DEFAULT  # type: ignore

from followthemoney.types.common import PropertyType
from followthemoney.util import defer as _


class MimeType(PropertyType):
    name = "mimetype"
    group = "mimetypes"
    label = _("MIME-Type")
    plural = _("MIME-Types")
    matchable = False

    def clean_text(self, text, **kwargs):
        text = normalize_mimetype(text)
        if text != DEFAULT:
            return text

    def rdf(self, value):
        return URIRef("urn:mimetype:%s" % value)

    def caption(self, value):
        return parse_mimetype(value).label