Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/boto/fps/response.py @ 0:d30785e31577 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
| author | guerler |
|---|---|
| date | Fri, 31 Jul 2020 00:18:57 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d30785e31577 |
|---|---|
| 1 # Copyright (c) 2012 Andy Davidoff http://www.disruptek.com/ | |
| 2 # Copyright (c) 2010 Jason R. Coombs http://www.jaraco.com/ | |
| 3 # Copyright (c) 2008 Chris Moyer http://coredumped.org/ | |
| 4 # Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/ | |
| 5 # | |
| 6 # Permission is hereby granted, free of charge, to any person obtaining a | |
| 7 # copy of this software and associated documentation files (the | |
| 8 # "Software"), to deal in the Software without restriction, including | |
| 9 # without limitation the rights to use, copy, modify, merge, publish, dis- | |
| 10 # tribute, sublicense, and/or sell copies of the Software, and to permit | |
| 11 # persons to whom the Software is furnished to do so, subject to the fol- | |
| 12 # lowing conditions: | |
| 13 # | |
| 14 # The above copyright notice and this permission notice shall be included | |
| 15 # in all copies or substantial portions of the Software. | |
| 16 # | |
| 17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
| 18 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | |
| 19 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | |
| 20 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
| 21 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
| 23 # IN THE SOFTWARE. | |
| 24 from decimal import Decimal | |
| 25 from boto.compat import filter, map | |
| 26 | |
| 27 | |
| 28 def ResponseFactory(action): | |
| 29 class FPSResponse(Response): | |
| 30 _action = action | |
| 31 _Result = globals().get(action + 'Result', ResponseElement) | |
| 32 | |
| 33 # due to nodes receiving their closing tags | |
| 34 def endElement(self, name, value, connection): | |
| 35 if name != action + 'Response': | |
| 36 super(FPSResponse, self).endElement(name, value, connection) | |
| 37 return FPSResponse | |
| 38 | |
| 39 | |
| 40 class ResponseElement(object): | |
| 41 def __init__(self, connection=None, name=None): | |
| 42 if connection is not None: | |
| 43 self._connection = connection | |
| 44 self._name = name or self.__class__.__name__ | |
| 45 | |
| 46 @property | |
| 47 def connection(self): | |
| 48 return self._connection | |
| 49 | |
| 50 def __repr__(self): | |
| 51 render = lambda pair: '{!s}: {!r}'.format(*pair) | |
| 52 do_show = lambda pair: not pair[0].startswith('_') | |
| 53 attrs = filter(do_show, self.__dict__.items()) | |
| 54 return '{0}({1})'.format(self.__class__.__name__, | |
| 55 ', '.join(map(render, attrs))) | |
| 56 | |
| 57 def startElement(self, name, attrs, connection): | |
| 58 return None | |
| 59 | |
| 60 # due to nodes receiving their closing tags | |
| 61 def endElement(self, name, value, connection): | |
| 62 if name != self._name: | |
| 63 setattr(self, name, value) | |
| 64 | |
| 65 | |
| 66 class Response(ResponseElement): | |
| 67 _action = 'Undefined' | |
| 68 | |
| 69 def startElement(self, name, attrs, connection): | |
| 70 if name == 'ResponseMetadata': | |
| 71 setattr(self, name, ResponseElement(name=name)) | |
| 72 elif name == self._action + 'Result': | |
| 73 setattr(self, name, self._Result(name=name)) | |
| 74 else: | |
| 75 return super(Response, self).startElement(name, attrs, connection) | |
| 76 return getattr(self, name) | |
| 77 | |
| 78 | |
| 79 class ComplexAmount(ResponseElement): | |
| 80 def __repr__(self): | |
| 81 return '{0} {1}'.format(self.CurrencyCode, self.Value) | |
| 82 | |
| 83 def __float__(self): | |
| 84 return float(self.Value) | |
| 85 | |
| 86 def __str__(self): | |
| 87 return str(self.Value) | |
| 88 | |
| 89 def startElement(self, name, attrs, connection): | |
| 90 if name not in ('CurrencyCode', 'Value'): | |
| 91 message = 'Unrecognized tag {0} in ComplexAmount'.format(name) | |
| 92 raise AssertionError(message) | |
| 93 return super(ComplexAmount, self).startElement(name, attrs, connection) | |
| 94 | |
| 95 def endElement(self, name, value, connection): | |
| 96 if name == 'Value': | |
| 97 value = Decimal(value) | |
| 98 super(ComplexAmount, self).endElement(name, value, connection) | |
| 99 | |
| 100 | |
| 101 class AmountCollection(ResponseElement): | |
| 102 def startElement(self, name, attrs, connection): | |
| 103 setattr(self, name, ComplexAmount(name=name)) | |
| 104 return getattr(self, name) | |
| 105 | |
| 106 | |
| 107 class AccountBalance(AmountCollection): | |
| 108 def startElement(self, name, attrs, connection): | |
| 109 if name == 'AvailableBalances': | |
| 110 setattr(self, name, AmountCollection(name=name)) | |
| 111 return getattr(self, name) | |
| 112 return super(AccountBalance, self).startElement(name, attrs, connection) | |
| 113 | |
| 114 | |
| 115 class GetAccountBalanceResult(ResponseElement): | |
| 116 def startElement(self, name, attrs, connection): | |
| 117 if name == 'AccountBalance': | |
| 118 setattr(self, name, AccountBalance(name=name)) | |
| 119 return getattr(self, name) | |
| 120 return super(GetAccountBalanceResult, self).startElement(name, attrs, | |
| 121 connection) | |
| 122 | |
| 123 | |
| 124 class GetTotalPrepaidLiabilityResult(ResponseElement): | |
| 125 def startElement(self, name, attrs, connection): | |
| 126 if name == 'OutstandingPrepaidLiability': | |
| 127 setattr(self, name, AmountCollection(name=name)) | |
| 128 return getattr(self, name) | |
| 129 return super(GetTotalPrepaidLiabilityResult, self).startElement(name, | |
| 130 attrs, connection) | |
| 131 | |
| 132 | |
| 133 class GetPrepaidBalanceResult(ResponseElement): | |
| 134 def startElement(self, name, attrs, connection): | |
| 135 if name == 'PrepaidBalance': | |
| 136 setattr(self, name, AmountCollection(name=name)) | |
| 137 return getattr(self, name) | |
| 138 return super(GetPrepaidBalanceResult, self).startElement(name, attrs, | |
| 139 connection) | |
| 140 | |
| 141 | |
| 142 class GetOutstandingDebtBalanceResult(ResponseElement): | |
| 143 def startElement(self, name, attrs, connection): | |
| 144 if name == 'OutstandingDebt': | |
| 145 setattr(self, name, AmountCollection(name=name)) | |
| 146 return getattr(self, name) | |
| 147 return super(GetOutstandingDebtBalanceResult, self).startElement(name, | |
| 148 attrs, connection) | |
| 149 | |
| 150 | |
| 151 class TransactionPart(ResponseElement): | |
| 152 def startElement(self, name, attrs, connection): | |
| 153 if name == 'FeesPaid': | |
| 154 setattr(self, name, ComplexAmount(name=name)) | |
| 155 return getattr(self, name) | |
| 156 return super(TransactionPart, self).startElement(name, attrs, | |
| 157 connection) | |
| 158 | |
| 159 | |
| 160 class Transaction(ResponseElement): | |
| 161 def __init__(self, *args, **kw): | |
| 162 self.TransactionPart = [] | |
| 163 super(Transaction, self).__init__(*args, **kw) | |
| 164 | |
| 165 def startElement(self, name, attrs, connection): | |
| 166 if name == 'TransactionPart': | |
| 167 getattr(self, name).append(TransactionPart(name=name)) | |
| 168 return getattr(self, name)[-1] | |
| 169 if name in ('TransactionAmount', 'FPSFees', 'Balance'): | |
| 170 setattr(self, name, ComplexAmount(name=name)) | |
| 171 return getattr(self, name) | |
| 172 return super(Transaction, self).startElement(name, attrs, connection) | |
| 173 | |
| 174 | |
| 175 class GetAccountActivityResult(ResponseElement): | |
| 176 def __init__(self, *args, **kw): | |
| 177 self.Transaction = [] | |
| 178 super(GetAccountActivityResult, self).__init__(*args, **kw) | |
| 179 | |
| 180 def startElement(self, name, attrs, connection): | |
| 181 if name == 'Transaction': | |
| 182 getattr(self, name).append(Transaction(name=name)) | |
| 183 return getattr(self, name)[-1] | |
| 184 return super(GetAccountActivityResult, self).startElement(name, attrs, | |
| 185 connection) | |
| 186 | |
| 187 | |
| 188 class GetTransactionResult(ResponseElement): | |
| 189 def startElement(self, name, attrs, connection): | |
| 190 if name == 'Transaction': | |
| 191 setattr(self, name, Transaction(name=name)) | |
| 192 return getattr(self, name) | |
| 193 return super(GetTransactionResult, self).startElement(name, attrs, | |
| 194 connection) | |
| 195 | |
| 196 | |
| 197 class GetTokensResult(ResponseElement): | |
| 198 def __init__(self, *args, **kw): | |
| 199 self.Token = [] | |
| 200 super(GetTokensResult, self).__init__(*args, **kw) | |
| 201 | |
| 202 def startElement(self, name, attrs, connection): | |
| 203 if name == 'Token': | |
| 204 getattr(self, name).append(ResponseElement(name=name)) | |
| 205 return getattr(self, name)[-1] | |
| 206 return super(GetTokensResult, self).startElement(name, attrs, | |
| 207 connection) |
