Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'definitions': 0.07; 'cc:addr:python-list': 0.09; '-1,': 0.09; '22,': 0.09; 'already.': 0.09; 'empty,': 0.09; 'port,': 0.09; 'output': 0.13; 'wed,': 0.15; 'correctly,': 0.16; 'dictionary,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'investigate': 0.16; 'luck!': 0.16; 'third,': 0.16; 'wrote:': 0.16; 'obviously': 0.16; "shouldn't": 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(the': 0.22; 'item.': 0.22; 'occurs': 0.22; 'parse': 0.22; 'am,': 0.23; 'seems': 0.23; 'header:In-Reply- To:1': 0.24; "i've": 0.25; "doesn't": 0.26; 'example': 0.26; 'subject:list': 0.26; 'message-id:@mail.gmail.com': 0.27; 'data,': 0.27; 'finally,': 0.27; "skip:' 10": 0.28; '(my': 0.29; 'objects': 0.29; "i'm": 0.30; 'that.': 0.30; 'skip:[ 10': 0.31; "i'd": 0.31; 'rules': 0.31; 'right?': 0.33; 'rule': 0.33; 'case,': 0.34; "skip:' 20": 0.34; 'handle': 0.34; 'previous': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'too': 0.36; 'list,': 0.36; 'skip:i 20': 0.36; 'should': 0.36; 'there': 0.36; 'subject:: ': 0.37; 'things': 0.38; 'doing': 0.38; 'data': 0.39; 'sure': 0.39; 'rather': 0.39; 'where': 0.40; 'some': 0.40; 'easy': 0.60; 'your': 0.60; "you'll": 0.61; 'skip:u 10': 0.61; 'here': 0.66; 'jul': 0.72; 'chrisa': 0.84; 'find.': 0.84; 'permit,': 0.84; 'source:': 0.84; 'start.': 0.84; 'to:none': 0.91; 'mean.': 0.91; 'ports': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=d/OeU/gx8yYV/plWYeH6yKyuhm+VqUmTX7B9cvO40Hg=; b=kvhFWCxauic0rLnftHWgjQ9STOm3uQqBz+AE88wLADMW+JM+sbFO7qNI1tO9vJayeg jyWJUy51i6FG51oCoV05r92toPGL5QsTIk5k/nV3NPiwmU+F8Rk+hl4Cdkab74xYMXKV PcxKnxqNtgoLGJv0Yysw97NGjaE9Mt6EGrSVOxa5hWmjCumpFBJuSHQjFxhYpL38lZ9T aubclkEQKC3/ARKQW7hzv+yTk4qw76AnZMTONfyACYPYWYOCAQ/dMRljpc7UuQUJzbHL GYw4xkfqKydfsmvsjOG9eKSC8XGWsGCoZBIyxGfmYLgLF7MuYLXOdMD6yqDLDvGAEKV4 oLLA== MIME-Version: 1.0 X-Received: by 10.50.142.67 with SMTP id ru3mr27479714igb.16.1437524747791; Tue, 21 Jul 2015 17:25:47 -0700 (PDT) In-Reply-To: References: Date: Wed, 22 Jul 2015 10:25:47 +1000 Subject: Re: convert output to list(and nested dictionary) From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437524756 news.xs4all.nl 2853 [2001:888:2000:d::a6]:49953 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.90.MISMATCH!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:94330 On Wed, Jul 22, 2015 at 7:12 AM, max scalf wrote: > SecurityGroup:default sg-e1304484 inbound: IPPermissions:tcp(80-80) source: [67.184.225.222/32] > >>>> > > > Here is the output i am looking for.... > > > rule1 = [{ > > 'cidr': '67.184.225.222/32', > > 'proto': 'tcp', > > 'port': 80 > > },{ So if I'm understanding you correctly, one line (from your previous iteration) will become one dictionary, right? In that case, start by figuring out how to parse that line and produce that output. In the example I've quoted, it should be pretty easy (the 'rule' seems to have your proto and port, and your 'rule.grants' has the cidr), but looking over your data, I see some snags. Firstly, some of your port numbers are None-None or -1--1, and I'm not sure what those mean. (My guess: None-None occurs only when proto is -1, and -1--1 happens when proto is icmp, which doesn't use port numbers. But you'd have to investigate that.) Also, your cidr might be a list, rather than a single item. What do you do if it's empty, or if it has multiple? Third, your ports are very obviously a range (1024-65535 comes up), so you'll need to handle that. And finally, some of those rules look like things I would permit, and some look like things I'd reject. You may need to look into the rule definitions to see what you can find. But the first thing to try would be to get hold of one of those rule objects and start doing some introspection; dir(rule) and help(rule) would be where I'd start. Good luck! This shouldn't be too hard; the data seems to be all there already. ChrisA