File: //lib/python2.7/site-packages/pyzor/config.pyc
�
YF�Tc @ s� d Z d d l Z d d l Z d d l Z d d l Z y d d l m Z e Z Wn e k
ri e
Z n Xd d l Z e j
d � Z d � Z d � Z d � Z d � Z d � Z d d
d � Z d � Z d S(
s8 Functions that handle parsing pyzor configuration files.i����N( t
SentryHandlers ((?<=[^\\])#.*)c C s? t j d � } t j t � } t j j | � sT | j d � t d � | t j
<| St | � } x�| D]�} | j � sg | d d k r� qg n y; g | j
d
� D] } | j � j � ^ q� \ } } } Wn$ t k
r� | j d | � qg n Xy i t d 6t d
6| } Wn$ t k
r4| j d | � qg n X| d k rJd } n% g | j
� D] }
|
j � ^ qW} | d k r�| } n% g | j
� D] } | j � ^ q�} xq | D]i } | r�| j d d j | � | � | | j | � q�| j d d j | � | � | | j | � q�Wqg W| j � | j d | � | S( s� Load the ACL from the specified file, if it exists, and return an
ACL dictionary, where each key is a username and each value is a set
of allowed permissions (if the permission is not in the set, then it
is not allowed).
'accounts' is a dictionary of accounts that exist on the server - only
the keys are used, which must be the usernames (these are the users
that are granted permission when the 'all' keyword is used, as
described below).
Each line of the file should be in the following format:
operation : user : allow|deny
where 'operation' is a space-separated list of pyzor commands or the
keyword 'all' (meaning all commands), 'username' is a space-separated
list of usernames or the keyword 'all' (meaning all users) - the
anonymous user is called "anonymous", and "allow|deny" indicates whether
or not the specified user(s) may execute the specified operations.
The file is processed from top to bottom, with the final match for
user/operation being the value taken. Every file has the following
implicit final rule:
all : all : deny
If the file does not exist, then the following default is used:
check report ping info : anonymous : allow
t pyzordsX Using default ACL: the anonymous user may use the check, report, ping and info commands.t checkt reportt pingt pongt infoi t #t :s Invalid ACL line: %rt allowt denyt allt whitelists Granting %s to %s.t ,s Revoking %s from %s.s ACL: %r( s checkR R R s info( s checkR R R s infos whitelist( t loggingt getLoggert collectionst defaultdictt sett ost patht existsR t pyzort anonymous_usert opent stript splitt lowert
ValueErrort warnt Truet Falset KeyErrort debugt joint updatet difference_updatet close( t access_fnt accountst logt aclt accessft linet partt
operationst userst allowedt operationt user( ( s0 /usr/lib/python2.7/site-packages/pyzor/config.pyt load_access_file sN
8
" %
c C s t j d � } i } t j j | � s8 | j d � | St | � } x� | D]� } | j � sK | d d k rt qK n y | j d � \ } } Wn$ t k
r� | j
d | � qK n X| j � } | j � } | j d | | � | | | <qK W| j � | j d d j
| � � | S(
s Load the accounts from the specified file.
Each line of the file should be in the format:
username : key
If the file does not exist, then an empty dictionary is returned;
otherwise, a dictionary of (username, key) items is returned.
R sI Accounts file does not exist - only the anonymous user will be available.i R R s Invalid accounts line: %rs'