slixmpp/sleekxmpp/plugins/xep_0080/geoloc.py

123 lines
5.1 KiB
Python
Raw Normal View History

2012-03-10 20:54:31 +00:00
"""
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2010 Nathanael C. Fritz, Erik Reuterborg Larsson
This file is part of SleekXMPP.
See the file LICENSE for copying permission.
"""
import logging
import sleekxmpp
2012-03-13 02:06:54 +00:00
from sleekxmpp.plugins.base import BasePlugin
2012-03-10 20:54:31 +00:00
from sleekxmpp.xmlstream import register_stanza_plugin
from sleekxmpp.plugins.xep_0080 import stanza, Geoloc
log = logging.getLogger(__name__)
2012-03-13 02:06:54 +00:00
class XEP_0080(BasePlugin):
2012-03-10 20:54:31 +00:00
"""
XEP-0080: User Location
"""
2012-03-13 02:06:54 +00:00
name = 'xep_0080'
description = 'XEP-0080: User Location'
dependencies = set(['xep_0163'])
stanza = stanza
2012-03-10 20:54:31 +00:00
2012-03-13 02:06:54 +00:00
def plugin_init(self):
"""Start the XEP-0080 plugin."""
self.xmpp['xep_0163'].register_pep('user_location', Geoloc)
2012-03-10 20:54:31 +00:00
def publish_location(self, **kwargs):
"""
Publish the user's current location.
Arguments:
accuracy -- Horizontal GPS error in meters.
alt -- Altitude in meters above or below sea level.
area -- A named area such as a campus or neighborhood.
2012-06-19 08:29:48 +00:00
bearing -- GPS bearing (direction in which the entity is
heading to reach its next waypoint), measured in
2012-03-10 20:54:31 +00:00
decimal degrees relative to true north.
building -- A specific building on a street or in an area.
country -- The nation where the user is located.
countrycode -- The ISO 3166 two-letter country code.
datum -- GPS datum.
2012-06-19 08:29:48 +00:00
description -- A natural-language name for or description of
2012-03-10 20:54:31 +00:00
the location.
error -- Horizontal GPS error in arc minutes. Obsoleted by
the accuracy parameter.
floor -- A particular floor in a building.
lat -- Latitude in decimal degrees North.
2012-06-19 08:29:48 +00:00
locality -- A locality within the administrative region, such
2012-03-10 20:54:31 +00:00
as a town or city.
lon -- Longitude in decimal degrees East.
postalcode -- A code used for postal delivery.
2012-06-19 08:29:48 +00:00
region -- An administrative region of the nation, such
2012-03-10 20:54:31 +00:00
as a state or province.
room -- A particular room in a building.
2012-06-19 08:29:48 +00:00
speed -- The speed at which the entity is moving,
2012-03-10 20:54:31 +00:00
in meters per second.
street -- A thoroughfare within the locality, or a crossing
of two thoroughfares.
2012-06-19 08:29:48 +00:00
text -- A catch-all element that captures any other
2012-03-10 20:54:31 +00:00
information about the location.
2012-06-19 08:29:48 +00:00
timestamp -- UTC timestamp specifying the moment when the
2012-03-10 20:54:31 +00:00
reading was taken.
uri -- A URI or URL pointing to information about
the location.
options -- Optional form of publish options.
ifrom -- Specify the sender's JID.
block -- Specify if the send call will block until a response
is received, or a timeout occurs. Defaults to True.
timeout -- The length of time (in seconds) to wait for a response
before exiting the send call if blocking is used.
Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
callback -- Optional reference to a stream handler function. Will
be executed when a reply stanza is received.
"""
options = kwargs.get('options', None)
ifrom = kwargs.get('ifrom', None)
block = kwargs.get('block', None)
callback = kwargs.get('callback', None)
timeout = kwargs.get('timeout', None)
for param in ('ifrom', 'block', 'callback', 'timeout', 'options'):
if param in kwargs:
del kwargs[param]
geoloc = Geoloc()
geoloc.values = kwargs
return self.xmpp['xep_0163'].publish(geoloc,
2012-03-10 20:54:31 +00:00
options=options,
ifrom=ifrom,
block=block,
callback=callback,
timeout=timeout)
def stop(self, ifrom=None, block=True, callback=None, timeout=None):
"""
Clear existing user location information to stop notifications.
Arguments:
ifrom -- Specify the sender's JID.
block -- Specify if the send call will block until a response
is received, or a timeout occurs. Defaults to True.
timeout -- The length of time (in seconds) to wait for a response
before exiting the send call if blocking is used.
Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
callback -- Optional reference to a stream handler function. Will
be executed when a reply stanza is received.
"""
geoloc = Geoloc()
2012-06-19 08:29:48 +00:00
return self.xmpp['xep_0163'].publish(geoloc,
2012-03-10 20:54:31 +00:00
ifrom=ifrom,
block=block,
callback=callback,
timeout=timeout)