[PATCH 04/21] Move our custom errors to their own module
Mathieu Bridon
bochecha at fedoraproject.org
Wed May 6 11:53:00 UTC 2015
From: Mathieu Bridon <bochecha at daitauha.fr>
This will make it easier to reuse them. It also makes the main module a
bit shorter, which can't be a bad thing.
And while I'm at it, I'm documenting all those error classes.
---
src/pyrpkg/__init__.py | 12 ++----------
src/pyrpkg/errors.py | 34 ++++++++++++++++++++++++++++++++++
src/pyrpkg/sources.py | 14 ++------------
3 files changed, 38 insertions(+), 22 deletions(-)
create mode 100644 src/pyrpkg/errors.py
diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py
index b32effc..c6a13ca 100644
--- a/src/pyrpkg/__init__.py
+++ b/src/pyrpkg/__init__.py
@@ -38,16 +38,8 @@ try:
except ImportError:
pass
-from pyrpkg.sources import HashtypeMixingError, SourcesFile
-
-
-# Define our own error class
-class rpkgError(Exception):
- faultCode = 1000
-
-class rpkgAuthError(rpkgError):
- """Raised when there is an error in authentication"""
- faultCode = 1002
+from pyrpkg.errors import HashtypeMixingError, rpkgError, rpkgAuthError
+from pyrpkg.sources import SourcesFile
# Setup our logger
diff --git a/src/pyrpkg/errors.py b/src/pyrpkg/errors.py
new file mode 100644
index 0000000..ec67bdb
--- /dev/null
+++ b/src/pyrpkg/errors.py
@@ -0,0 +1,34 @@
+# Copyright (c) 2015 - Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
+# the full text of the license.
+
+
+"""Custom error classes"""
+
+
+class rpkgError(Exception):
+ """Our base error class"""
+ faultCode = 1000
+
+
+class rpkgAuthError(rpkgError):
+ """Raised in case of authentication errors"""
+ faultCode = 1002
+
+
+class HashtypeMixingError(rpkgError):
+ """Raised when we try to mix hash types in a sources file"""
+ def __init__(self, existing_hashtype, new_hashtype):
+ super(HashtypeMixingError, self).__init__()
+
+ self.existing_hashtype = existing_hashtype
+ self.new_hashtype = new_hashtype
+
+
+class MalformedLineError(rpkgError):
+ """Raised when parsing a sources file with malformed lines"""
+ pass
diff --git a/src/pyrpkg/sources.py b/src/pyrpkg/sources.py
index a3ff1b1..1486c53 100644
--- a/src/pyrpkg/sources.py
+++ b/src/pyrpkg/sources.py
@@ -19,23 +19,13 @@ entries, and write these entries to the file in the proper format.
import os
import re
+from .errors import HashtypeMixingError, MalformedLineError
+
LINE_PATTERN = re.compile(
r'^(?P<hashtype>[^ ]+?) \((?P<file>[^ )]+?)\) = (?P<hash>[^ ]+?)$')
-class HashtypeMixingError(Exception):
- def __init__(self, existing_hashtype, new_hashtype):
- super(HashtypeMixingError, self).__init__()
-
- self.existing_hashtype = existing_hashtype
- self.new_hashtype = new_hashtype
-
-
-class MalformedLineError(Exception):
- pass
-
-
class SourcesFile(object):
def __init__(self, sourcesfile, entry_type, replace=False):
self.sourcesfile = sourcesfile
--
2.1.0
More information about the rel-eng
mailing list