ó
ÎrOc           @   s   d  d l  m Z d  d l m Z d  d l Z d  d l m Z d  d l m Z m	 Z	 m
 Z
 d  d l m Z m Z m Z d e f d     YZ d S(	   i˙˙˙˙(   t	   urlencode(   t   urlopenN(   t
   ExpatError(   t   Geocodert   GeocoderErrort   GeocoderResultError(   t   Pointt   Locationt   utilt	   MediaWikic           B   s>   e  Z d d   Z e d    Z d   Z d   Z d   Z RS(   c         C   s%   | |  _  t |  r! | |  _ n  d S(   sn  Initialize a geocoder that can parse MediaWiki pages with the GIS
        extension enabled.

        ``format_url`` is a URL string containing '%s' where the page name to
        request will be interpolated. For example: 'http://www.wiki.com/wiki/%s'

        ``transform_string`` is a callable that will make appropriate
        replacements to the input string before requesting the page. If None is
        given, the default transform_string which replaces ' ' with '_' will be
        used. It is recommended that you consider this argument keyword-only,
        since subclasses will likely place it last.
        N(   t
   format_urlt   callablet   transform_string(   t   selfR
   R   (    (    s7   /var/www/python/geopy-trunk/geopy/geocoders/wiki_gis.pyt   __init__
   s    	c         C   s   | j  d d  S(   s8   Do the WikiMedia dance: replace spaces with underscores.t    t   _(   t   replace(   t   clst   string(    (    s7   /var/www/python/geopy-trunk/geopy/geocoders/wiki_gis.pyR      s    c         C   s)   |  j  |  } |  j | } |  j |  S(   N(   R   R
   t   geocode_url(   R   R   t   wiki_stringt   url(    (    s7   /var/www/python/geopy-trunk/geopy/geocoders/wiki_gis.pyt   geocode!   s    c         C   sK   t  j j d |  t |  } |  j |  \ } \ } } | | | f f S(   Ns   Fetching %s...(   R   t   loggert   debugR   t   parse_xhtml(   R   R   t   paget   namet   latitudet	   longitude(    (    s7   /var/www/python/geopy-trunk/geopy/geocoders/wiki_gis.pyR   &   s    c      	   C   sÖ   t  | t  r | p t |  } | j j d i d d 6 } | rM | d pP d  } | j j d i d d 6 } | rĵ | d } t j |  \ } } | d k sĴ | d k rĈ d  } } qĈ n
 d  } } | | | f f S(   Nt   metas   geo.placenameR   t   contents   geo.positioni    (   t
   isinstancet   BeautifulSoupt   headt   findt   NoneR   t	   parse_geo(   R   R   t   soupR   R   t   positionR   R   (    (    s7   /var/www/python/geopy-trunk/geopy/geocoders/wiki_gis.pyR   ,   s    !

N(	   t   __name__t
   __module__R%   R   t   classmethodR   R   R   R   (    (    (    s7   /var/www/python/geopy-trunk/geopy/geocoders/wiki_gis.pyR	   	   s
   		(   t   urllibR    t   urllib2R   t   xmlt   xml.parsers.expatR   t   geopy.geocoders.baseR   R   R   t   geopyR   R   R   R	   (    (    (    s7   /var/www/python/geopy-trunk/geopy/geocoders/wiki_gis.pyt   <module>   s   