How to use the pymarc.exceptions.BadLeaderValue function in pymarc

To help you get started, we’ve selected a few pymarc 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 edsu / pymarc / test / test_leader.py View on Github external
def test_setters_errors(self):
        leader = Leader(LEADER)
        for field, index, expected in FIELDS:
            value = random_string(len(expected) + 1)
            with self.assertRaises(BadLeaderValue):
                setattr(leader, field, value)
github edsu / pymarc / pymarc / leader.py View on Github external
def type_of_control(self, value):
        # type: (str) -> str
        """Type of control (08)."""
        if len(value) != 1:
            raise BadLeaderValue("Type of control is 1 char field, got %s" % value)
        self._replace_values(position=8, value=value)
github edsu / pymarc / pymarc / leader.py View on Github external
def multipart_ressource(self, value):
        # type: (str) -> str
        """Multipart resource record level (19)."""
        if len(value) != 1:
            raise BadLeaderValue(
                "Multipart resource record level is 1 char field, got %s" % value
            )
        self._replace_values(position=19, value=value)
github edsu / pymarc / pymarc / leader.py View on Github external
def subfield_code_count(self, value):
        # type: (str) -> str
        """Subfield code count (11)."""
        if len(value) != 1:
            raise BadLeaderValue("Subfield code count is 1 char field, got %s" % value)
        self._replace_values(position=11, value=value)
github edsu / pymarc / pymarc / leader.py View on Github external
def length_of_field_length(self, value):
        # type: (str) -> str
        """Length of the length-of-field portion (20)."""
        if len(value) != 1:
            raise BadLeaderValue(
                "Length of the length-of-field portion is 1 char field, got %s" % value
            )
        self._replace_values(position=20, value=value)
github edsu / pymarc / pymarc / leader.py View on Github external
def encoding_level(self, value):
        # type: (str) -> str
        """Encoding level (17)."""
        if len(value) != 1:
            raise BadLeaderValue("Encoding level is 1 char field, got %s" % value)
        self._replace_values(position=17, value=value)
github edsu / pymarc / pymarc / leader.py View on Github external
def base_address(self, value):
        # type: (str) -> str
        """Base address of data (12-16)."""
        if len(value) != 5:
            raise BadLeaderValue(
                "Base address of data is 4 chars field, got %s" % value
            )
        self._replace_values(position=12, value=value)
github edsu / pymarc / pymarc / leader.py View on Github external
def _replace_values(self, position, value):
        # type: (int, str) -> str
        """Replaces the values in the leader at `position` by `value`."""
        if position < 0:
            raise IndexError("Position must be positive")
        after = position + len(value)
        if after > LEADER_LEN:
            raise BadLeaderValue(
                "%s is too long to be inserted at %d" % (value, position)
            )
        self.leader = self.leader[:position] + value + self.leader[after:]
github edsu / pymarc / pymarc / leader.py View on Github external
def type_of_record(self, value):
        # type: (str) -> str
        """Type of record (06)."""
        if len(value) != 1:
            raise BadLeaderValue("Type of record is 1 char field, got %s" % value)
        self._replace_values(position=6, value=value)
github edsu / pymarc / pymarc / leader.py View on Github external
def indicator_count(self, value):
        # type: (str) -> str
        """Indicator count (10)."""
        if len(value) != 1:
            raise BadLeaderValue("Indicator count is 1 char field, got %s" % value)
        self._replace_values(position=10, value=value)