o
    …>ax  ã                   @   s\   d Z ddlZddlZddlmZ ddlmZ ddl	m
Z
 e d¡Zedg d¢ƒZd	d
„ ZdS )z, Helper functions for change file handling. é    N)Ú
namedtuple)ÚReader)ÚNOTHINGÚpyosmiumÚReplicationHeader)ÚurlÚsequenceÚ	timestampc                 C   s  t | tƒ}| ¡ }| d¡}| d¡}|s|rt d¡ |rXt d|¡ | d¡}|rUt d|¡ zt|ƒ}|dk rBt d|¡ d	}W n tyT   t d
|¡ d	}Y nw d	}nd	}d	}|r†t d|¡ zt	j
 |d¡}|jt	jjd�}W n ty…   t d¡ d	}Y nw d	}t|||ƒS )a‘   Scans the given file for an Osmosis replication header. It returns
        a namedtuple with `url`, `sequence` and `timestamp`. Each or all fields
        may be None, if the piece of information is not avilable. If any of
        the fields has an invalid format, it is simply ignored.

        The given file must exist and be readable for osmium, otherwise
        a `RuntimeError` is raised.
    Úosmosis_replication_timestampÚosmosis_replication_base_urlz1Replication information found in OSM file header.zReplication URL: %sÚ#osmosis_replication_sequence_numberzReplication sequence: %sr   z9Sequence id '%d' in OSM file header is negative. Ignored.Nz=Sequence id '%s' in OSM file header is not a number. Ignored.zReplication timestamp: %sz%Y-%m-%dT%H:%M:%SZ)ÚtzinfozSDate in OSM file header is not in ISO8601 format (e.g. 2015-12-24T08:08Z). Ignored.)Úoreaderr   ÚheaderÚgetÚLOGÚdebugÚintÚwarningÚ
ValueErrorÚdtÚdatetimeÚstrptimeÚreplaceÚtimezoneÚutcr   )ÚfnameÚrÚhÚtsr   Úseq© r!   ú:/usr/lib/python3/dist-packages/osmium/replication/utils.pyÚget_replication_header   sF   





€þ
þr#   )Ú__doc__Úloggingr   r   Úcollectionsr   Ú	osmium.ior   r   Ú
osmium.osmr   Ú	getLoggerr   r   r#   r!   r!   r!   r"   Ú<module>   s    
ÿ