Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 6c9b48e

Browse files
author
dmp42
committed
Add new compat and exceptions files
1 parent 6728ca4 commit 6c9b48e

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed

docker_registry/lib/core/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
docker-registry.core
4+
~~~~~~~~~~~~~~~
5+
6+
"""
7+
8+
from __future__ import absolute_import
9+
10+
__all__ = []

docker_registry/lib/core/compat.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
docker-registry.compat
4+
~~~~~~~~~~~~~~~~~~~~~~
5+
6+
This file defines a collection of properties to quickly identify what python
7+
runtime/version we are working with, and handles the import of modules
8+
that changed, hence hiding import gymnastics from other components.
9+
10+
Use imports from here to ensure portability.
11+
12+
Largely stolen from requests (http://docs.python-requests.org/en/latest/)
13+
under Apache2 license
14+
"""
15+
16+
__all__ = []
17+
18+
import logging
19+
logger = logging.getLogger(__name__)
20+
21+
import sys
22+
23+
# -------
24+
# Pythons
25+
# -------
26+
27+
_ver = sys.version_info
28+
29+
is_py2 = (_ver[0] == 2)
30+
is_py3 = (_ver[0] == 3)
31+
32+
is_py25 = (is_py2 and _ver[1] == 5)
33+
is_py26 = (is_py2 and _ver[1] == 6)
34+
# is_py27 = (is_py2 and _ver[1] == 7)
35+
# is_py30 = (is_py3 and _ver[1] == 0)
36+
# is_py31 = (is_py3 and _ver[1] == 1)
37+
# is_py32 = (is_py3 and _ver[1] == 2)
38+
# is_py33 = (is_py3 and _ver[1] == 3)
39+
# is_py34 = (is_py3 and _ver[1] == 4)
40+
41+
# ---------
42+
# Platforms
43+
# ---------
44+
45+
# _ver = sys.version.lower()
46+
47+
# is_pypy = ('pypy' in _ver)
48+
# is_jython = ('jython' in _ver)
49+
# is_ironpython = ('iron' in _ver)
50+
# is_cpython = not any((is_pypy, is_jython, is_ironpython))
51+
52+
# is_windows = 'win32' in str(sys.platform).lower()
53+
# is_linux = ('linux' in str(sys.platform).lower())
54+
# is_osx = ('darwin' in str(sys.platform).lower())
55+
# is_hpux = ('hpux' in str(sys.platform).lower()) # Complete guess.
56+
# is_solaris = ('solar' in str(sys.platform).lower()) # Complete guess.
57+
58+
if is_py25 or is_py26:
59+
logger.debug("Old python! Using simplejson.")
60+
try:
61+
import simplejson as json # noqa
62+
except ImportError:
63+
json = {}
64+
else:
65+
import json # noqa
66+
67+
# ---------
68+
# Specifics
69+
# ---------
70+
71+
if is_py2:
72+
logger.debug("This is python2")
73+
from urllib import quote_plus # noqa
74+
75+
builtin_str = str
76+
bytes = str
77+
str = unicode
78+
basestring = basestring
79+
# numeric_types = (int, long, float)
80+
81+
elif is_py3:
82+
logger.debug("This is python3")
83+
from urllib.parse import quote_plus # noqa
84+
85+
builtin_str = str
86+
str = str
87+
bytes = bytes
88+
basestring = (str, bytes)
89+
# numeric_types = (int, float)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
docker-registry.exceptions
4+
~~~~~~~~~~~~~~~~~~~~~
5+
6+
"""
7+
8+
__all__ = [
9+
"UnspecifiedError",
10+
"UsageError", "NotImplementedError", "FileNotFoundError", "ConfigError"
11+
# "WrongArgumentsError",
12+
# "ConnectionError", "UnreachableError", "MissingError", "BrokenError"
13+
]
14+
15+
16+
class UnspecifiedError(Exception):
17+
18+
"""Base class for all exceptions in docker-registry.
19+
"""
20+
21+
def __init__(self, *args, **kwargs):
22+
self.message = kwargs.pop('message', 'No details')
23+
super(UnspecifiedError, self).__init__(*args, **kwargs)
24+
25+
26+
class UsageError(UnspecifiedError):
27+
28+
"""Exceptions related to use of the library."""
29+
30+
31+
class NotImplementedError(UsageError):
32+
33+
"""Requested feature is not supported / not implemented."""
34+
35+
36+
class FileNotFoundError(UsageError):
37+
38+
"""Requested (config) file not found."""
39+
40+
41+
class ConfigError(UsageError):
42+
43+
"""Something in the configuration file is not ok."""
44+
45+
46+
# class WrongArgumentsError(UsageError):
47+
48+
# """Expected arguments not satisfied."""
49+
50+
51+
# class ConnectionError(UnspecifiedError):
52+
53+
# """Exceptions related to server/client operation."""
54+
55+
56+
# class UnreachableError(ConnectionError):
57+
58+
# """The requested server is not reachable."""
59+
60+
61+
# class MissingError(ConnectionError):
62+
63+
# """The requested ressource is not to be found on the server."""
64+
65+
66+
# class BrokenError(ConnectionError):
67+
68+
# """Something died on our hands, that the server couldn't digest..."""

0 commit comments

Comments
 (0)