Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85431
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <torque.india@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'else:': 0.03; 'method.': 0.07; 'string': 0.09; 'none)': 0.09; 'none):': 0.09; 'parsing': 0.09; 'skip:f 70': 0.09; 'subject:parsing': 0.09; 'try:': 0.09; 'variables.': 0.09; 'python': 0.11; 'def': 0.12; '"r")': 0.16; 'dict': 0.16; 'list):': 0.16; 'properties,': 0.16; 'typeerror:': 0.16; 'x86_64': 0.16; 'subject:python': 0.16; 'trying': 0.19; 'skip:f 30': 0.19; 'later': 0.20; 'written': 0.21; 'print': 0.22; 'error': 0.23; 'expanded': 0.24; 'skip:i 40': 0.24; '>': 0.26; 'skip:_ 20': 0.27; 'values': 0.27; 'function': 0.29; 'properties': 0.29; 'xml': 0.29; 'characters': 0.30; 'message-id:@mail.gmail.com': 0.30; 'program,': 0.31; 'getting': 0.31; "skip:' 10": 0.31; 'doc': 0.31; 'skip:i 60': 0.31; 'file': 0.32; 'linux': 0.33; 'skip:d 20': 0.34; 'subject:with': 0.35; 'except': 0.35; 'skip:s 30': 0.35; 'skip:u 20': 0.35; 'convert': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'skip:f 40': 0.36; 'doing': 0.36; 'area': 0.37; 'being': 0.38; 'server': 0.38; 'skip:& 10': 0.38; 'hat': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'skip:& 20': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'skip:x 10': 0.40; 'skip:\xc2 10': 0.60; 'tag': 0.61; 'no.': 0.61; 'back': 0.62; 'skip:n 10': 0.64; 'skip:f 50': 0.65; 'here': 0.66; '8bit%:100': 0.72; 'skip:$ 10': 0.81; 'dict,': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=D7XeHoy+WhC0H/1Xo4G0sYnqHWId7cTxeMRdykKKF9s=; b=HSJ5L0gKz+6p2DfxxbQ0yQRR73Kb5JbwHpGUdQ1UFmliyIoWaaaExc7WZhm1JKNk3/ 0GOs03GgkIA1MxwjmmIsyElU9havmVZKVI2qL9AusTN0RQf7FwSXJSnUbXVq3+BRDWex MaJrqugFxtNV+XjkwvQWzu9ZqeR96x8S/XRKULTYV+LPmj/yin75Z21p/EkHPaiR6M26 /9gkb08ZweZaxo1PKJzKYODzGfbsveBFOBDiZkniIwUYxl1TRYaYdTx21hxK0FW+Umw4 ZUJuzbtOCxv48HwUgLTkpNFEaCOEqrPKV/hGKbOHMgwSH8txKLbmnzlhTY9XBPYLR3oj mXyw== |
| MIME-Version | 1.0 |
| X-Received | by 10.202.107.195 with SMTP id g186mr13831777oic.67.1423553404501; Mon, 09 Feb 2015 23:30:04 -0800 (PST) |
| Date | Tue, 10 Feb 2015 13:00:04 +0530 |
| Subject | Varable parsing error with python |
| From | OmPs <torque.india@gmail.com> |
| To | python mail list <python-list@python.org> |
| Content-Type | multipart/alternative; boundary=001a1141bdc6fe83b8050eb6daa2 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18598.1423553413.18130.python-list@python.org> (permalink) |
| Lines | 222 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1423553413 news.xs4all.nl 2904 [2001:888:2000:d::a6]:46359 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:85431 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
In an XML file which contain a tag and then these tags contain properties,
which later are being called in anoter tag where these properties are
expanded as variables.
For eg.
<instance name='instancename' user='test' group='test'
fullname='test%20-%20dev%20app' >
<property>
<APPVERSION>1.0</APPVERSION>
</property>
</instance>
<component name='testappComp' user='test' group='test'>
<version>1.2</version>
<os>Red Hat Enterprise Linux Server 5 X86_64</os>
<package>testsapppath</package>
</component>
<package name='testapppath'>
<description>my testapp area</description>
<version>${APPVERSION}</version>
</package>
So now i have written a python program whcih is parsing this program, so
what i am doing in here is reading this xml file
with open(filename, "r") as f:
orig_xml = f.read()
#unescape html characters like %20
xmlstring = urllib.unquote(orig_xml)
#convert xml to dict
doc = xmltodict.parse(xmlstring)
#replace property values in xml string via instancename
s = Template(xmlstring)
#iterate over instances/ match the one we need
for i in doc.get("application").get("instance", None):
#when found
# s/r properties in xml and then convert it back to dict
try:
if i.get("@name", None) == instancename:
try:
instance_property = dict(i.get("property"))
final_string = s.safe_substitute(instance_property)
final_dict = xmltodict.parse(final_string)
except TypeError:
final_dict = doc
# Handle strings in case of dict, strings do not have get method.
except AttributeError:
final_dict = doc
and when i am trying to get the version no. using a function for getting
the package version
def _getPackgeVersion(xmlfile, p):
package = str(p)
if isinstance(fpmdict["application"]["package"], list):
for i in fpmdict["application"]["package"]:
if i["@name"] == p:
_pkgVersion = i["version"]
else:
_pkgversion = fpmdict["application"]["package"]["version"]
return _pkgVersion
pkgVersion = _getPackgeVersion(final_doc, testpackage)
print type(pkgVersion)
I am getting the below error
<type 'NoneType'>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Varable parsing error with python OmPs <torque.india@gmail.com> - 2015-02-10 13:00 +0530
csiph-web