@@ 371,12 371,23 @@ class InPost(Carrier):
class DHL(Carrier):
DISPLAYNAME = 'DHL'
+ @classmethod
+ def identify(cls, code):
+ # DHL Parcel
+ if code.startswith('3S') or code.startswith('JVGL'):
+ if len(code) == 14:
+ return True
+
+ # DHL Express codes are very non-unique. Described as 10 digit numerical
+ return False
+
def _addr(self, payload):
res = Address()
if 'countryCode' in payload['address']:
res.country = payload['address']['countryCode']
return res
+ @classmethod
def get_requirements(cls, code):
return [
('apikey', 'DHL API key', 'text'),
@@ 427,10 438,10 @@ class DHL(Carrier):
e = PackageEvent(stamp, location, event['status'])
result.events.append(e)
- if 'address' in payload['origin']:
+ if 'origin' in payload and 'address' in payload['origin']:
result.origin = self._addr(payload['origin'])
- if 'address' in payload['destination']:
+ if 'destination' in payload and 'address' in payload['destination']:
result.destination = self._addr(payload['destination'])
return result