Skip to content

Commit 5150cfd

Browse files
committed
PEP8 pass.
1 parent c3a9815 commit 5150cfd

File tree

11 files changed

+196
-136
lines changed

11 files changed

+196
-136
lines changed

CHANGES.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
Change Log
22
==========
33

4-
1.0.15
5-
------
4+
1.1.0
5+
-----
66

7+
* A quick PEP8 pass on most of the codebase. Yucky. (gtaylor)
78
* Changing recommended install method to use pip + PyPi. (radlws)
89
* Updated rate_request and freight_rate_request examples for WSDL v16
910
compatibility. (foxxyz)

README.rst

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,26 @@ Python FedEx SOAP API Module
33

44
:Author: Greg Taylor
55
:License: BSD
6+
:Status: Stable
67

78
What is it?
89
-----------
910

10-
A light wrapper around FedEx's Webservice Soap API.
11-
12-
Requirements
13-
------------
14-
15-
The only dependency is the suds SOAP module, which is available at::
16-
17-
https://fedorahosted.org/suds/
18-
19-
You may also use easy_install or pip to install from PyPi::
20-
21-
pip install suds
11+
A light wrapper around FedEx's Webservice Soap API. We don't do much of any
12+
validation, but we'll help you sort through the pile of SOAP objects FedEx
13+
uses.
2214

2315
Installation
2416
------------
2517

26-
As root/admin on your machine::
27-
28-
python setup.py install
29-
30-
Pip install, bringing in all dependencies::
18+
The easiest way is via pip or easy_install::
3119

3220
pip install fedex
33-
21+
3422
Documentation
3523
-------------
3624

37-
For documentation, see the project webpage at::
38-
39-
http://code.google.com/p/python-fedex/
25+
Refer to the documentation_ for more details on the project.
4026

4127
There are also a lot of useful examples under the examples directory within
4228
this directory.
@@ -56,3 +42,5 @@ This software is licensed under the BSD License.
5642

5743
python-fedex is not authored by, endorsed by, or in any way affiliated with
5844
FedEx.
45+
46+
.. _documentation: https://pythonhosted.org/fedex/

fedex/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@
5252
our U{Google Code project<http://code.google.com/p/python-fedex/>} and enter
5353
an issue in the U{Issue Tracker<http://code.google.com/p/python-fedex/issues/list>}.
5454
"""
55-
VERSION = '1.0.15'
55+
VERSION = '1.1.0'

fedex/base_service.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,55 @@
44
common may be found here.
55
66
In 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+
910
import os
1011
import logging
12+
1113
import suds
1214
from suds.client import Client
1315

16+
1417
class 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+
2734
class 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+
3443
class FedexError(FedexBaseServiceException):
3544
"""
3645
Exception: These are generally problems with the client-provided data.
3746
"""
47+
3848
pass
3949

50+
4051
class 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+
5265
class 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

fedex/printers/unix.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
installations. By "Unix", we mean Linux, Mac OS, BSD, and various flavors
44
of Unix.
55
"""
6+
67
import binascii
78

9+
810
class DirectDevicePrinter(object):
911
"""
1012
This class pipes the label data directly through a /dev/* entry.
1113
Consequently, this is very Unix/Linux specific. It *MAY* work on Mac too.
1214
"""
15+
1316
def __init__(self, shipment, device="/dev/ttyS0"):
1417
"""
1518
Instantiates from a shipment object. You may optionally specify
@@ -19,6 +22,7 @@ def __init__(self, shipment, device="/dev/ttyS0"):
1922
@param shipment: A Fedex ProcessShipmentRequest object to pull the
2023
printed label data from.
2124
"""
25+
2226
self.device = device
2327
"""@ivar: A string with the path to the device to print to."""
2428
self.shipment = shipment
@@ -32,8 +36,11 @@ def print_label(self, package_num=None):
3236
@param package_num: 0-based index of the package to print. This is
3337
only useful for shipments with more than one package.
3438
"""
39+
3540
if package_num:
36-
packages = [self.shipment.response.CompletedShipmentDetail.CompletedPackageDetails[package_num]]
41+
packages = [
42+
self.shipment.response.CompletedShipmentDetail.CompletedPackageDetails[package_num]
43+
]
3744
else:
3845
packages = self.shipment.response.CompletedShipmentDetail.CompletedPackageDetails
3946

@@ -50,6 +57,7 @@ def _print_base64(self, base64_data):
5057
@type base64_data: L{str}
5158
@param base64_data: The base64 encoded string for the label to print.
5259
"""
60+
5361
label_file = open(self.device, "w")
5462
label_file.write(base64_data)
55-
label_file.close()
63+
label_file.close()

fedex/services/address_validation_service.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,46 @@
66
easy access. For more details on each, refer to the respective class's
77
documentation.
88
"""
9+
910
from datetime import datetime
1011
from .. base_service import FedexBaseService
1112

13+
1214
class FedexAddressValidationRequest(FedexBaseService):
1315
"""
1416
This class allows you validate anywhere from one to a hundred addresses
1517
in one go. Create AddressToValidate WSDL objects and add them to each
1618
instance of this request using add_address().
1719
"""
20+
1821
def __init__(self, config_obj, *args, **kwargs):
1922
"""
2023
@type config_obj: L{FedexConfig}
2124
@param config_obj: A valid FedexConfig object.
2225
"""
26+
2327
self._config_obj = config_obj
24-
2528
# Holds version info for the VersionId SOAP object.
26-
self._version_info = {'service_id': 'aval', 'major': '2',
27-
'intermediate': '0', 'minor': '0'}
29+
self._version_info = {
30+
'service_id': 'aval',
31+
'major': '2',
32+
'intermediate': '0',
33+
'minor': '0'
34+
}
2835

2936
self.AddressValidationOptions = None
3037
"""@ivar: Holds the AddressValidationOptions WSDL object."""
3138
self.addresses_to_validate = []
3239
"""@ivar: Holds the AddressToValidate WSDL object."""
3340
# Call the parent FedexBaseService class for basic setup work.
34-
super(FedexAddressValidationRequest, self).__init__(self._config_obj,
35-
'AddressValidationService_v2.wsdl',
36-
*args, **kwargs)
41+
super(FedexAddressValidationRequest, self).__init__(
42+
self._config_obj, 'AddressValidationService_v2.wsdl', *args, **kwargs)
3743

3844
def _prepare_wsdl_objects(self):
3945
"""
4046
Create the data structure and get it ready for the WSDL request.
4147
"""
48+
4249
# This holds some optional options for the request..
4350
self.AddressValidationOptions = self.client.factory.create('AddressValidationOptions')
4451

@@ -53,6 +60,7 @@ def _assemble_and_send_request(self):
5360
@warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(),
5461
WHICH RESIDES ON FedexBaseService AND IS INHERITED.
5562
"""
63+
5664
# We get an exception like this when specifying an IntegratorId:
5765
# suds.TypeNotFound: Type not found: 'IntegratorId'
5866
# Setting it to None does not seem to appease it.
@@ -62,14 +70,14 @@ def _assemble_and_send_request(self):
6270
self.logger.debug(self.TransactionDetail)
6371
self.logger.debug(self.VersionId)
6472
# Fire off the query.
65-
response = self.client.service.addressValidation(WebAuthenticationDetail=self.WebAuthenticationDetail,
66-
ClientDetail=self.ClientDetail,
67-
TransactionDetail=self.TransactionDetail,
68-
Version=self.VersionId,
69-
RequestTimestamp=datetime.now(),
70-
Options=self.AddressValidationOptions,
71-
AddressesToValidate=self.addresses_to_validate)
72-
return response
73+
return self.client.service.addressValidation(
74+
WebAuthenticationDetail=self.WebAuthenticationDetail,
75+
ClientDetail=self.ClientDetail,
76+
TransactionDetail=self.TransactionDetail,
77+
Version=self.VersionId,
78+
RequestTimestamp=datetime.now(),
79+
Options=self.AddressValidationOptions,
80+
AddressesToValidate=self.addresses_to_validate)
7381

7482
def add_address(self, address_item):
7583
"""
@@ -81,4 +89,5 @@ def add_address(self, address_item):
8189
this FedexAddressValidationRequest object.
8290
See examples/create_shipment.py for more details.
8391
"""
84-
self.addresses_to_validate.append(address_item)
92+
93+
self.addresses_to_validate.append(address_item)

0 commit comments

Comments
 (0)