1911 |
1911 |
1912 class UnsupportedRepositoryURI(PublisherError): |
1912 class UnsupportedRepositoryURI(PublisherError): |
1913 """Used to indicate that the specified repository URI uses an |
1913 """Used to indicate that the specified repository URI uses an |
1914 unsupported scheme.""" |
1914 unsupported scheme.""" |
1915 |
1915 |
1916 def __str__(self): |
1916 |
1917 if self.data: |
1917 def __init__(self, uris=[]): |
1918 scheme = urlparse.urlsplit(self.data, |
1918 if isinstance(uris, basestring): |
|
1919 uris = [uris] |
|
1920 |
|
1921 assert isinstance(uris, (list, tuple, set)) |
|
1922 |
|
1923 self.uris = uris |
|
1924 |
|
1925 def __str__(self): |
|
1926 illegals = [] |
|
1927 |
|
1928 for u in self.uris: |
|
1929 assert isinstance(u, basestring) |
|
1930 scheme = urlparse.urlsplit(u, |
1919 allow_fragments=0)[0] |
1931 allow_fragments=0)[0] |
|
1932 illegals.append((u, scheme)) |
|
1933 |
|
1934 if len(illegals) > 1: |
|
1935 msg = _("The follwing URIs use unsupported " |
|
1936 "schemes. Supported schemes are " |
|
1937 "file://, http://, and https://.") |
|
1938 for i, s in illegals: |
|
1939 msg += _("\n %(uri)s (scheme: " |
|
1940 "%(scheme)s)") % {"uri": i, "scheme": s } |
|
1941 return msg |
|
1942 elif len(illegals) == 1: |
|
1943 i, s = illegals[0] |
1920 return _("The URI '%(uri)s' uses the unsupported " |
1944 return _("The URI '%(uri)s' uses the unsupported " |
1921 "scheme '%(scheme)s'. Supported schemes are " |
1945 "scheme '%(scheme)s'. Supported schemes are " |
1922 "file://, http://, and https://.") % { |
1946 "file://, http://, and https://.") % { |
1923 "uri": self.data, "scheme": scheme } |
1947 "uri": i, "scheme": s } |
1924 return _("The specified URI uses an unsupported scheme." |
1948 return _("The specified URI uses an unsupported scheme." |
1925 " Supported schemes are: file://, http://, and https://.") |
1949 " Supported schemes are: file://, http://, and " |
|
1950 "https://.") |
1926 |
1951 |
1927 |
1952 |
1928 class UnsupportedRepositoryURIAttribute(PublisherError): |
1953 class UnsupportedRepositoryURIAttribute(PublisherError): |
1929 """Used to indicate that the specified repository URI attribute is not |
1954 """Used to indicate that the specified repository URI attribute is not |
1930 supported for the URI's scheme.""" |
1955 supported for the URI's scheme.""" |
2971 "a version of %(exp)s, but its version was %(found)s") % { |
2996 "a version of %(exp)s, but its version was %(found)s") % { |
2972 "exp": self.expected, |
2997 "exp": self.expected, |
2973 "found": self.found, |
2998 "found": self.found, |
2974 "loc": self.loc, |
2999 "loc": self.loc, |
2975 } |
3000 } |
|
3001 |
|
3002 class InvalidOptionError(ApiException): |
|
3003 """Used to indicate an issue with verifying options passed to a certain |
|
3004 operation.""" |
|
3005 |
|
3006 GENERIC = "generic" # generic option violation |
|
3007 REPEATED = "repeated" # option repetition is not allowed |
|
3008 INCOMPAT = "incompat" # option 'a' can not be specified with option 'b' |
|
3009 REQUIRED = "required" # option 'a' requires option 'b' |
|
3010 XOR = "xor" # either option 'a' or option 'b' must be specified |
|
3011 |
|
3012 def __init__(self, err_type=GENERIC, options=[], msg=None): |
|
3013 |
|
3014 self.err_type = err_type |
|
3015 self.options = options |
|
3016 self.msg = msg |
|
3017 |
|
3018 def __str__(self): |
|
3019 |
|
3020 # In case the user provided a custom message we just take it and |
|
3021 # append the according options. |
|
3022 if self.msg is not None: |
|
3023 if self.options: |
|
3024 self.msg += ": " |
|
3025 self.msg += " ".join(self.options) |
|
3026 return self.msg |
|
3027 |
|
3028 if self.err_type == self.REPEATED: |
|
3029 assert len(self.options) == 1 |
|
3030 return _("Option '%(option)s' repeated ") % { |
|
3031 "option" : options[0]} |
|
3032 elif self.err_type == self.INCOMPAT: |
|
3033 assert len(self.options) == 2 |
|
3034 return _("The '%(op1)s' and '%(op2)s' option may " |
|
3035 "not be combined") % {"op1" : self.options[0], |
|
3036 "op2" : self.options[1]} |
|
3037 elif self.err_type == self.REQUIRED: |
|
3038 assert len(self.options) == 2 |
|
3039 return _("'%(op1)s' may only be used with " |
|
3040 "'%(op2)s'") % {"op1" : self.options[0], |
|
3041 "op2" : self.options[1]} |
|
3042 elif self.err_type == self.XOR: |
|
3043 assert len(self.options) == 2 |
|
3044 return _("Either '%(op1)s' or '%(op2)s' must be " |
|
3045 "specified") % {"op1" : self.options[0], |
|
3046 "op2" : self.options[1]} |
|
3047 else: |
|
3048 return _("invalid option(s): ") + " ".join(self.options) |
|
3049 |
|
3050 class InvalidOptionErrors(ApiException): |
|
3051 |
|
3052 def __init__(self, errors): |
|
3053 |
|
3054 self.errors = [] |
|
3055 |
|
3056 assert (isinstance(errors, list) or isinstance(errors, tuple) or |
|
3057 isinstance(errors, set) or |
|
3058 isinstance(errors, InvalidOptionError)) |
|
3059 |
|
3060 if isinstance(errors, InvalidOptionError): |
|
3061 self.errors.append(errors) |
|
3062 else: |
|
3063 self.errors = errors |
|
3064 |
|
3065 def __str__(self): |
|
3066 msgs = [] |
|
3067 for e in self.errors: |
|
3068 msgs.append(str(e)) |
|
3069 return "\n".join(msgs) |
|
3070 |
|
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 |
|
3077 |
|
3078 |
|
3079 |
|
3080 |