def add_contact(self, contact):
     """
     Adds C{contact} to the SIM and returns the index where was stored
     
     @rtype: C{defer.Deferred}
     """ 
     name = from_u(contact.get_name())
     
     if 'UCS2' in self.device.sim.charset:
         name = pack_ucs2_bytes(name)
     
     # common arguments for both operations (name and number)
     args = [name, from_u(contact.get_number())]
     
     if contact.index:
         # contact.index is set, user probably wants to overwrite an
         # existing contact
         args.append(contact.index)
         d = super(SIMCardConnAdapter, self).add_contact(*args)
         d.addCallback(lambda _: contact.index)
         return d
     
     # contact.index is not set, this means that we need to obtain the
     # first slot free on the phonebook and then add the contact
     def get_next_id_cb(index):
         args.append(index)
         d2 = super(SIMCardConnAdapter, self).add_contact(*args)
         # now we just fake add_contact's response and we return the index
         d2.addCallback(lambda _: index)
         return d2
     
     d = super(SIMCardConnAdapter, self).get_next_contact_id()
     d.addCallback(get_next_id_cb)
     return d
示例#2
0
    def add_contact(self, contact):
        """
        Adds C{contact} to the SIM and returns the index where was stored
        
        @rtype: C{defer.Deferred}
        """
        name = from_u(contact.get_name())

        if 'UCS2' in self.device.sim.charset:
            name = pack_ucs2_bytes(name)

        # common arguments for both operations (name and number)
        args = [name, from_u(contact.get_number())]

        if contact.index:
            # contact.index is set, user probably wants to overwrite an
            # existing contact
            args.append(contact.index)
            d = super(SIMCardConnAdapter, self).add_contact(*args)
            d.addCallback(lambda _: contact.index)
            return d

        # contact.index is not set, this means that we need to obtain the
        # first slot free on the phonebook and then add the contact
        def get_next_id_cb(index):
            args.append(index)
            d2 = super(SIMCardConnAdapter, self).add_contact(*args)
            # now we just fake add_contact's response and we return the index
            d2.addCallback(lambda _: index)
            return d2

        d = super(SIMCardConnAdapter, self).get_next_contact_id()
        d.addCallback(get_next_id_cb)
        return d
示例#3
0
    def add_contact(self, contact):
        """
        Adds C{contact} to the SIM and returns the index where was stored

        @rtype: C{defer.Deferred}
        """
        def hw_add_contact(name, number, index):
            """
            Adds a contact to the SIM card
            """
            try:  # are all ascii chars
                name.encode('ascii')
                raw = 0
            except:  # write in TS31.101 type 80 raw format
                name = '80' + pack_ucs2_bytes(name) + 'FF'
                raw = 1

            category = number.startswith('+') and 145 or 129
            args = (index, number, category, name, raw)
            cmd = ATCmd('AT^CPBW=%d,"%s",%d,"%s",%d' % args,
                        name='add_contact')
            return self.queue_at_cmd(cmd)

        name = from_u(contact.get_name())

        # common arguments for both operations (name and number)
        args = [name, from_u(contact.get_number())]

        if contact.index:
            # contact.index is set, user probably wants to overwrite an
            # existing contact
            args.append(contact.index)
            d = hw_add_contact(*args)
            d.addCallback(lambda _: contact.index)
            return d

        # contact.index is not set, this means that we need to obtain the
        # first slot free on the phonebook and then add the contact
        def get_next_id_cb(index):
            args.append(index)
            d2 = hw_add_contact(*args)
            # now we just fake add_contact's response and we return the index
            d2.addCallback(lambda _: index)
            return d2

        d = super(HuaweiAdapter, self).get_next_contact_id()
        d.addCallback(get_next_id_cb)
        return d
    def add_contact(self, contact):
        """
        Adds C{contact} to the SIM and returns the index where was stored

        @rtype: C{defer.Deferred}
        """

        def hw_add_contact(name, number, index):
            """
            Adds a contact to the SIM card
            """
            try:     # are all ascii chars
                name.encode('ascii')
                raw = 0
            except:  # write in TS31.101 type 80 raw format
                name = '80' + pack_ucs2_bytes(name) + 'FF'
                raw = 1

            category = number.startswith('+') and 145 or 129
            args = (index, number, category, name, raw)
            cmd = ATCmd('AT^CPBW=%d,"%s",%d,"%s",%d' % args, name='add_contact')
            return self.queue_at_cmd(cmd)

        name = from_u(contact.get_name())

        # common arguments for both operations (name and number)
        args = [name, from_u(contact.get_number())]

        if contact.index:
            # contact.index is set, user probably wants to overwrite an
            # existing contact
            args.append(contact.index)
            d = hw_add_contact(*args)
            d.addCallback(lambda _: contact.index)
            return d

        # contact.index is not set, this means that we need to obtain the
        # first slot free on the phonebook and then add the contact
        def get_next_id_cb(index):
            args.append(index)
            d2 = hw_add_contact(*args)
            # now we just fake add_contact's response and we return the index
            d2.addCallback(lambda _: index)
            return d2

        d = super(HuaweiAdapter, self).get_next_contact_id()
        d.addCallback(get_next_id_cb)
        return d
示例#5
0
 def __init__(self, number, text, smsc=None, validity=None, **kwds):
     super(ShortMessageSubmit, self).__init__(number, text, **kwds)
     self.address = GSMAddress(from_u(number))
     self.smsc = smsc
     self.encoding = None
     self.user_data = None
     self.__set_text(text)
     self.validity = None
     self._set_validity(validity)
示例#6
0
 def __init__(self, number, text, smsc=None, validity=None, **kwds):
     super(ShortMessageSubmit, self).__init__(number, text, **kwds)
     self.address = GSMAddress(from_u(number))
     self.smsc = smsc
     self.encoding = None
     self.user_data = None
     self.__set_text(text)
     self.validity = None
     self._set_validity(validity)
示例#7
0
 def get_smsc_cb(response):
     try:
         smsc = response[0].group('smsc')
         if not smsc.startswith('+'):
             if check_if_ucs2(smsc):
                 # the smsc is in UCS2 format
                 smsc = from_u(unpack_ucs2_bytes(smsc))
 
         return smsc
     except KeyError, e:
         raise ex.CMEErrorNotFound()