Nonsensical results with shared names
Closed this issue · 1 comments
twm commented
I see strange results when entries share secondary names. In this example, I create a file where foo-1
and foo-2
both alias foo
, then clear foo
by name, and re-add foo-1
with a different address. The result is a file that only contains foo-2
.
$ virtualenv hosts
New python executable in hosts/bin/python
Installing setuptools, pip, wheel...cdone.
$ hosts/bin/pip install python-hosts
...
Successfully installed python-hosts-0.3.2
$ hosts/bin/python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from python_hosts import Hosts, HostsEntry
>>> hosts = Hosts(path='foo_hosts')
>>> hosts.add([HostsEntry(entry_type='ipv4', address='1.2.3.4', names=['foo-1', 'foo']),
... HostsEntry(entry_type='ipv4', address='2.3.4.5', names=['foo-2', 'foo'])])
{'ipv6_count': 0, 'ipv4_count': 2, 'invalid_count': 0, 'duplicate_count': 0, 'replaced_count': 0}
>>> hosts.write()
{'ipv4_entries_written': 2, 'ipv6_entries_written': 0, 'total_written': 2, 'comments_written': 0, 'blanks_written': 0}
>>> with open('foo_hosts') as f:
... print f.read()
...
1.2.3.4 foo-1 foo
2.3.4.5 foo-2 foo
>>> hosts = Hosts(path='foo_hosts')
>>> hosts.remove_all_matching(name='foo')
>>> hosts.add([HostsEntry(entry_type='ipv4', address='1.2.3.6', names=['foo-1', 'foo'])])
{'ipv6_count': 0, 'ipv4_count': 0, 'invalid_count': 0, 'duplicate_count': 1, 'replaced_count': 0}
>>> hosts.write()
{'ipv4_entries_written': 1, 'ipv6_entries_written': 0, 'total_written': 1, 'comments_written': 0, 'blanks_written': 0}
>>> with open('foo_hosts') as f:
... print f.read()
...
2.3.4.5 foo-2 foo
>>>
I would expect this as the result:
1.2.3.6 foo-1 foo
jonhadfield commented
Fixed with #2.