Skip to content

Commit

Permalink
Minor fixes to ported python code
Browse files Browse the repository at this point in the history
git-svn-id: https://pybluez.googlecode.com/svn/trunk@64 bcb67f6a-c13e-0410-b0c7-e53ae835acad
  • Loading branch information
[email protected] committed Jan 19, 2014
1 parent 68d3a3d commit a5854a1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
12 changes: 6 additions & 6 deletions bluetooth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import os
if sys.version < '3':
from btcommon import *
from .btcommon import *
else:
from bluetooth.btcommon import *

Expand All @@ -21,11 +21,11 @@ def _dbg(*args):
os.path.exists (os.path.join (sysroot, "system32", dll)) or \
os.path.exists (os.path.join (sysroot, dll)):
try:
import widcomm
from . import widcomm
if widcomm.inquirer.is_device_ready ():
# if the Widcomm stack is active and a Bluetooth device on that
# stack is detected, then use the Widcomm stack
from widcomm import *
from .widcomm import *
have_widcomm = True
except ImportError:
pass
Expand All @@ -34,17 +34,17 @@ def _dbg(*args):
# otherwise, fall back to the Microsoft stack
_dbg("Widcomm not ready. falling back to MS stack")
if sys.version < '3':
from msbt import *
from .msbt import *
else:
from bluetooth.msbt import *

elif sys.platform.startswith("linux"):
if sys.version < '3':
from bluez import *
from .bluez import *
else:
from bluetooth.bluez import *
elif sys.platform == "darwin":
from osx import *
from .osx import *
else:
raise Exception("This platform (%s) is currently not supported by pybluez." % sys.platform)

Expand Down
13 changes: 6 additions & 7 deletions bluetooth/bluez.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import binascii

if sys.version < '3':
from btcommon import *
from .btcommon import *
import _bluetooth as _bt
else:
from bluetooth.btcommon import *
Expand Down Expand Up @@ -266,8 +266,7 @@ def find_service (name = None, uuid = None, address = None):
continue

if name is not None:
matches = filter (lambda s: s.get ("name", "") == name, \
matches)
matches = [s for s in matches if s.get ("name", "") == name]

for m in matches:
m["host"] = addr
Expand Down Expand Up @@ -580,7 +579,7 @@ def _device_discovered (self, address, device_class,

def _send_next_name_req (self):
assert len (self.names_to_find) > 0
address = self.names_to_find.keys ()[0]
address = list(self.names_to_find.keys ())[0]
device_class, psrm, pspm, clockoff = self.names_to_find[address]
bdaddr = _bt.str2ba (address)

Expand Down Expand Up @@ -622,10 +621,10 @@ def device_discovered (self, address, device_class, name):
[1] https://www.bluetooth.org/foundry/assignnumb/document/baseband
"""
if name:
print("found: %s - %s (class 0x%X)" % \
(address, name, device_class))
print(("found: %s - %s (class 0x%X)" % \
(address, name, device_class)))
else:
print("found: %s (class 0x%X)" % (address, device_class))
print(("found: %s (class 0x%X)" % (address, device_class)))

def inquiry_complete (self):
"""
Expand Down
2 changes: 1 addition & 1 deletion bluetooth/msbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def dup (self):

def makefile (self):
# TODO
raise "Not yet implemented"
raise Exception("Not yet implemented")


def advertise_service (sock, name, service_id = "", service_classes = [], \
Expand Down
2 changes: 1 addition & 1 deletion bluetooth/osx.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from btcommon import *
from .btcommon import *

raise NotImplementedError
4 changes: 2 additions & 2 deletions bluetooth/widcomm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from btcommon import *
from .btcommon import *
import socket
import struct
import threading
Expand Down Expand Up @@ -217,7 +217,7 @@ def _port_ev_code_to_str (code):
_widcomm.PORT_EV_FC : "Flow control enabled flag changed by remote",
_widcomm.PORT_EV_FCS : "Flow control status true = enabled" }
result = []
for k, v in d.items ():
for k, v in list(d.items ()):
if code & k:
result.append (v)
if len (result) == 0:
Expand Down
4 changes: 2 additions & 2 deletions examples/bluezchat/bluezchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def send_button_clicked(self, widget):
text = self.input_tb.get_text()
if len(text) == 0: return

for addr, sock in self.peers.items():
for addr, sock in list(self.peers.items()):
sock.send(text)

self.input_tb.set_text("")
Expand Down Expand Up @@ -159,7 +159,7 @@ def connect(self, addr):
sock = bluetooth.BluetoothSocket (bluetooth.L2CAP)
try:
sock.connect((addr, 0x1001))
except bluez.error, e:
except bluez.error as e:
self.add_text("\n%s" % str(e))
sock.close()
return
Expand Down

0 comments on commit a5854a1

Please sign in to comment.