Форум сайта python.su
// keep this handle handy as we need it for further RIL commands
HRIL rilHandle;
...
HRESULT hr = RIL_Initialize(
1, // index of the RIL port to use (e.g., 1 for RIL1:)
&resultCallBack, // this is a pointer to your result call back method
¬ifyCallback, // this is a pointer to your notify call back method
RIL_NCLASS_ALL, // all notification (except device specific)
(DWORD) this, // custom param (could be a pointer to an instance of a class)
&rilHandle); // returned handle to RIL instance
...
void CALLBACK resultCallback(
DWORD dwCode,
HRESULT hrCmdID,
const void *lpData,
DWORD cbData,
DWORD dwParam)
{
// handle the results
...
void CALLBACK notifyCallback(
DWORD dwCode,
const void *lpData,
DWORD cbData,
DWORD dwParam)
{
// handle the notification
#! /usr/bin/env python
from vsws import url_pattern, Controller
from webob import Request, Response
@url_pattern("/users")
@url_pattern("/all_users")
@url_pattern("/users/${username}/list", ['GET'])
def get_users (response):
response.status = 200
return "Inside get_users()"
@url_pattern("/users/${username}")
def get_user (username):
return {"body": "Inside get_user('%s')" % username, "status": 201}
@url_pattern("/users/${username}/plans", ['GET', 'PUT'])
def get_plans (username):
return "Inside get_plans('%s'), GET or PUT" % username
@url_pattern("/users/${username}/plans", ['POST'])
def get_plans (username):
return "Inside get_plans('%s'), POST" % username
@url_pattern("/users/${username}/plans/${year}")
def get_plan (username, year, method, param2 = ''):
return "Inside get_plan('%s', %s, %s, %s)" % (username, year, method, param2)
print Request.blank ('/users/john/plans/2009?param1=value1¶m2=value2').get_response (Controller())
import threading
def proc(p):
print "Start thread " + p
p1 = threading.Thread(target=proc, name="p1", args=["1"])
p2 = threading.Thread(target=proc, name="p2", args=["2"])
p1.start()
p2.start()
ERROR: dbgp.client:
The main thread of this application is exiting while there are still threads
alive. When the main thread exits, it is system defined whether the other
threads survive.
See Caveats at http://docs.python.org/lib/module-thread.html
from itertools import chain
class cNode:
def __init__(self, name = "", attrs = {}):
self.name = name
self.attrs = attrs
def GetAttrs(self):
return self.attrs.keys()
def GetValue(self, attr):
value = None
try:
value = self.attrs[attr]
except KeyError:
pass
return value
class cTree:
class cData:
def __init__(self, data=None):
self.child = []
self.node = data
def __iter__(self):
#for nn in self.child:
# yield nn
for n in chain([self], *self.child):
yield n
def __init__(self):
self.data = cTree.cData()
def __iter__(self):
for n in self.data:
if isinstance(n.node, cNode):
yield n.node
def Append(self, parent, node):
temp = cTree.cData(node)
if parent is None:
self.data.child.append(temp)
else:
for n in self.data:
if n.node == parent:
n.child.append(temp)
break
tree = cTree()
node1 = cNode("root")
node2 = cNode("3")
node3 = cNode("4")
node4 = cNode("5")
node5 = cNode("1")
node6 = cNode("2")
node7 = cNode("10")
node8 = cNode("11")
node9 = cNode("12")
tree.Append(None, node1)
tree.Append(node1, node2)
tree.Append(node2, node3)
tree.Append(node2, node4)
tree.Append(node1, node5)
tree.Append(node1, node6)
tree.Append(node3, node7)
tree.Append(node3, node8)
tree.Append(node3, node9)
for tn in tree:
print tn.name
root
3
4
10
11
12
5
1
2