<commit_before>__version__ = (0, 1)


from .parser import Parser
from .serializer import Serializer
from .curvedata import Curve, Comment, FrameCorrelation
from .validator import Validator
from .common import MalformedError


def parse(fileobj):
    """Parse a file-like object or a file-path
    """
    if isinstance(fileobj, basestring):
        fileobj = open(fileobj)

    return Parser(fileobj).parse()


def parse_str(string):
    """Parse a string containing a Framecurve
    """
    import StringIO
    return Parser(StringIO.StringIO(string)).parse()


def validate(fileobj):
    """Given a file-like object or a file-path, return a Validator
    object.

    The object has an "ok" property which is True if the curve is
    perfect (no errors or warnings).

    You can get a list of the errors and warnings from ".errors" and ".warnings"
    """

    if isinstance(fileobj, basestring):
        fileobj = open(fileobj)

    return Validator(fileobj)


def validate_str(string):
    """Validates a string containing a Framecurve

    >>> v = validate_str("10\t23.2")
    >>> v.ok
    False
    >>> v.warnings
    []
    >>> v.errors
    ["Malformed line 1: '10.2  23.5'"]
    """
    import StringIO
    return validator.Validator(fileobj = StringIO.StringIO(string))


def serialize(fileobj, curve):
    if isinstance(fileobj, basestring):
        fileobj = open(fileobj)

    s = Serializer(fileobj = fileobj, curve = curve)
    s.serialize()


def serialize_str(curve):
    fileobj = StringIO.StringIO()
    s = Serializer(fileobj = fileobj, curve = curve)
    return s.getvalue()<commit_msg>Fix validator and serialize methods<commit_after>__version__ = (0, 1)


from .parser import Parser
from .serializer import Serializer
from .curvedata import Curve, Comment, FrameCorrelation
from .validator import Validator
from .common import MalformedError


def parse(fileobj):
    """Parse a file-like object or a file-path
    """
    if isinstance(fileobj, basestring):
        fileobj = open(fileobj)

    return Parser(fileobj).parse()


def parse_str(string):
    """Parse a string containing a Framecurve
    """
    import StringIO
    return Parser(StringIO.StringIO(string)).parse()


def validate(fileobj = None, curve = None):
    """Given a file-like object or a file-path, return a Validator
    object.

    The object has an "ok" property which is True if the curve is
    perfect (no errors or warnings).

    You can get a list of the errors and warnings from ".errors" and ".warnings"
    """

    if isinstance(fileobj, basestring):
        fileobj = open(fileobj)

    return Validator(fileobj = fileobj, curve = curve)


def validate_str(string):
    """Validates a string containing a Framecurve

    >>> v = validate_str("10\t23.2")
    >>> v.ok
    False
    >>> v.warnings
    []
    >>> v.errors
    ["Malformed line 1: '10.2  23.5'"]
    """
    import StringIO
    return validator.Validator(fileobj = StringIO.StringIO(string))


def serialize(fileobj, curve):
    if isinstance(fileobj, basestring):
        fileobj = open(fileobj)

    s = Serializer(fileobj = fileobj, curve = curve)
    s.serialize()


def serialize_str(curve):
    import StringIO
    fileobj = StringIO.StringIO()
    s = Serializer(fileobj = fileobj, curve = curve)
    return fileobj.getvalue()
{'fraction_non_alphanumeric': 0.10580411124546554, 'fraction_numerical': 0.008464328899637243, 'mean_word_length': 3.2260536398467434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2605156', 'n_tokens_mistral': 1042, 'n_tokens_neox': 995, 'n_words': 319}