Christian Scholz
2008-07-14 21:31:34 UTC
Hi!
I was playing around a bit while waiting for a video encoding to finish
and I came up with this example high level API which is more a set of
functions (no class needed here). It also includes doctests directly
which pass in my example sandbox.
I am not sure this works here regarding line breaks, so you can also see
it here:
http://pastebin.com/mffb73aa
(I also refactored the code a bit to use IPlaceAvatar on the AgentDomain
and not the Agent anymore and I implement an Avatar class which holds a
reference to the region it just is on which in turn stores the details
which it gets from place_avatar().
-- Christian
"""
High level API
"""
from pyogp.lib.base.credentials import PlainPasswordCredential
from pyogp.lib.base.agentdomain import AgentDomain
from pyogp.lib.base.regiondomain import Region
from pyogp.lib.base.interfaces import IPlaceAvatar
### login methods
def login_with_plainpassword(agentdomain_url, firstname, lastname,
password):
"""logs an agent into the agent domain and returns an agent handle
takes firstname, lastname and plain password and returns an agent
object
Now this agent should contain an agentdomain object
"""
credentials = PlainPasswordCredential(firstname, lastname, password)
agentdomain = AgentDomain(agentdomain_url)
agent = agentdomain.login(credentials)
return agent
### place avatar
def place_avatar(agent, region_url):
"""place an avatar on a region
Placing an avatar is simple. We just need an agent object and a
region url.
"""
place = IPlaceAvatar(agent.agentdomain)
region = Region(region_url)
avatar = place(region)
return avatar
def run_loop(avatar):
"""run the UDP loop for the avatar
I was playing around a bit while waiting for a video encoding to finish
and I came up with this example high level API which is more a set of
functions (no class needed here). It also includes doctests directly
which pass in my example sandbox.
I am not sure this works here regarding line breaks, so you can also see
it here:
http://pastebin.com/mffb73aa
(I also refactored the code a bit to use IPlaceAvatar on the AgentDomain
and not the Agent anymore and I implement an Avatar class which holds a
reference to the region it just is on which in turn stores the details
which it gets from place_avatar().
-- Christian
"""
High level API
"""
from pyogp.lib.base.credentials import PlainPasswordCredential
from pyogp.lib.base.agentdomain import AgentDomain
from pyogp.lib.base.regiondomain import Region
from pyogp.lib.base.interfaces import IPlaceAvatar
### login methods
def login_with_plainpassword(agentdomain_url, firstname, lastname,
password):
"""logs an agent into the agent domain and returns an agent handle
takes firstname, lastname and plain password and returns an agent
object
agent =
login_with_plainpassword("http://localhost:12345","Firstname","Lastname","secret")Now this agent should contain an agentdomain object
agent.agentdomain
<pyogp.lib.base.agentdomain.AgentDomain object at ...>agent.agentdomain.seed_cap
<SeedCapability for http://127.0.0.1:12345/seed_cap>"""
credentials = PlainPasswordCredential(firstname, lastname, password)
agentdomain = AgentDomain(agentdomain_url)
agent = agentdomain.login(credentials)
return agent
### place avatar
def place_avatar(agent, region_url):
"""place an avatar on a region
Placing an avatar is simple. We just need an agent object and a
region url.
agent =
login_with_plainpassword("http://localhost:12345","Firstname","Lastname","secret")avatar = place_avatar(agent, "http://localhost:12345/region")
avatar.region
<pyogp.lib.base.regiondomain.Region object at ...>avatar.region
avatar.region.details
{'sim_port': 12345, 'sim_ip': '127.0.0.1'}"""
place = IPlaceAvatar(agent.agentdomain)
region = Region(region_url)
avatar = place(region)
return avatar
def run_loop(avatar):
"""run the UDP loop for the avatar
agent =
login_with_plainpassword("http://localhost:12345","Firstname","Lastname","secret")avatar = place_avatar(agent, "http://localhost:12345/region")
run_loop(avatar)
"""run_loop(avatar)
--
Christian Scholz video blog: http://comlounge.tv
COM.lounge blog: http://mrtopf.de/blog
Luetticher Strasse 10 Skype: HerrTopf
52064 Aachen Homepage: http://comlounge.net
Tel: +49 241 400 730 0 E-Mail ***@comlounge.net
Fax: +49 241 979 00 850 IRC: MrTopf, Tao_T
neue Show: TOPFt?glich (http://mrtopf.de/blog/category/topf-taglich/)
Christian Scholz video blog: http://comlounge.tv
COM.lounge blog: http://mrtopf.de/blog
Luetticher Strasse 10 Skype: HerrTopf
52064 Aachen Homepage: http://comlounge.net
Tel: +49 241 400 730 0 E-Mail ***@comlounge.net
Fax: +49 241 979 00 850 IRC: MrTopf, Tao_T
neue Show: TOPFt?glich (http://mrtopf.de/blog/category/topf-taglich/)