Example #1
0
    def __init__(self, reactor, params):
        Entity.__init__(self)

        self.reactor = reactor
        self.params = params

        # Initial property values
        self.address = Address(params.host, params.port)
        if params.node_id:
            self.id_= safe_str(params.node_id)
        else:
            self.id_ = self.CreateId(params)
        if params.pos_x or params.pos_y:
            self.position = Position((params.pos_x, params.pos_y, 0))
        else:
            self.position = self.RandomPosition()
        if params.pseudo:
            self.pseudo = safe_unicode(params.pseudo)
        else:
            self.pseudo = self.RandomPseudo()
        print "Creating node '%s'" % self.id_

        # Call parent class constructor

        # Dummy test data
        self.languages = ['fr', 'en']
Example #2
0
 def UpdateMeta(self, pseudo=None, languages=None, services=None):
     """
     Update metadata from a pseudo, a list of languages and a list of services.
     """
     if pseudo is not None:
         self.pseudo = safe_unicode(pseudo)
     if languages is not None:
         self.languages = languages
     if services is not None:
         self.UpdateServices(services)
 def LoadSection(self, section_name, fields):
     """
     Load the given config options from the given section.
     """
     p = self._config_parser
     for k, (var, cons, default) in fields.items():
         # For each requested field, get the corresponding value
         # from the config file or use the default value
         if p.has_option(section_name, k):
             v = cons(safe_unicode(p.get(section_name, k), CHARSET))
         else:
             v = default
         setattr(self, var, v)
     for var, v in self._options.__dict__.items():
         # For each command-line option that is not None or empty,
         # override the config file value
         if v or not hasattr(self, var):
             if isinstance(v, str):
                 v = safe_unicode(v, CHARSET)
             setattr(self, var, v)
Example #4
0
 def RandomPseudo(self):
     """
     Returns a random pseudo according to other node properties
     (e.g. position).
     """
     x, y = self.position.GetXY()
     a = x * (10.0 / self.world_size)
     b = y * (10.0 / self.world_size)
     c = random.choice(self.home_translations)
     pseudo = '%s%s-%s' % (chr(int(a) + ord('a')), str(int(b) + 1), c)
     return safe_unicode(pseudo)
Example #5
0
    def __init__(self, id_="", position=Position(), awareness_radius=0, pseudo=u"", address=None):
        """
        Create a new Entity and keep information about it.
        """
        # position
        self.position = position
        self.awareness_radius = awareness_radius

        # public address of this node, address= IP+port
        self.address = address

        # id of this node
        self.id_ = id_

        # Metadata
        self.pseudo = safe_unicode(pseudo)
        self.services = {}
        self.languages = []
        self.services_enabled = True
 def __init__(self, text, font=None):
     self.font = font or wx.SWISS_FONT
     #~ print repr(text), type(text) #, '=>', repr(self.text)
     self.text = safe_unicode(text)
     self.size = None
        else:
            s.append("%s;d=%s" % (service.id_, service.type))
    return ", ".join(s)

_from_string = {
    ARG_ACCEPT_LANGUAGES:   _accept_languages_from_string,
    ARG_ACCEPT_SERVICES:    _accept_services_from_string,
    ARG_ADDRESS:            (lambda s: Address.FromString(s)),
    ARG_AWARENESS_RADIUS:   float,
    ARG_BEST_DISTANCE:      float,
    ARG_CLOCKWISE:          (lambda c: int(c) > 0),
    ARG_HOLD_TIME:          int,
    ARG_ID:                 intern,
    ARG_NEEDS_MIDDLEMAN:    (lambda s: s == "yes"),
    ARG_POSITION:           (lambda s: Position.FromString(s)),
    ARG_PSEUDO:             (lambda s: safe_unicode(s, CHARSET)),
    ARG_SEND_DETECTS:       (lambda s: s == 'now'),
    ARG_SERVICE_ID:         str,
    ARG_SERVICE_ADDRESS:    (lambda a: str(a)),
    ARG_VERSION:            (lambda v: float(v)),
}

_to_string = {
    ARG_ACCEPT_LANGUAGES:   _accept_languages_to_string,
    ARG_ACCEPT_SERVICES:    _accept_services_to_string,
    ARG_ADDRESS:            (lambda a: a.ToString()),
    ARG_AWARENESS_RADIUS:   (lambda x: str(long(x))),
    ARG_BEST_DISTANCE:      (lambda x: str(long(x))),
    ARG_CLOCKWISE:          (lambda c: c and "+1" or "-1"),
    ARG_HOLD_TIME:          str,
    ARG_ID:                 str,