Skip to content

Commit 64332e0

Browse files
author
srathod
committed
2 parents e59328e + f44a75c commit 64332e0

File tree

10 files changed

+3872
-3821
lines changed

10 files changed

+3872
-3821
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sudo: false
33

44
python:
55
- "2.7"
6+
- "3.4"
67
# - "pypy" Disabling pypy until travis moves to newer version, known issue with lxml crashing pypy
78

89
install:

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ Requirements
9292

9393
Run the following to get pyxb and nosetests:
9494
- pip install pyxb
95-
- pip install nosetests
96-
- pip install Magicmock
95+
- pip install unittest2
96+
- pip install nose
97+
- pip install lxml
9798

9899
Testing
99100
--------------------------------------

authorizenet/apicontractsv1.py

Lines changed: 3779 additions & 3780 deletions
Large diffs are not rendered by default.

authorizenet/apicontrollersbase.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import sys
1010
import xml.dom.minidom
1111
from pip._vendor import requests
12-
from _pyio import __metaclass__
1312
from lxml import objectify
1413

1514
from authorizenet.constants import constants
@@ -97,8 +96,8 @@ def buildrequest(self):
9796

9897
xmlRequest = self._request.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype())
9998
#remove namespaces that toxml() generates
100-
xmlRequest = xmlRequest.replace(constants.nsNamespace1, '')
101-
xmlRequest = xmlRequest.replace(constants.nsNamespace2, '')
99+
xmlRequest = xmlRequest.replace(constants.nsNamespace1, b'')
100+
xmlRequest = xmlRequest.replace(constants.nsNamespace2, b'')
102101

103102
return xmlRequest
104103

@@ -138,8 +137,8 @@ def execute(self):
138137
self._response = apicontractsv1.CreateFromDocument(self._httpResponse)
139138
#objectify code
140139
xmlResponse= self._response.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype())
141-
xmlResponse = xmlResponse.replace(constants.nsNamespace1, '')
142-
xmlResponse = xmlResponse.replace(constants.nsNamespace2, '')
140+
xmlResponse = xmlResponse.replace(constants.nsNamespace1, b'')
141+
xmlResponse = xmlResponse.replace(constants.nsNamespace2, b'')
143142
self._mainObject = objectify.fromstring(xmlResponse)
144143

145144
except Exception as objectifyexception:
@@ -148,21 +147,21 @@ def execute(self):
148147
self._response = apicontractsv1.CreateFromDocument(self._httpResponse)
149148
#objectify code
150149
xmlResponse= self._response.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype())
151-
xmlResponse = xmlResponse.replace(constants.nsNamespace1, '')
152-
xmlResponse = xmlResponse.replace(constants.nsNamespace2, '')
150+
xmlResponse = xmlResponse.replace(constants.nsNamespace1, b'')
151+
xmlResponse = xmlResponse.replace(constants.nsNamespace2, b'')
153152
self._mainObject = objectify.fromstring(xmlResponse)
154153
else:
155154
#if type(self.getresponseclass()) == type(self._response):
156155
if type(self.getresponseclass()) != type(self._mainObject):
157156
if self._response.messages.resultCode == "Error":
158-
print "Response error"
157+
logging.debug("Response error")
159158
domResponse = xml.dom.minidom.parseString(self._httpResponse)
160159
logging.debug('Received response: %s' % domResponse.toprettyxml())
161160
else:
162161
#Need to handle ErrorResponse
163162
logging.debug('Error retrieving response for request: %s' % self._request)
164163
else:
165-
print "Did not receive http response"
164+
logging.debug("Did not receive http response")
166165
return
167166

168167
def getresponse(self):

authorizenet/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class constants(object):
3838
note = ' note="Status with a capital \'S\' is obsolete."'
3939

4040
'''ns namespace 1'''
41-
nsNamespace1 = 'ns1:'
41+
nsNamespace1 = b'ns1:'
4242

4343
'''ns namespace 2'''
44-
nsNamespace2 = ':ns1'
44+
nsNamespace2 = b':ns1'
4545

4646
'''default log file name'''
4747
defaultLogFileName = "anetsdk.log"

authorizenet/utility.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
@author: krgupta
55
'''
66

7-
from ConfigParser import SafeConfigParser
8-
from ConfigParser import NoSectionError
7+
try:
8+
from ConfigParser import SafeConfigParser
9+
from ConfigParser import NoSectionError
10+
except ImportError:
11+
from configparser import SafeConfigParser
12+
from configparser import NoSectionError
13+
914
import os
1015
import sys
16+
import logging
1117
#from __future__ import print_function
1218

19+
logger = logging.getLogger(__name__)
20+
1321
class helper():
1422
__parser = "null"
1523
__propertyfilename = "null"
@@ -45,20 +53,20 @@ def getproperty(propertyname):
4553
try:
4654
helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""})
4755
except:
48-
print ("Parser could not be initialized")
56+
logger.debug("Parser could not be initialized")
4957

5058
if ('null' != helper.getparser()):
5159
try:
5260
helper.getparser().read(helper.__propertyfilename)
5361
helper.__initialized = True
5462
except:
55-
print ("Unable to load the property file")
63+
logger.debug("Unable to load the property file")
5664

5765
if (True == helper.__classinitialized()):
5866
try:
5967
stringvalue = helper.getparser().get("properties", propertyname)
6068
except:
61-
sys.stderr.write("'%s' not found\n" %propertyname )
69+
logger.debug("'%s' not found\n" %propertyname )
6270

6371
if ( "null" == stringvalue):
6472
stringvalue = os.getenv(propertyname)

script/addany.pl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#Modifying XSD to add wildcard character
66
#Adding paymentScheduleTypeInterval type to overcome pyxb's anonymous complex type issue
77

8-
$input_file = "AnetApiSchema.xsd";
9-
$intermediate_file = "IntermediateAnetOut.xsd";
10-
$output_file = "AnetApiSchemaOut.xsd";
8+
$input_file = $ARGV[0];
9+
$intermediate_file = $ARGV[1];
10+
$output_file = $ARGV[2];
1111
$inp_cmd = "dos2unix $input_file\n";
1212

1313
open(INP,"<$input_file") or die "Cannot open $input_file for reading:$!\n";
@@ -25,7 +25,7 @@
2525
}
2626
close(OUP);
2727
close(INP);
28-
print "$intermediate_file created from AnetApiSchema.xsd\n";
28+
#print "$intermediate_file created from AnetApiSchema.xsd\n"; #uncomment for debugging
2929

3030
# Using intermediate file as input
3131
open(INPUT,"<$intermediate_file") or die "Cannot open $intermediate_file for reading:$!\n";

script/generateobjectsfromxsd.sh

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
# Requires pyxb module to be installed and available in path
55

66
dt=`date '+%m/%d/%Y %H:%M:%S'`
7+
8+
AnetURL=https://apitest.authorize.net/xml/v1/schema/AnetApiSchema.xsd
9+
AnetURLPERL='https:\/\/apitest.authorize.net\/xml\/v1schema\/AnetApiSchema.xsd'
10+
LOCALXSDWITHANY=./script/AnetOut.xsd
11+
CONTRACTSDIR=authorizenet
12+
CONTRACTSFILE=apicontractsv1
13+
PYXBGENPATH=`which pyxbgen`
14+
TEMPFILE=binding
15+
TEMPDIRECTORY=./script/temp
16+
717
echo Starting pyxbgen on ${dt}
818
which python > /dev/null
919
if [ $? -eq 0 ]
@@ -32,32 +42,60 @@ else
3242
exit 1
3343
fi
3444

35-
LOCALXSDWITHANY=./script/AnetApiSchemaOut.xsd
36-
CONTRACTSDIR=authorizenet
37-
CONTRACTSFILE=apicontractsv1
38-
PYXBGENPATH=`which pyxbgen`
39-
TEMPFILE=binding
40-
41-
echo Downloading AnetAPISchema file under Script directory
42-
wget -O AnetApiSchema.xsd https://apitest.authorize.net/xml/v1/schema/AnetApiSchema.xsd
45+
which wget > /dev/null
4346
if [ $? -eq 0 ]
4447
then
45-
echo AnetAPISchema.xsd downloaded
48+
echo Found wget. Downloading AnetAPISchema file under Script directory.
49+
wget -O ./script/AnetApiSchema.xsd ${AnetURL}
50+
if [ $? -eq 0 ]
51+
then
52+
echo AnetAPISchema.xsd downloaded.
53+
else
54+
echo Unable to download AnetAPISchema.
55+
exit 1
56+
fi
4657
else
47-
echo Unable to download AnetAPISchema.
48-
exit 1
58+
echo Wget not found. Looking for Curl
59+
which curl > /dev/null
60+
if [ $? -eq 0 ]
61+
then
62+
echo Found curl. Downloading AnetAPISchema file under Script directory.
63+
curl --noproxy '*' ${AnetURL} > ./script/AnetApiSchema.xsd
64+
if [ $? -eq 0 ]
65+
then
66+
echo AnetAPISchema.xsd downloaded.
67+
else
68+
curl ${AnetURL} > ./script/AnetApiSchema.xsd
69+
if [ $? -eq 0 ]
70+
then
71+
echo AnetAPISchema.xsd downloaded.
72+
else
73+
echo Unable to download AnetAPISchema.
74+
exit 1
75+
fi
76+
fi
77+
else
78+
echo Unable to find wget and curl. Make sure either one is installed
79+
exit 1
80+
fi
4981
fi
5082

51-
echo modifying XSD using perl to support backward compatibility
52-
perl addany.pl
83+
echo Modifying XSD using perl to support backward compatibility
84+
echo Creating temporary directory
85+
mkdir -p "$TEMPDIRECTORY"
86+
87+
perl script/addany.pl script/AnetApiSchema.xsd ${TEMPDIRECTORY}/IntermediateAnetOut.xsd ${LOCALXSDWITHANY}
5388
if [ $? -eq 0 ]
5489
then
55-
echo AnetOut.xsd generated
90+
: #echo AnetOut.xsd generated #Uncomment for debugging
5691
else
5792
echo Unable to generate AnetOut.xsd
5893
exit 1
5994
fi
6095

96+
echo Deleting temporary directory
97+
rm -rf "$TEMPDIRECTORY"
98+
6199
echo Using pyxb from "${PYXBGENPATH}"
62100
if [ -e "${TEMPFILE}.py" ]; then
63101
rm ${TEMPFILE}.py
@@ -75,12 +113,13 @@ then
75113
rm "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
76114
fi
77115
mv "${TEMPFILE}.py" "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
78-
echo Bindings have been successfully generated from XSD in the file "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
116+
echo Bindings have been successfully generated from XSD in the file "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
79117
echo Old contracts have been moved to .old
80118
else
81119
echo Error generating bindings from XSD. Review the errors and rerun the script.
82120
exit 1
83121
fi
84122

85-
exit 0
123+
perl -i -pe "s/.Location\(\'(.*)\'/.Location\(\'$AnetURLPERL\'/g" ${CONTRACTSDIR}/${CONTRACTSFILE}.py
86124

125+
exit 0

tests/apitestbase.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
import random
1111
import test
1212

13-
from ConfigParser import SafeConfigParser
13+
try:
14+
from ConfigParser import SafeConfigParser
15+
except ImportError:
16+
from configparser import SafeConfigParser
17+
1418
from authorizenet import apicontractsv1, apicontrollersbase
1519
from authorizenet.utility import *
1620
#from authorizenet.apicontractsv1 import CTD_ANON

tests/testpyxb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ def testGetCustomerProfile(self):
141141
try:
142142
'''serialzing object to XML '''
143143
xmlRequest = getCustomerProfileRequest.toxml(encoding=constants.xml_encoding, element_name='getCustomerProfileRequest')
144-
xmlRequest = xmlRequest.replace(constants.nsNamespace1, '')
145-
xmlRequest = xmlRequest.replace(constants.nsNamespace2, '')
144+
xmlRequest = xmlRequest.replace(constants.nsNamespace1, b'')
145+
xmlRequest = xmlRequest.replace(constants.nsNamespace2, b'')
146146
logging.debug( "Xml Request: %s" % xmlRequest)
147147
#print( "Xml Request: %s" % xmlRequest)
148148
except Exception as ex:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy