Skip to content

Commit

Permalink
Merge pull request #36 from packit/nforro-sources
Browse files Browse the repository at this point in the history
Make Sources inherit from MutableSequence
  • Loading branch information
nforro authored Mar 31, 2022
2 parents e8081d6 + f1c3565 commit 75bfd49
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions specfile/sources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

import collections
import re
import urllib.parse
from abc import ABC, abstractmethod
Expand Down Expand Up @@ -185,8 +186,8 @@ def comments(self) -> Comments:
return self._source.comments


class Sources:
"""Class that represents a list of all sources."""
class Sources(collections.abc.MutableSequence):
"""Class that represents a sequence of all sources."""

PREFIX = "Source"

Expand Down Expand Up @@ -216,7 +217,7 @@ def __repr__(self) -> str:
# don't have to reimplement __repr__()
return f"{self.__class__.__name__}({tags}, {sourcelists}, {allow_duplicates})"

def __contains__(self, location: str) -> bool:
def __contains__(self, location: object) -> bool:
items = self._get_items()
if not items:
return False
Expand Down Expand Up @@ -346,15 +347,6 @@ def _deduplicate_tag_names(self) -> None:
ts0, ts0.index + 1
)

def append(self, location: str) -> None:
"""
Adds a new source.
Args:
location: Location of the new source.
"""
self.insert(len(self), location)

def insert(self, i: int, location: str) -> None:
"""
Inserts a new source at a specified index.
Expand Down Expand Up @@ -409,11 +401,6 @@ def remove(self, location: str) -> None:
if source.location == location:
del container[index]

def clear(self) -> None:
"""Removes all sources."""
for _, container, index in reversed(self._get_items()):
del container[index]

def count(self, location: str) -> int:
"""
Counts sources by location.
Expand All @@ -429,19 +416,9 @@ def count(self, location: str) -> int:
return 0
return len([s for s in list(zip(*items))[0] if s.location == location])

def extend(self, locations: List[str]) -> None:
"""
Extends the sources by a list of locations.
Args:
locations: List of locations of the sources to be added.
"""
for location in locations:
self.append(location)


class Patches(Sources):
"""Class that represents a list of all patches."""
"""Class that represents a sequence of all patches."""

PREFIX = "Patch"

Expand Down

0 comments on commit 75bfd49

Please sign in to comment.