How to use the clevercsv.parser.State function in clevercsv

To help you get started, we’ve selected a few clevercsv 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 alan-turing-institute / CleverCSV / clevercsv / parser.py View on Github external
def _quote_in_quoted_field(self, u):
        if u == self.dialect.quotechar:
            self.parse_add_char(u)
            self.state = State.IN_QUOTED_FIELD
        elif u == self.dialect.delimiter:
            self.parse_save_field()
            self.state = State.START_FIELD
        elif u == "\r" or u == "\n" or u == "\0":
            self.parse_save_field()
            self.state = State.START_RECORD if u == "\0" else State.EAT_CRNL
        elif not self.dialect.strict:
            self.parse_add_char(u)
            self.state = State.IN_FIELD
        else:
            raise Error(
                "'%c' expected after '%c'"
                % (self.dialect.delimiter, self.dialect.quotechar)
            )
        return 0
github alan-turing-institute / CleverCSV / clevercsv / parser.py View on Github external
def _quote_in_quoted_field(self, u):
        if u == self.dialect.quotechar:
            self.parse_add_char(u)
            self.state = State.IN_QUOTED_FIELD
        elif u == self.dialect.delimiter:
            self.parse_save_field()
            self.state = State.START_FIELD
        elif u == "\r" or u == "\n" or u == "\0":
            self.parse_save_field()
            self.state = State.START_RECORD if u == "\0" else State.EAT_CRNL
        elif not self.dialect.strict:
            self.parse_add_char(u)
            self.state = State.IN_FIELD
        else:
            raise Error(
                "'%c' expected after '%c'"
                % (self.dialect.delimiter, self.dialect.quotechar)
            )
        return 0
github alan-turing-institute / CleverCSV / clevercsv / parser.py View on Github external
def _in_field(self, u):
        if u == "\r" or u == "\n" or u == "\0":
            # EOL return [fields]
            self.parse_save_field()
            self.state = State.START_RECORD if u == "\0" else State.EAT_CRNL
        elif u == self.dialect.escapechar:
            self.state = State.ESCAPED_CHAR
        elif u == self.dialect.quotechar:
            self.parse_add_char(u)
            self.state = State.IN_QUOTED_FIELD
        elif u == self.dialect.delimiter:
            self.parse_save_field()
            self.state = State.START_FIELD
        else:
            self.parse_add_char(u)
        return 0
github alan-turing-institute / CleverCSV / clevercsv / parser.py View on Github external
def _in_field(self, u):
        if u == "\r" or u == "\n" or u == "\0":
            # EOL return [fields]
            self.parse_save_field()
            self.state = State.START_RECORD if u == "\0" else State.EAT_CRNL
        elif u == self.dialect.escapechar:
            self.state = State.ESCAPED_CHAR
        elif u == self.dialect.quotechar:
            self.parse_add_char(u)
            self.state = State.IN_QUOTED_FIELD
        elif u == self.dialect.delimiter:
            self.parse_save_field()
            self.state = State.START_FIELD
        else:
            self.parse_add_char(u)
        return 0
github alan-turing-institute / CleverCSV / clevercsv / parser.py View on Github external
def _in_quoted_field(self, u, v):
        if u == "\0":
            pass
        elif u == self.dialect.escapechar:
            self.state = State.ESCAPE_IN_QUOTED_FIELD
        elif u == self.dialect.quotechar:
            if v == self.dialect.quotechar:
                self.dialect.doublequote = True
                self.state = State.QUOTE_IN_QUOTED_FIELD
            elif self.dialect.strict:
                raise Error(
                    "'%c' expected after '%c'"
                    % (self.dialect.delimiter, self.dialect.quotechar)
                )
            else:
                self.parse_add_char(u)
                self.state = State.IN_FIELD
        else:
            self.parse_add_char(u)
        return 0
github alan-turing-institute / CleverCSV / clevercsv / parser.py View on Github external
def parse_process_char(self, u, v):
        if self.state == State.START_RECORD:
            fallthru, retcode = self._start_record(u)
            if fallthru:
                self._start_field(u)
        elif self.state == State.START_FIELD:
            retcode = self._start_field(u)
        elif self.state == State.ESCAPED_CHAR:
            retcode = self._escaped_char(u)
        elif self.state == State.AFTER_ESCAPED_CRNL:
            fallthru, retcode = self._after_escaped_crnl(u)
            if fallthru:
                self._in_field(u)
        elif self.state == State.IN_FIELD:
            retcode = self._in_field(u)
        elif self.state == State.IN_QUOTED_FIELD:
            retcode = self._in_quoted_field(u, v)
        elif self.state == State.ESCAPE_IN_QUOTED_FIELD:
github alan-turing-institute / CleverCSV / clevercsv / parser.py View on Github external
def parse_process_char(self, u, v):
        if self.state == State.START_RECORD:
            fallthru, retcode = self._start_record(u)
            if fallthru:
                self._start_field(u)
        elif self.state == State.START_FIELD:
            retcode = self._start_field(u)
        elif self.state == State.ESCAPED_CHAR:
            retcode = self._escaped_char(u)
        elif self.state == State.AFTER_ESCAPED_CRNL:
            fallthru, retcode = self._after_escaped_crnl(u)
            if fallthru:
                self._in_field(u)
        elif self.state == State.IN_FIELD:
            retcode = self._in_field(u)
        elif self.state == State.IN_QUOTED_FIELD:
            retcode = self._in_quoted_field(u, v)
        elif self.state == State.ESCAPE_IN_QUOTED_FIELD:
            retcode = self._escape_in_quoted_field(u)
        elif self.state == State.QUOTE_IN_QUOTED_FIELD:
            retcode = self._quote_in_quoted_field(u)
        elif self.state == State.EAT_CRNL:
            retcode = self._eat_crnl(u)

        return retcode
github alan-turing-institute / CleverCSV / clevercsv / parser.py View on Github external
def _quote_in_quoted_field(self, u):
        if u == self.dialect.quotechar:
            self.parse_add_char(u)
            self.state = State.IN_QUOTED_FIELD
        elif u == self.dialect.delimiter:
            self.parse_save_field()
            self.state = State.START_FIELD
        elif u == "\r" or u == "\n" or u == "\0":
            self.parse_save_field()
            self.state = State.START_RECORD if u == "\0" else State.EAT_CRNL
        elif not self.dialect.strict:
            self.parse_add_char(u)
            self.state = State.IN_FIELD
        else:
            raise Error(
                "'%c' expected after '%c'"
                % (self.dialect.delimiter, self.dialect.quotechar)
            )
        return 0
github alan-turing-institute / CleverCSV / clevercsv / parser.py View on Github external
def _in_quoted_field(self, u, v):
        if u == "\0":
            pass
        elif u == self.dialect.escapechar:
            self.state = State.ESCAPE_IN_QUOTED_FIELD
        elif u == self.dialect.quotechar:
            if v == self.dialect.quotechar:
                self.dialect.doublequote = True
                self.state = State.QUOTE_IN_QUOTED_FIELD
            elif self.dialect.strict:
                raise Error(
                    "'%c' expected after '%c'"
                    % (self.dialect.delimiter, self.dialect.quotechar)
                )
            else:
                self.parse_add_char(u)
                self.state = State.IN_FIELD
        else:
            self.parse_add_char(u)
        return 0