44common may be found here.
55
66In particular, the L{FedexBaseService} class handles most of the basic,
7- repetetive setup work that most requests do.
7+ repetitive setup work that most requests do.
88"""
9+
910import os
1011import logging
12+
1113import suds
1214from suds .client import Client
1315
16+
1417class FedexBaseServiceException (Exception ):
1518 """
1619 Exception: Serves as the base exception that other service-related
1720 exception objects are sub-classed from.
1821 """
22+
1923 def __init__ (self , error_code , value ):
2024 self .error_code = error_code
2125 self .value = value
26+
2227 def __unicode__ (self ):
2328 return "%s (Error code: %s)" % (repr (self .value ), self .error_code )
29+
2430 def __str__ (self ):
2531 return self .__unicode__ ()
2632
33+
2734class FedexFailure (FedexBaseServiceException ):
2835 """
2936 Exception: The request could not be handled at this time. This is generally
3037 a server problem.
3138 """
39+
3240 pass
3341
42+
3443class FedexError (FedexBaseServiceException ):
3544 """
3645 Exception: These are generally problems with the client-provided data.
3746 """
47+
3848 pass
3949
50+
4051class SchemaValidationError (FedexBaseServiceException ):
4152 """
4253 Exception: There is probably a problem in the data you provided.
4354 """
55+
4456 def __init__ (self , fault ):
4557 self .error_code = - 1
4658 self .value = "suds encountered an error validating your data against this service's WSDL schema. Please double-check for missing or invalid values, filling all required fields."
@@ -49,6 +61,7 @@ def __init__(self, fault):
4961 except AttributeError :
5062 pass
5163
64+
5265class FedexBaseService (object ):
5366 """
5467 This class is the master class for all Fedex request objects. It gets all
@@ -59,6 +72,7 @@ class FedexBaseService(object):
5972 @note: This object should never be used directly, use one of the included
6073 sub-classes.
6174 """
75+
6276 def __init__ (self , config_obj , wsdl_name , * args , ** kwargs ):
6377 """
6478 This constructor should only be called by children of the class. As is
@@ -70,6 +84,7 @@ def __init__(self, config_obj, wsdl_name, *args, **kwargs):
7084 differentiate this transaction from others. This value will be
7185 returned with the response from Fedex.
7286 """
87+
7388 self .logger = logging .getLogger ('fedex' )
7489 """@ivar: Python logger instance with name 'fedex'."""
7590 self .config_obj = config_obj
@@ -87,8 +102,6 @@ def __init__(self, config_obj, wsdl_name, *args, **kwargs):
87102
88103 self .client = Client ('file:///%s' % self .wsdl_path .lstrip ('/' ))
89104
90- #print self.client
91-
92105 self .VersionId = None
93106 """@ivar: Holds details on the version numbers of the WSDL."""
94107 self .WebAuthenticationDetail = None
@@ -114,6 +127,7 @@ def __set_web_authentication_detail(self):
114127 Sets up the WebAuthenticationDetail node. This is required for all
115128 requests.
116129 """
130+
117131 # Start of the authentication stuff.
118132 WebAuthenticationCredential = self .client .factory .create ('WebAuthenticationCredential' )
119133 WebAuthenticationCredential .Key = self .config_obj .key
@@ -129,6 +143,7 @@ def __set_client_detail(self):
129143 Sets up the ClientDetail node, which is required for all shipping
130144 related requests.
131145 """
146+
132147 ClientDetail = self .client .factory .create ('ClientDetail' )
133148 ClientDetail .AccountNumber = self .config_obj .account_number
134149 ClientDetail .MeterNumber = self .config_obj .meter_number
@@ -141,6 +156,7 @@ def __set_transaction_detail(self, *args, **kwargs):
141156 """
142157 Checks kwargs for 'customer_transaction_id' and sets it if present.
143158 """
159+
144160 customer_transaction_id = kwargs .get ('customer_transaction_id' , False )
145161 if customer_transaction_id :
146162 TransactionDetail = self .client .factory .create ('TransactionDetail' )
@@ -152,6 +168,7 @@ def __set_version_id(self):
152168 """
153169 Pulles the versioning info for the request from the child request.
154170 """
171+
155172 VersionId = self .client .factory .create ('VersionId' )
156173 VersionId .ServiceId = self ._version_info ['service_id' ]
157174 VersionId .Major = self ._version_info ['major' ]
@@ -166,13 +183,15 @@ def __prepare_wsdl_objects(self):
166183 any of the required WSDL objects so the user can just print their
167184 __str__() methods and see what they need to fill in.
168185 """
186+
169187 pass
170188
171189 def __check_response_for_fedex_error (self ):
172190 """
173191 This checks the response for general Fedex errors that aren't related
174192 to any one WSDL.
175193 """
194+
176195 if self .response .HighestSeverity == "FAILURE" :
177196 for notification in self .response .Notifications :
178197 if notification .Severity == "FAILURE" :
@@ -185,6 +204,7 @@ def _check_response_for_request_errors(self):
185204 specific to that module. For example, invalid tracking numbers in
186205 a Tracking request.
187206 """
207+
188208 if self .response .HighestSeverity == "ERROR" :
189209 for notification in self .response .Notifications :
190210 if notification .Severity == "ERROR" :
@@ -195,6 +215,7 @@ def create_wsdl_object_of_type(self, type_name):
195215 """
196216 Creates and returns a WSDL object of the specified type.
197217 """
218+
198219 return self .client .factory .create (type_name )
199220
200221 def send_request (self , send_function = None ):
@@ -206,6 +227,7 @@ def send_request(self, send_function=None):
206227 allows for overriding the default function in cases such as
207228 validation requests.
208229 """
230+
209231 # Send the request and get the response back.
210232 try :
211233 # If the user has overridden the send function, use theirs
0 commit comments