Last change
on this file since 99 was 96, checked in by Bart Vastenhouw, 2 years ago |
Fixed small issues in domaineditor.
|
File size:
1.3 KB
|
Rev | Line | |
---|
[96] | 1 | import re
|
---|
| 2 | from pyson.JsonValue import JsonValue
|
---|
| 3 |
|
---|
| 4 | class PartyId:
|
---|
| 5 | '''
|
---|
| 6 | Unique ID of a party in a negotiation. The name should start with a short
|
---|
| 7 | string indicating the party (eg, the party name plus some machine
|
---|
| 8 | identifier), optionally followed by an "_", and more characters to make the
|
---|
| 9 | partyid unique. We require the name and "-" so that the string up to the
|
---|
| 10 | first "-" can be used to determine between sessions which opponents are
|
---|
| 11 | instances of the same class.
|
---|
| 12 | <h2>Note</h2> Normally, negotiation parties should not create new Party IDs
|
---|
| 13 | as all needed IDs should be provided by the protocol.
|
---|
| 14 | '''
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | def __init__(self,name:str):
|
---|
| 18 | '''
|
---|
| 19 | @param name a simple name, starting with letter, followed by zero or more
|
---|
| 20 | letters, digits or _.
|
---|
| 21 |
|
---|
| 22 | '''
|
---|
| 23 | if name == None or not re.fullmatch("[a-zA-Z]\\w*", name):
|
---|
| 24 | raise ValueError("name '" + name
|
---|
| 25 | + "' is not a letter followed by zero or more word characters (letter, digit or _)");
|
---|
| 26 | self._name = name;
|
---|
| 27 |
|
---|
| 28 | @JsonValue()
|
---|
| 29 | def getName(self) -> str:
|
---|
| 30 | return self._name
|
---|
| 31 |
|
---|
| 32 | def __repr__(self):
|
---|
| 33 | return self._name
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | def __eq__(self, other):
|
---|
| 37 | return super().__eq__(other) and isinstance(other, self.__class__) and \
|
---|
| 38 | self._name==other._name
|
---|
| 39 |
|
---|
| 40 | def __hash__(self):
|
---|
| 41 | '''
|
---|
| 42 | support for using this in dict etc
|
---|
| 43 | '''
|
---|
| 44 | return hash(self._name)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.