Skip to content

Commit 80dba9d

Browse files
committed
strict order of address fields
1 parent 6d4c3e7 commit 80dba9d

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test: venv
2121
PYTHONPATH=./src ./venv/bin/pytest -vv --color=yes --capture=no --log-cli-level=DEBUG ./tests
2222

2323
test/%:
24-
PYTHONPATH=./src ./venv/bin/pytest -vv $*
24+
PYTHONPATH=./src ./venv/bin/pytest -vvv $*
2525

2626
rabbitmq_server_dev:
2727
@echo "Starting RabbitMQ server, admin dashboard is available here: http://127.0.0.1:15672"

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup_params = dict(
44
name='epp-python-client',
5-
version='0.0.18',
5+
version='0.0.19',
66
author='Veselin Penev',
77
author_email='[email protected]',
88
packages=find_packages(where='src'),

src/epp/commands/contact.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@
5959
<create>
6060
<contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
6161
<contact:id>%(contact_id)s</contact:id>
62-
%(contact_fields)s
6362
%(postal_infos)s
64-
%(auth_info)s</contact:create>
63+
%(contact_fields)s
64+
%(auth_info)s
65+
</contact:create>
6566
</create>
6667
<clTRID>%(cltrid)s</clTRID>
6768
</command>
@@ -75,9 +76,10 @@
7576
<contact:update xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
7677
<contact:id>%(contact_id)s</contact:id>
7778
<contact:chg>
78-
%(contact_fields)s
7979
%(postal_infos)s
80-
%(auth_info)s</contact:chg>
80+
%(contact_fields)s
81+
%(auth_info)s
82+
</contact:chg>
8183
</contact:update>
8284
</update>
8385
<clTRID>%(cltrid)s</clTRID>

src/epp/epp_client.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ def int_from_net(data, format_32):
5555
def int_to_net(value, format_32):
5656
return struct.pack(format_32, value)
5757

58+
59+
def sort_address_fields(fields):
60+
weights = {
61+
"street": 100,
62+
"city": 90,
63+
"sp": 80,
64+
"pc": 70,
65+
"cc": 60,
66+
}
67+
return sorted(fields, key=lambda field: -weights.get(field[0], 10))
68+
5869
#------------------------------------------------------------------------------
5970

6071
class EPPConnectionAlreadyClosedError(Exception):
@@ -382,7 +393,7 @@ def contact_create(self, contact_id, voice=None, fax=None, email=None, contacts=
382393
commands.contact.field3 % dict(
383394
field=afield,
384395
value=', '.join(avalue) if isinstance(avalue, list) else avalue,
385-
) for (afield, avalue) in cont['address'].items() if avalue
396+
) for (afield, avalue) in sort_address_fields(cont['address'].items()) if avalue
386397
])
387398
) for cont in contacts
388399
]),
@@ -411,7 +422,7 @@ def contact_update(self, contact_id, voice=None, fax=None, email=None, contacts=
411422
commands.contact.field4 % dict(
412423
field=afield,
413424
value=', '.join(avalue) if isinstance(avalue, list) else avalue,
414-
) for (afield, avalue) in cont['address'].items() if avalue
425+
) for (afield, avalue) in sort_address_fields(cont['address'].items()) if avalue
415426
])
416427
) for cont in contacts
417428
]),

tests/epp/test_rpc_server.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -442,18 +442,15 @@ def test_cmd_contact_create(self):
442442
<create>
443443
<contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
444444
<contact:id>epp_id_new_123</contact:id>
445-
<contact:voice>+1234567890</contact:voice>
446-
<contact:fax>0987654321</contact:fax>
447-
<contact:email>[email protected]</contact:email>
448445
<contact:postalInfo type="int">
449446
<contact:name>Tester</contact:name>
450447
<contact:org>TestingCorp</contact:org>
451448
<contact:addr>
452449
<contact:street>Street, 1234</contact:street>
453450
<contact:city>TrialTown</contact:city>
454451
<contact:sp>North Side</contact:sp>
455-
<contact:cc>AI</contact:cc>
456452
<contact:pc>1234AB</contact:pc>
453+
<contact:cc>AI</contact:cc>
457454
</contact:addr>
458455
</contact:postalInfo>
459456
<contact:postalInfo type="loc">
@@ -463,11 +460,15 @@ def test_cmd_contact_create(self):
463460
<contact:street>Street, 1234</contact:street>
464461
<contact:city>TrialTown</contact:city>
465462
<contact:sp>North Side</contact:sp>
466-
<contact:cc>AI</contact:cc>
467463
<contact:pc>1234AB</contact:pc>
464+
<contact:cc>AI</contact:cc>
468465
</contact:addr>
469466
</contact:postalInfo>
467+
<contact:voice>+1234567890</contact:voice>
468+
<contact:fax>0987654321</contact:fax>
469+
<contact:email>[email protected]</contact:email>
470470
<contact:authInfo><contact:pw>123456</contact:pw></contact:authInfo>
471+
471472
</contact:create>
472473
</create>
473474
<clTRID>c5bc8f94103f1a47019a09049dff5aec</clTRID>

0 commit comments

Comments
 (0)