DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Prompt Once And ONCE ONLY For Connection (access Point) To Use

  • submit to reddit
        Simple to see what's going on here.. it just took me a while to find the API calls so thought I should share it.

Once the default access point is set, the likes of urllib will not prompt again during the running of the script.

You could take this further by e.g. writing the selected access point Id to a config file if you never want the user to be prompted again.

In PyS60 versions before 1.9.x:

import socket

In PyS60 versions 1.9.x and above:

import btsocket

The reason for the difference: As of PyS60 1.9.x the module "socket" has been renamed to "btsocket". This is because of the name clash between the PyS60 extension module and the Python(2.5.1) core module. 



Snippets Manager replied on Mon, 2008/11/24 - 7:56am

To present selection for IAP and store it: def log(a): print a class AppContext: datapath="e:\\yourappfolder" iap=0 iapObj = None canvas = None def StoreAccessPointSelection(self): file= open(self.datapath+'\\iapsel.txt','w') str=cer.dumps(self.iap) file.write(str) file.close def RetrieveAccessPointSelection(self): try: file= open(self.datapath+'\\iapsel.txt','r') self.iap = cer.loads( file.close except: self.iap=0 log(ExceptionInfo()) log("no stored iap. will prompt.") def __init__(self): self.RetrieveAccessPointSelection() appCtx = 0 appCtx = AppContext() def SelectIAP(): global appCtx while appCtx.iapObj == None: if appCtx.iap==0: try: appCtx.iap=socket.select_access_point() except: log(ExceptionInfo()) print "failed to select iap." appCtx.iap=None if appCtx.iap == None: raise RuntimeError() log("selected iap "+str(appCtx.iap)) try: appCtx.iapObj = socket.access_point(appCtx.iap) log('created access point object '+str(appCtx.iap)) except: log(ExceptionInfo()) log('failed to start access point '+str(appCtx.iap)) log('setting default access point') socket.set_default_access_point(appCtx.iapObj) appCtx.StoreAccessPointSelection() log('set default access point ok') def GetUrl(url,gufile): global appCtx SelectIAP() while 1: try: log('retrieving url '+url+' to file '+gufile) urllib.urlretrieve(url,gufile) break except: log(ExceptionInfo()) appCtx.iapObj = None appCtx.iap = 0 SelectIAP() log('retrieved url ok')