text - Grab LDAP Attribute from stdin in Python -


i've got ldap query , i'm not versed in text-processing in python. i'm sending script via stdin , can read out, given reads single line little more lost how grab value of protocol. given protocol=http, want store value after delimiter.

my stdin looks (but not exactly):

discover-repository-location=null, file name=null, date-detected=tue jun11 12:44:14 utc 2013, endpoint-machine-name=null, incident-id=545527, sender-ip=12.1.141.87, sender-email=winnt://tmpdm/tmpcmp, assigned to=null, sender-port=-null, endpoint-domain-name=null, business unit=null, endpoint-dos-volume-name=null, file-access-date=null, date-sent=tue jun 11 12:44:14 utc 2013, endpoint-file-name=null, file-modified-by=null, country=null, manager email=null, plugin-chain-id=1, discover-server=null, data-owner-name=null, dismissal reason=null, last name=null, first name=null, phone=null, subject=http incident, sender email=null, userid=null, endpoint-user-name=null, endpoint-volume-name=null, discover-name=null, discover-content-root-path=null, data-owner-email=null, file-create-date=null, endpoint-application-name=null, employee code=null, region=null, manager first name=null, path=null, endpoint-application-path=null, manager last name=null, department=null, discover-location=null, protocol=http, resolution=null, file-owner=null, postal code=null, endpoint-file-path=null, title=null, discover-extraction-date=null, script-attribute=null, manager phone=null, file-created-by=null, file-owner-domain=nul 

and can assure can find by:

for line in sys.stdin:      if 'protocol' in line:          print "protocol found" 

any ideas or pointers on next step?

line_dict line in sys.stdin:     parts = line.split(",")     line_dict = dict(map(str.strip,part.split("=")) part in parts)     print line_dict['protocol'] 

to fair didnt test there may minor syntax errors want. if wanted protocol

import re line in sys.stdin:      if 'protocol' in line:          print re.findall("protocol\s*=([^,]*)",line) 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -