Beispiel #1
0
    def _process_default(self, line):
        """Read the rest of a DEFAULT line.:"""

        if line[1].match("PARENT"):

            parent = self._get_string(line, 2, "parent tag")
            self._check_rubbish(line, 2)

            if self.debug:
                print ">>> DEFAULT PARENT '%s'" % parent

        elif line[1].match("PRINTABLE") and line[2].match("GRAPHICS"):

            graphics = self._get_string(line, 3, "printable graphics")
            self._check_rubbish(line, 3)

            if self.debug:
                print ">>> PRINTABLE GRAPHICS '%s'" % graphics

        elif line[1].match("ESCAPE"):

            escape = self._get_string(line, 2,
                                      "truncated escape/collection number")
            self._check_rubbish(line, 2)

            if self.debug:
                print ">>> ESCAPE '%s' (%s)" % (printable(escape),
                                                iso2022_charset(escape, TRUE))

        else:
            raise dfd_parse_error,\
                  (line,"Unrecognised DEFAULT construct `%s'"%line[1])
Beispiel #2
0
    def _process_default(self, line):
        """Read the rest of a DEFAULT line.:"""

        if line[1].match("PARENT"):

            parent = self._get_string(line, 2, "parent tag")
            self._check_rubbish(line, 2)

            if self.debug:
                print ">>> DEFAULT PARENT '%s'" % parent

        elif line[1].match("PRINTABLE") and line[2].match("GRAPHICS"):

            graphics = self._get_string(line, 3, "printable graphics")
            self._check_rubbish(line, 3)

            if self.debug:
                print ">>> PRINTABLE GRAPHICS '%s'" % graphics

        elif line[1].match("ESCAPE"):

            escape = self._get_string(line, 2, "truncated escape/collection number")
            self._check_rubbish(line, 2)

            if self.debug:
                print ">>> ESCAPE '%s' (%s)" % (printable(escape), iso2022_charset(escape, TRUE))

        else:
            raise dfd_parse_error, (line, "Unrecognised DEFAULT construct `%s'" % line[1])
Beispiel #3
0
    def _read_field(self, line):
        """Read the contents of a FIELD...END FIELD structure."""

        # Deal with the rest of the FIELD line

        tag = self._get_string(line, 1, "field tag")

        if len(line) > 2:
            name = self._get_string(line, 2, "field name")
            self._check_rubbish(line, 2)
        else:
            name = ""
            self._check_rubbish(line, 1)

        if self.debug:
            print ">>> FIELD '%s' '%s'" % (tag, name)

            # Prime the formatting

        format = Format()

        format.start_format()

        # Deal with the rest of the field structure

        while 1:
            # Read the next significant line in

            try:
                line = self._get_next_line()

            except dfd_eof, detail:
                raise dfd_unexpeof, "End of file not expected inside FIELD data"

                # Do what seems appropriate

            if line[0].match("END") and line[1].match("FIELD"):

                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>> END FIELD"

                return

            elif line[0].match("PARENT"):

                parent = self._get_string(line, 1, "parent tag")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    PARENT '%s'" % parent

                pass

            elif line[0].match("PRINTABLE") and line[1].match("GRAPHICS"):

                graphics = self._get_string(line, 2, "printable graphics")
                self._check_rubbish(line, 2)

                if self.debug:
                    print ">>>    PRINTABLE GRAPHICS '%s'" % graphics

                pass

            elif line[0].match("ESCAPE"):

                escape = self._get_string(line, 1, "truncated escape/collection number")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    ESCAPE '%s' (%s)" % (printable(escape), iso2022_charset(escape, TRUE))

                pass

            elif line[0].match("STRUCTURE") and line[1].match("CODE"):

                # This will read until END FIELD for us

                self._read_labels(line, "STRUCTURE CODE", format)

                if self.debug:
                    print format
                    # format.write_DFD(sys.stdout)
                return

            elif line[0].match("NUMERIC") and line[1].match("DESCRIPTOR"):

                # This will read until END FIELD for us

                self._read_labels(line, "NUMERIC DESCRIPTOR", format)

                if self.debug:
                    print format
                    # format.write_DFD(sys.stdout)
                return

            elif line[0].match("FOR"):

                # This will read until END FIELD for us

                self._read_labels(line, "FOR", format)

                if self.debug:
                    print format
                    # format.write_DFD(sys.stdout)
                return

            elif line[0].match("BY"):

                raise dfd_parse_error, (line, "Cannot have BY before FOR")

            elif line[0].match("REPEAT"):

                raise dfd_parse_error, (line, "Cannot have REPEAT before FOR")

            elif line[0].match("END") and line[1].match("REPEAT"):

                raise dfd_parse_error, (line, "Cannot have END REPEAT before FOR")

            elif line[0].match("THEN"):

                raise dfd_parse_error, (line, "Cannot have THEN before FOR")

            else:
                raise dfd_parse_error, (line, "Unexpected item %s" % line[0])
Beispiel #4
0
    def _read_leader(self):
        """Read the contents of a LEADER...END LEADER structure."""

        while 1:
            # Read the next significant line in

            try:
                line = self._get_next_line()

            except dfd_eof, detail:
                raise dfd_unexpeof, "End of file not expected inside LEADER data"

                # Do what seems appropriate

            if line[0].match("END") and line[1].match("LEADER"):

                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>> END LEADER"

                self.had_leader = TRUE

                return

            elif line[0].match("TAG") and line[1].match("LENGTH"):

                length = self._get_number(line, 2, "tag length")
                self._check_rubbish(line, 2)

                if self.debug:
                    print ">>>    TAG LENGTH %d" % length

                pass

            elif line[0].match("LEVEL"):

                level = self._get_number(line, 1, "level")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    LEVEL %d" % level

                pass

            elif line[0].match("VERSION"):

                version = self._get_number(line, 1, "version")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    VERSION %d" % version

                pass

            elif line[0].match("FORM"):

                form = self._get_string(line, 1, "form")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    FORM '%s'" % form

                pass

            elif line[0].match("INLINE") and line[1].match("EXTENSION") and line[2].match("CODE"):

                code = self._get_string(line, 3, "inline extension code")
                self._check_rubbish(line, 3)

                if self.debug:
                    print ">>>    INLINE EXTENSION CODE '%s'" % code

                pass

            elif line[0].match("APPLICATION") and line[1].match("INDICATOR"):

                appl = self._get_string(line, 2, "application indicator")
                self._check_rubbish(line, 2)

                if self.debug:
                    print ">>>    APPLICATION INDICATOR '%s'" % printable(appl)

                pass

            elif line[0].match("ESCAPE"):

                esc = self._get_string(line, 1, "truncated escape or collection number")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    ESCAPE '%s' (%s)" % (printable(esc), iso2022_charset(esc, TRUE))

                pass

            else:
                raise dfd_parse_error, (line, "Unrecognised LEADER construct `%s'" % line[0])
Beispiel #5
0
    def __repr__(self):

        if self.is_keyword:
            return printable(self.text)
        else:
            return "'" + printable(self.text) + "'"
Beispiel #6
0
    def _read_field(self, line):
        """Read the contents of a FIELD...END FIELD structure."""

        # Deal with the rest of the FIELD line

        tag = self._get_string(line, 1, "field tag")

        if len(line) > 2:
            name = self._get_string(line, 2, "field name")
            self._check_rubbish(line, 2)
        else:
            name = ""
            self._check_rubbish(line, 1)

        if self.debug:
            print ">>> FIELD '%s' '%s'" % (tag, name)

        # Prime the formatting

        format = Format()

        format.start_format()

        # Deal with the rest of the field structure

        while 1:
            # Read the next significant line in

            try:
                line = self._get_next_line()

            except dfd_eof, detail:
                raise dfd_unexpeof, "End of file not expected inside FIELD data"

            # Do what seems appropriate

            if line[0].match("END") and line[1].match("FIELD"):

                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>> END FIELD"

                return

            elif line[0].match("PARENT"):

                parent = self._get_string(line, 1, "parent tag")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    PARENT '%s'" % parent

                pass

            elif line[0].match("PRINTABLE") and line[1].match("GRAPHICS"):

                graphics = self._get_string(line, 2, "printable graphics")
                self._check_rubbish(line, 2)

                if self.debug:
                    print ">>>    PRINTABLE GRAPHICS '%s'" % graphics

                pass

            elif line[0].match("ESCAPE"):

                escape = self._get_string(
                    line, 1, "truncated escape/collection number")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    ESCAPE '%s' (%s)" % (
                        printable(escape), iso2022_charset(escape, TRUE))

                pass

            elif line[0].match("STRUCTURE") and line[1].match("CODE"):

                # This will read until END FIELD for us

                self._read_labels(line, "STRUCTURE CODE", format)

                if self.debug:
                    print format
                    #format.write_DFD(sys.stdout)
                return

            elif line[0].match("NUMERIC") and line[1].match("DESCRIPTOR"):

                # This will read until END FIELD for us

                self._read_labels(line, "NUMERIC DESCRIPTOR", format)

                if self.debug:
                    print format
                    #format.write_DFD(sys.stdout)
                return

            elif line[0].match("FOR"):

                # This will read until END FIELD for us

                self._read_labels(line, "FOR", format)

                if self.debug:
                    print format
                    #format.write_DFD(sys.stdout)
                return

            elif line[0].match("BY"):

                raise dfd_parse_error, (line, "Cannot have BY before FOR")

            elif line[0].match("REPEAT"):

                raise dfd_parse_error, (line, "Cannot have REPEAT before FOR")

            elif line[0].match("END") and line[1].match("REPEAT"):

                raise dfd_parse_error, (line,
                                        "Cannot have END REPEAT before FOR")

            elif line[0].match("THEN"):

                raise dfd_parse_error, (line, "Cannot have THEN before FOR")

            else:
                raise dfd_parse_error,\
                      (line,"Unexpected item %s"%line[0])
Beispiel #7
0
    def _read_leader(self):
        """Read the contents of a LEADER...END LEADER structure."""

        while 1:
            # Read the next significant line in

            try:
                line = self._get_next_line()

            except dfd_eof, detail:
                raise dfd_unexpeof, "End of file not expected inside LEADER data"

            # Do what seems appropriate

            if line[0].match("END") and line[1].match("LEADER"):

                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>> END LEADER"

                self.had_leader = TRUE

                return

            elif line[0].match("TAG") and line[1].match("LENGTH"):

                length = self._get_number(line, 2, "tag length")
                self._check_rubbish(line, 2)

                if self.debug:
                    print ">>>    TAG LENGTH %d" % length

                pass

            elif line[0].match("LEVEL"):

                level = self._get_number(line, 1, "level")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    LEVEL %d" % level

                pass

            elif line[0].match("VERSION"):

                version = self._get_number(line, 1, "version")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    VERSION %d" % version

                pass

            elif line[0].match("FORM"):

                form = self._get_string(line, 1, "form")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    FORM '%s'" % form

                pass

            elif line[0].match("INLINE") and line[1].match("EXTENSION") and\
                 line[2].match("CODE"):

                code = self._get_string(line, 3, "inline extension code")
                self._check_rubbish(line, 3)

                if self.debug:
                    print ">>>    INLINE EXTENSION CODE '%s'" % code

                pass

            elif line[0].match("APPLICATION") and line[1].match("INDICATOR"):

                appl = self._get_string(line, 2, "application indicator")
                self._check_rubbish(line, 2)

                if self.debug:
                    print ">>>    APPLICATION INDICATOR '%s'" % printable(appl)

                pass

            elif line[0].match("ESCAPE"):

                esc = self._get_string(
                    line, 1, "truncated escape or collection number")
                self._check_rubbish(line, 1)

                if self.debug:
                    print ">>>    ESCAPE '%s' (%s)" % (
                        printable(esc), iso2022_charset(esc, TRUE))

                pass

            else:
                raise dfd_parse_error,\
                      (line,"Unrecognised LEADER construct `%s'"%line[0])
Beispiel #8
0
    def __repr__(self):

        if self.is_keyword:
            return printable(self.text)
        else:
            return "'" + printable(self.text) + "'"