Server IP : 103.169.32.36 / Your IP : 216.73.217.13 Web Server : Apache System : Linux web.dpmptsp 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : apache ( 48) PHP Version : 5.6.40 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib/python2.7/site-packages/yum/ |
Upload File : |
| Current File : /usr/lib/python2.7/site-packages/yum/parser.py |
#! /usr/bin/python -tt
import re
import urlparse
import urlgrabber
import os.path
import Errors
_KEYCRE = re.compile(r"\$(\w+)")
def varReplace(raw, vars):
'''Perform variable replacement
@param raw: String to perform substitution on.
@param vars: Dictionary of variables to replace. Key is variable name
(without $ prefix). Value is replacement string.
@return: Input raw string with substituted values.
'''
if not vars:
return raw
done = [] # Completed chunks to return
while raw:
m = _KEYCRE.search(raw)
if not m:
done.append(raw)
break
# Determine replacement value (if unknown variable then preserve
# original)
varname = m.group(1).lower()
replacement = vars.get(varname, m.group())
start, end = m.span()
done.append(raw[:start]) # Keep stuff leading up to token
done.append(replacement) # Append replacement value
raw = raw[end:] # Continue with remainder of string
return ''.join(done)
class ConfigPreProcessor:
"""
ConfigParser Include Pre-Processor
File-like Object capable of pre-processing include= lines for
a ConfigParser.
The readline function expands lines matching include=(url)
into lines from the url specified. Includes may occur in
included files as well.
Suggested Usage::
cfg = ConfigParser.ConfigParser()
fileobj = confpp( fileorurl )
cfg.readfp(fileobj)
"""
def __init__(self, configfile, vars=None):
# put the vars away in a helpful place
self._vars = vars
# used to track the current ini-section
self._section = None
# set some file-like object attributes for ConfigParser
# these just make confpp look more like a real file object.
self.mode = 'r'
# first make configfile a url even if it points to
# a local file
scheme = urlparse.urlparse(configfile)[0]
if scheme == '':
# check it to make sure it's not a relative file url
if configfile[0] != '/':
try:
rootdir = os.getcwd() + "/"
except:
rootdir = "/"
configfile = rootdir + configfile
url = 'file://' + configfile
else:
url = configfile
# these are used to maintain the include stack and check
# for recursive/duplicate includes
self._incstack = []
self._alreadyincluded = []
# _pushfile will return None if he couldn't open the file
fo = self._pushfile( url )
if fo is None:
raise Errors.ConfigError, 'Error accessing file: %s' % url
def readline( self, size=0 ):
"""
Implementation of File-Like Object readline function. This should be
the only function called by ConfigParser according to the python docs.
We maintain a stack of real FLOs and delegate readline calls to the
FLO on top of the stack. When EOF occurs on the topmost FLO, it is
popped off the stack and the next FLO takes over. include= lines
found anywhere cause a new FLO to be opened and pushed onto the top
of the stack. Finally, we return EOF when the bottom-most (configfile
arg to __init__) FLO returns EOF.
Very Technical Pseudo Code::
def confpp.readline() [this is called by ConfigParser]
open configfile, push on stack
while stack has some stuff on it
line = readline from file on top of stack
pop and continue if line is EOF
if line starts with 'include=' then
error if file is recursive or duplicate
otherwise open file, push on stack
continue
else
return line
return EOF
"""
# set line to EOF initially.
line=''
while len(self._incstack) > 0:
# peek at the file like object on top of the stack
fo = self._incstack[-1]
line = fo.readline()
if len(line) > 0:
m = re.match( r'\s*include\s*=\s*(?P<url>.*)', line )
if m:
url = m.group('url')
if len(url) == 0:
raise Errors.ConfigError, \
'Error parsing config %s: include must specify file to include.' % (self.name)
else:
# whooohoo a valid include line.. push it on the stack
url = varReplace(url, self._vars)
fo = self._pushfile( url )
else:
# check if the current line starts a new section
secmatch = re.match( r'\s*\[(?P<section>.*)\]', line )
if secmatch:
self._section = secmatch.group('section')
# line didn't match include=, just return it as is
# for the ConfigParser
break
else:
# the current file returned EOF, pop it off the stack.
self._popfile()
# if the section is prefixed by a space then it is breaks iniparser/configparser
# so fix it
broken_sec_match = re.match(r'\s+\[(?P<section>.*)\]', line)
if broken_sec_match:
line = line.lstrip()
# at this point we have a line from the topmost file on the stack
# or EOF if the stack is empty
return varReplace(line, self._vars)
def _absurl( self, url ):
"""
Returns an absolute url for the (possibly) relative
url specified. The base url used to resolve the
missing bits of url is the url of the file currently
being included (i.e. the top of the stack).
"""
if len(self._incstack) == 0:
# it's the initial config file. No base url to resolve against.
return url
else:
return urlparse.urljoin( self.geturl(), url )
def _pushfile( self, url ):
"""
Opens the url specified, pushes it on the stack, and
returns a file like object. Returns None if the url
has previously been included.
If the file can not be opened this function exits.
"""
# absolutize this url using the including files url
# as a base url.
absurl = self._absurl(url)
# get the current section to add it to the included
# url's name.
includetuple = (absurl, self._section)
# check if this has previously been included.
if self._isalreadyincluded(includetuple):
return None
try:
fo = urlgrabber.grabber.urlopen(absurl)
except urlgrabber.grabber.URLGrabError, e:
fo = None
if fo is not None:
self.name = absurl
self._incstack.append( fo )
self._alreadyincluded.append(includetuple)
else:
raise Errors.ConfigError, \
'Error accessing file for config %s' % (absurl)
return fo
def _popfile( self ):
"""
Pop a file off the stack signaling completion of including that file.
"""
fo = self._incstack.pop()
fo.close()
if len(self._incstack) > 0:
self.name = self._incstack[-1].geturl()
else:
self.name = None
def _isalreadyincluded( self, tuple ):
"""
Checks if the tuple describes an include that was already done.
This does not necessarily have to be recursive
"""
for etuple in self._alreadyincluded:
if etuple == tuple: return 1
return 0
def geturl(self): return self.name
| N4m3 |
5!z3 |
L45t M0d!f!3d |
0wn3r / Gr0up |
P3Rm!55!0n5 |
0pt!0n5 |
| .. |
-- |
December 21 2023 09:18:24 |
0 / 0 |
0755 |
|
| | | | | |
| Errors.py |
4.265 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| Errors.pyc |
9.084 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| __init__.py |
304.096 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| __init__.pyc |
199.779 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| callbacks.py |
5.64 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| callbacks.pyc |
6.232 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| comps.py |
31.586 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| comps.pyc |
26.872 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| config.py |
49.886 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| config.pyc |
48.018 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| constants.py |
4.516 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| constants.pyc |
3.42 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| depsolve.py |
74.046 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| depsolve.pyc |
46.906 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| drpm.py |
12.851 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| drpm.pyc |
10.834 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| failover.py |
5.005 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| failover.pyc |
5.236 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| fssnapshots.py |
10.159 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| fssnapshots.pyc |
9.752 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| history.py |
61.125 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| history.pyc |
53.306 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| i18n.py |
20.437 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| i18n.pyc |
16.05 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| igroups.py |
9.313 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| igroups.pyc |
10.218 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| logginglevels.py |
7.904 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| logginglevels.pyc |
6.511 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| mdparser.py |
6.258 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| mdparser.pyc |
7.58 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| metalink.py |
9.188 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| metalink.pyc |
8.836 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| misc.py |
39.567 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| misc.pyc |
39.58 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| packageSack.py |
40.786 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| packageSack.pyc |
41.88 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| packages.py |
84.104 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| packages.pyc |
84.514 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| parser.py |
7.973 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| parser.pyc |
6.499 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| pgpmsg.py |
53.5 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| pgpmsg.pyc |
38.268 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| pkgtag_db.py |
4.864 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| pkgtag_db.pyc |
5.061 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| plugins.py |
28.1 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| plugins.pyc |
29.097 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| repoMDObject.py |
11.231 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| repoMDObject.pyc |
9.17 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| repos.py |
16.528 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| repos.pyc |
17.383 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| rpmsack.py |
70.255 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| rpmsack.pyc |
58.355 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| rpmtrans.py |
24.845 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| rpmtrans.pyc |
22.544 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| sqlitesack.py |
69.763 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| sqlitesack.pyc |
53.751 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| sqlutils.py |
6.271 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| sqlutils.pyc |
5.602 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| transactioninfo.py |
33.784 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| transactioninfo.pyc |
30.293 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| update_md.py |
25.9 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| update_md.pyc |
21.722 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| updateinfo.py |
18.29 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| updateinfo.pyc |
16.36 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|
| yumRepo.py |
83.852 KB |
October 01 2020 17:03:44 |
0 / 0 |
0755 |
|
| yumRepo.pyc |
64.827 KB |
October 01 2020 17:03:44 |
0 / 0 |
0644 |
|