def set_ap(): apid = config.get("internet","apid",None) if apid == None: socket.set_default_access_point(None) else: ap = socket.access_point(apid) socket.set_default_access_point(ap)
def set_accesspoint(): global _SETTINGS_ACCESPOINT apid = socket.select_access_point() if appuifw.query(u"Set as default access point", "query") == True: set_setting(_SETTINGS_ACCESPOINT, repr(apid)) apo = socket.access_point(apid) socket.set_default_access_point(apo)
def startInternet(self): if not self.ip: import sys import socket if sys.platform == 'symbian_s60': self.feedback(u'Prepare internet:please wait...') aps = [ap['name'] for ap in socket.access_points()] aps.sort() time_taken=0 while time_taken < 1: started = time.time() apid = appuifw.selection_list(aps,1) time_taken = time.time() - started if apid == None: return None self.feedback(u'Prepare internet:set access point') socket.set_default_access_point(aps[apid]) else: import socket self.ip = 'some ip' #one time socket, for just finding out our ip s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #anonymity issue here s.connect(('www.google.com',80)) self.ip = s.getsockname()[0] return True
def _select_access_point(self, apid = None): """ Shortcut for socket.select_access_point() TODO: save selected access point to the config TODO: allow user to change access point later """ if apid is not None: self.apid = apid else: access_points = socket.access_points() sort_key = "iapid" decorated = [(dict_[sort_key], dict_) for dict_ in access_points] decorated.sort() access_points = [dict_ for (key, dict_) in decorated] ap_names = [dict_["name"] for dict_ in access_points] ap_ids = [dict_["iapid"] for dict_ in access_points] selected = appuifw.selection_list(ap_names, search_field=1) #print selected, ap_names[selected], ap_ids[selected] if selected is not None: self.apid = ap_ids[selected] if self.apid: self.apo = socket.access_point(self.apid) socket.set_default_access_point(self.apo) self.config["apid"] = self.apid self.save_config() self._update_menu() return self.apid
def get_accespoint(): global _SETTINGS_ACCESPOINT apid = get_setting(_SETTINGS_ACCESPOINT) if not apid == None: apo = socket.access_point(int(apid)) socket.set_default_access_point(apo) else: set_accesspoint()
def get_accesspoint(self): config = self.get_config() if not config.get('apid') == None : apid = config.get('apid') apo = socket.access_point(apid) socket.set_default_access_point(apo) else: self.set_accesspoint()
def ap(): #print "set default access- point" #print config["ap"] ap_id = socket.select_access_point() apo = socket.access_point(ap_id) socket.set_default_access_point(apo) config["ap"] = ap_id save_config()
def set_accesspoint(): apid = socket.select_access_point() if appuifw.query(u"Set as default access point", "query") == True: f = open('e:\\apid.txt', 'w') f.write(repr(apid)) f.close() appuifw.note(u"Saved default access point ", "info") apo = socket.access_point(apid) socket.set_default_access_point(apo)
def set_accesspoint(self): apid = socket.select_access_point() if appuifw.query(u"Set as default access point","query") == True: appuifw.note(u"Saved default access point ", "info") config = self.get_config() config['apid'] = apid self.save_config(config) apo = socket.access_point(apid) socket.set_default_access_point(apo)
def __init__(self, servport = NETBIOS_NS_PORT, apn=None): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) if not apn: apn = socket.select_access_point() e32.ao_yield() if not apn: raise NetBIOSError, 'Please select a AP' ap = socket.access_point(apn) socket.set_default_access_point(ap) ap.start()
def ok(): try: file = open('e:\\system\\apps\\geturl\\set.ini', 'r') poin = file.read() file.close() socket.set_default_access_point(socket.access_point(int(poin))) except: pass url = text.get() urln = urllib.urlopen(url) ur = urln.geturl() text.set(ru(ur))
def set_ap(): val = appuifw.query(u"Access point name:", 'text') if val is not None: try: socket.set_default_access_point(unicode(val)) except: appuifw.note(u"If you passed an invalid access point then the" + " Test Passed else it Failed.") raise else: appuifw.note(u"Default access point set. Test passed. " + "Run ConnectToTheInternet test to verify.")
def start(self): try: self.apid = socket.select_access_point() self.ap = socket.access_point(self.apid) socket.set_default_access_point(self.ap) id = appuifw.query(u'DOUGA-ID', 'text') if not id: self.exit() download(unicode(id).encode('utf-8')) except Exception, e: traceback.print_exc()
def set_ap(self): from socket import access_points, access_point, select_access_point, set_default_access_point apid = [k for k in self.aps if k['name'] == u'WAP over GPRS'] if apid: #找的默认的接入点 self.apid = apid[0] self.ap = access_point(self.apid['iapid']) self.setting[6] = unicode(self.aps.index(self.apid)) set_default_access_point(self.ap) else: #没找到就选一个 self.apid_i = select_access_point() self.apid = [k for k in self.aps if k['iapid'] == self.apid_i][0] self.ap = access_point(self.apid['iapid']) self.setting[6] = unicode(self.aps.index(self.apid)) set_default_access_point(self.ap)
def restoreSettings(self): try: f = open("c:\\translate.cfg") self.source, self.target, accessPointId = f.read().split(",") f.close() self.accessPointId = int(accessPointId) except: self.source = "en" self.target = "da" self.accessPointId = "" try: self.accessPoint = socket.access_point(self.accessPointId) socket.set_default_access_point(self.accessPoint) except: pass
def start(self): if self._access_point_started: return if not self._default_access_point: confirm = appuifw.query(u"This operation requires data transfer. Confirm?", 'query') if not confirm: return apid = socket.select_access_point() # pylint: disable-msg=E1101 if not apid: return self._default_access_point = socket.access_point(apid) # pylint: disable-msg=E1101 socket.set_default_access_point(self._default_access_point) # pylint: disable-msg=E1101 self._default_access_point.start() self._access_point_started = True
def __init__(self, inet_mode): self.server_host = "http://test.talking-points.org" self.inet_mode = inet_mode self.mac_tpid_mapping = {'00194fa4e262': 33, '000272c008cb': 31, '0010c65e9224': 34} if self.inet_mode == "online": ap_id = socket.select_access_point() apo = socket.access_point(ap_id) socket.set_default_access_point(apo) # make sure path exists if e32.in_emulator(): self.dir = u"c:\\python\\tp_offline" else: self.dir = u"e:\\python\\tp_offline" if not os.path.exists(self.dir): os.makedirs(self.dir)
def select_default_access_point(): """ Select the default access point. Return True if the selection was done or False if not. """ aps = socket.access_points() if not aps: note(u"No access points available", "error") return False ap_labels = [x["name"] for x in aps] item = popup_menu(ap_labels, u"Access points:") if item is None: return False socket.set_default_access_point(aps[item]["name"]) return True
def main(): data = getContactsData() ap_names = [] ap_list_of_dicts = socket.access_points() for item in ap_list_of_dicts: ap_names.append(item['name']) ap_offset = appuifw.popup_menu(ap_names, u"Select default access point") if ap_offset is None: appuifw.note(u"Cancelled") return socket.set_default_access_point(ap_names[ap_offset]) status=UploadData(data) if status: appuifw.note(u"Backup Successfully") else: appuifw.note(u"Failed, unknown error")
def RetrieveAccessPointSelection(): if os.path.exists(apidFile): print "ap file exist" file = open(apidFile,'r') apid = sel_access_point(int(file.read())) file.close else: print "no stored iap. will prompt." apid = sel_access_point(0) StoreAccessPointSelection(apid) if apid: apo = socket.access_point(apid) socket.set_default_access_point(apo) return apo else: return None
def sel_access_point(self): """ Select and set the default access point. Return the access point object if the selection was done or None if not """ aps = socket.access_points() if not aps: note(u"No access points available", "error") return None ap_labels = map(lambda x: x['name'], aps) item = popup_menu(ap_labels, u"Access points:") if item is None: return None logging.debug('AP set: %s' % item) apo = socket.access_point(aps[item]['iapid']) socket.set_default_access_point(apo) return apo
def sel_access_point(self): """ Select and set the default access point. Return the access point object if the selection was done or None if not """ aps = socket.access_points() if not aps: note(u"No access points available","error") return None ap_labels = map(lambda x: x['name'], aps) item = popup_menu(ap_labels,u"Access points:") if item is None: return None logging.debug('AP set: %s' % item) apo = socket.access_point(aps[item]['iapid']) socket.set_default_access_point(apo) return apo
def getip(x): x = str(x) all = socket.access_points() for i in range(len(all)): iapid = all[i]["iapid"] pname = all[i]["name"] socket.set_default_access_point(socket.access_point(iapid)) try: ip = socket.gethostbyname(x) except: continue if ip.find("*") > -1: continue else: break #print ip return ip
def RetrieveAccessPointSelection(): if os.path.exists(apidFile): print "ap file exist" file = open(apidFile, 'r') apid = sel_access_point(int(file.read())) file.close else: print "no stored iap. will prompt." apid = sel_access_point(0) StoreAccessPointSelection(apid) if apid: apo = socket.access_point(apid) socket.set_default_access_point(apo) return apo else: return None
def select_access_point(self): """ Select the default access point. Return True if the selection was done or False if not found on <http://croozeus.com/blogs/?p=836> """ aps = socket.access_points() if not aps: appuifw.note(u"No access points available","error") return False ap_labels = map(lambda x: x['name'], aps) item = appuifw.popup_menu(ap_labels,u"Access points:") if item is None: return False self.apo = socket.access_point(aps[item]['iapid']) socket.set_default_access_point(self.apo) return True
def send(self, data='', url=''): #发送网络数据公用函数 import httplib from socket import access_points, access_point, select_access_point, set_default_access_point self.apid = self.aps[eval(self.setting[6])] self.ap = access_point(self.apid['iapid']) set_default_access_point(self.ap) heads = { "Accept": "text/plain", "Content-Type": "application/x-www-form-urlencoded", "User-Agent": "LeXun-PY_G-XWM-ZXF" } try: conn = httplib.HTTPConnection('10.0.0.172:80') conn.request('POST', url, data, heads) res = conn.getresponse() except: pass return res.status, res.reason, res.read()
def select_access_point(): ''' Return True if selected, False otherwise ''' import btsocket, socket global st_connected pnts = [] points = btsocket.access_points() for i in points: pnts.append(i['name']) index = appuifw.popup_menu(pnts, u'Select access point:') if index is not None: try: socket.set_default_access_point(pnts[index]) st_connected = True return True except: pass return False
def main(): syncday = appuifw.query(u"The date to be uploaded",u"date",time()) if syncday is None: appuifw.note(u"User Cancelled") return cal = calendar.open() entries = cal.daily_instances(syncday,appointments=1,events=1) if len(entries)>0: ap_names = [] ap_list_of_dicts = socket.access_points() for item in ap_list_of_dicts: ap_names.append(item['name']) ap_offset = appuifw.popup_menu(ap_names, u"Select default access point") if ap_offset is None: appuifw.note(u"Cancelled!") return socket.set_default_access_point(ap_names[ap_offset]) u=appuifw.query(u'email','text',u"@gmail.com") p=appuifw.query(u'password','code',u"") n=appuifw.query(u'username','text',u"") if u is None or p is None or n is None: appuifw.note(u"User Cancelled") return u=u.encode("utf8") p=p.encode("utf8") n=n.encode("utf8") feedloc = '/calendar/feeds/'+u+'/private/full' try: auth = GoogleAuth( u, p ) sess = SessionUrl( auth, feedloc ) for entry in entries: event = cal[entry['id']] dict = dictFromS60Event(event) entry = atomEntryFromDict(u,p,n,dict) entry=entry.encode("utf8") insertGcal(entry,sess,auth) print " Added : " + event.content print "OK" except Exception,msg: #print msg appuifw.note(u"Error")
def main(): ap_names = [] ap_list_of_dicts = socket.access_points() for item in ap_list_of_dicts: ap_names.append(item['name']) ap_offset = appuifw.popup_menu(ap_names, u"Select default access point") if ap_offset is None: appuifw.note(u"Cancelled!") else: socket.set_default_access_point(ap_names[ap_offset]) client=IPGWClient(PasswordManger()) try: if not client.open(): appuifw.note(u"Cancelled!") return ret = client.doConnect() appuifw.note(ret.decode("utf8")) print ret except Exception,e: print e appuifw.note(u"Cancelled!")
def WakeOnLan(): global config # Construct a six-byte hardware address addr_byte = config['mac'].split(':') hw_addr = struct.pack('BBBBBB', int(addr_byte[0], 16), int(addr_byte[1], 16), int(addr_byte[2], 16), int(addr_byte[3], 16), int(addr_byte[4], 16), int(addr_byte[5], 16)) # Build the Wake-On-LAN "Magic Packet"... msg = '\xff' * 6 + hw_addr * 16 # ...and send it to the broadcast address using UDP apo = socket.access_point(config['accesspoint']) socket.set_default_access_point(apo) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.sendto(msg, (config['ip'], 9)) s.close()
def sendToSOS(body, sensorMac, depth, endDate): apFile = open('e:\\SSN\\apid.txt', 'rb') setting = apFile.read() apid = eval(setting) apFile.close() #error checking here for the credit etc. "can you hear me?, yes? wicked!" trace("got credit") apo = socket.access_point(apid) socket.set_default_access_point(apo) sockIP = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # send the request. sockIP = httplib.HTTPConnection('150.229.66.73', 80) sockIP.request('POST', '/HutchinsSOS/sos', body) trace("still here") # check the response. resp = sockIP.getresponse() responsedoc = resp.read() dbm.execute(u'DELETE FROM sensordata WHERE sensorAddr=\'%s\' AND depth = %s AND timeStamp <= %s'%(sensorMac, depth, endDate)) trace("Transmission to SOS complete") trace("returning to 'for' loop, or exiting now")
def WakeOnLan(): global config # Construct a six-byte hardware address addr_byte = config['mac'].split(':') hw_addr = struct.pack('BBBBBB', int(addr_byte[0], 16), int(addr_byte[1], 16), int(addr_byte[2], 16), int(addr_byte[3], 16), int(addr_byte[4], 16), int(addr_byte[5], 16)) # Build the Wake-On-LAN "Magic Packet"... msg = '\xff' * 6 + hw_addr * 16 # ...and send it to the broadcast address using UDP apo = socket.access_point(config['accesspoint']) socket.set_default_access_point(apo) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.sendto(msg, (config['ip'], 9)) s.close()
def download(): #---------------------- copy from here --------------------------------------- try: f = open('e:\\apid.txt', 'rb') setting = f.read() apid = eval(setting) f.close() if not apid == None: apo = socket.access_point(apid) socket.set_default_access_point(apo) else: set_accesspoint() except: set_accesspoint() #------------------------- copy till here -------------------------------------- # and put it before the line of code in your script that invokes a connection to the internet # like here with urllib.urlretrieve(url, tempfile) # your own code here url = "http://www.leninsgodson.com/courses/pys60/resources/vid001.3gp" tempfile = 'e:\\Videos\\video.3gp' urllib.urlretrieve(url, tempfile) appuifw.note(u"Video downloaded", "info")
import telephone import contacts import inbox import logs import sysinfo DEFAULT_AP = u'GGG' # the web handler for message forwarding URL = 'http://www.schemacs.com:5000/forward' KEY = 'YOUR-KEY-HERE' app_lock = e32.Ao_lock() box = inbox.Inbox() # http://www.developer.nokia.com/Community/Wiki/Python_on_Symbian/09._Basic_Network_Programming#Access_point_selection socket.set_default_access_point(DEFAULT_AP) def notify(message): print 'notify', message playload = {'key': KEY, 'message': message.encode('utf8'), 'battery': sysinfo.battery()} params = urllib.urlencode(playload) remote_fh = urllib.urlopen(URL, params) result = remote_fh.read() return result def on_message(message_id): # http://www.developer.nokia.com/Community/Wiki/How_read_SMS_in_the_inbox
def clear_ap(): socket.set_default_access_point(None) appuifw.note(u"Default access point cleared. Test passed. " + "Run ConnectToTheInternet test to verify.")
def shua(): if os.path.exists(DB_FILE): f = file(DB_FILE, "r") lst = [] for line in f: lst.append(line.strip()) f.close() apid = lst[0] cq = lst[1] cm = lst[2] else: list = [] apid = sel_access_point() list.append(apid) yq = appuifw.query('qq号码:'.decode('utf-8'), 'number', 223081080) ym = appuifw.query('qq密码:'.decode('utf-8'), 'code') if yq and ym: list.append(yq) list.append(ym) cq, cm = yq, ym f = file(DB_FILE, "w") for item in list: print >> f, item f.close() def cancel_cb(): pass point = socket.access_point(int(apid)) socket.set_default_access_point(point) dlg = Wait(cn('正在连接网络'), False, cancel_cb) dlg.show() set_body(cn('正在连接网络')) get('http://z.qq.com') dlg.set_label(cn('请等待…\n正在获取网页地址')) a = step1('http://z.qq.com') set_body('打开网页'.decode('utf-8') + a) #过滤登录我的QQ空间 strgl = '\xe7\x99\xbb\xe5\xbd\x95\xe6\x88\x91\xe7\x9a\x84QQ\xe7\xa9\xba\xe9\x97\xb4' dlg.set_label(cn('如果您长期停留在某一界面请尝试更换接入点或退出程序稍后再试…')) c = lookurl(a, strgl) set_body('打开网页'.decode('utf-8') + c) dlg.set_label(cn('请等待\n正在登录空间…')) d = get_sid(c, cq, cm) set_body('提取sid为:'.decode('utf-8') + d) #手机美文链接 gl = '\xe6\x89\x8b\xe6\x9c\xba\xe7\xbe\x8e\xe6\x96\x87' libao = '\xe6\x81\xad\xe5\x96\x9c\xe6\x82\xa8\xe8\x8e\xb7\xe5\xbe\x97\xe5\xb9\xb8\xe8\xbf\x90\xe5\xa4\xa7\xe7\xa4\xbc\xe5\x8c\x85' dlg.set_label(cn('正在预读美文日志链接…')) set_body(cn('正在预读美文链接…')) m = lookurl(a, gl) dlg.close() url = m[:m.find('&sid=') + 5] + d for i in range(500): readnext(url) #读日志 set_body(cn('正在预读美文链接…')) url = lookurl(url, '\xe4\xb8\x8b\xe9\xa1\xb5') set_body(cn('正在检测进度…')) libaourl = lookurl(myzone_url, libao) if libaourl != None: set_body(cn('恭喜你,刷到了\n快点击<我的空间>看看吧…')) break if url == None: break if libaourl == None: set_body(cn('呜呜呜,还没刷到喔…\n继续…加油…')) point.stop()
import telephone import contacts import inbox import logs import sysinfo DEFAULT_AP = u'GGG' # the web handler for message forwarding URL = 'http://www.schemacs.com:5000/forward' KEY = 'YOUR-KEY-HERE' app_lock = e32.Ao_lock() box = inbox.Inbox() # http://www.developer.nokia.com/Community/Wiki/Python_on_Symbian/09._Basic_Network_Programming#Access_point_selection socket.set_default_access_point(DEFAULT_AP) def notify(message): print 'notify', message playload = { 'key': KEY, 'message': message.encode('utf8'), 'battery': sysinfo.battery() } params = urllib.urlencode(playload) remote_fh = urllib.urlopen(URL, params) result = remote_fh.read() return result
# the test set file name. testcase = test_set except: # Testapp is executed directly, get the first # file from testcase_dir listTestSets = os.listdir(testcase_dir) listTestSets.reverse() testcase = listTestSets[0] cmd = 'c:\\data\\python\\test\\regrtest.py' opt = '-f ' + testcase #Executes version.py before executing any of the test cases if testcase == "set_a.txt": execfile(sis_version) print "runtests_sets: " + testcase + "-> Started" if not e32.in_emulator(): socket.set_default_access_point(u'Mobile Office') sys.argv = ['python.exe'] + ['-v'] + ['-u'] + \ ['network,urlfetch'] + ['-f'] + \ ['%s\\%s'%(testcase_dir,testcase)] else: sys.argv = ['python.exe'] + ['-v'] + ['-f'] + \ ['%s\\%s' % (testcase_dir, testcase)] test.regrtest.main() except SystemExit: # Ignore the sys.exit at the end of regrtest's main() pass except: import traceback traceback.print_exc() finally: #delete the test_set file, so that its not used in next iteration.
def defaultAP(): ap_id = socket.select_access_point() apo = socket.access_point(ap_id) socket.set_default_access_point(apo)
# ip = apo.ip() # print u"Connected to WiFi as %s" % ip #except: # print u"Failed to connect to WiFi" menuitems = [] aps = socket.access_points() for k in aps: menuitems.append(k['name']) menuitems.append(u'LOCAL') id = globalui.global_popup_menu(menuitems, u'Select AP') if id < len(aps): print id, aps[id] apo = socket.access_point(aps[id]['iapid']) socket.set_default_access_point(apo) apo.start() try: ip = apo.ip() except: globalui.global_note(u"Could not Connect!, EXIT") sys.exit() else: # bind to localhost ip = "127.0.0.1" globalui.global_note(u"Your IP:"+ unicode(str(ip))) sys.path.append('e:\\python\\libs') import socketserver
import socket ap_id = socket.select_access_point() apo = socket.access_point(ap_id) socket.set_default_access_point(apo)
def onSetAccessPoint(self): self.accessPointId = socket.select_access_point() self.accessPoint = socket.access_point(self.accessPointId) socket.set_default_access_point(self.accessPoint) self.saveSettings()
def access_point(): ap_id = socket.select_access_point() apo = socket.access_point(ap_id) socket.set_default_access_point(apo)