Tony has a problem. He has been charged with turning a stack of Python code into nice, shiny PHP. Now, I'm not one to trust a language that makes such a big deal out of white-space but having a style imposed on developers does have it's benefits. For one, the code is supposed to be more easily groked precisely because the reader only has one style to parse.

Still, it's been no picnic for Tony.

I didn't write the original non-documented, barely-commented code. I don't even know who did, so I employ a strategy of examining this code as well as its input and output. Once that starts making sense, I write a PHP function that does at least that and sometimes more. I'd like to share one exciting bit of code I came across during this process.
  for field in ('value',):
   if self.request().value(field, None):
     val = self.request().value(field, '')
     if val.upper()[:3] == 'RE:':
       conds.append("%s ~ '%s'" % (field, val[3:]))
     lors = val.upper().split(' OR ')

     for l in lors:
       d = {}
       d[field] = '%%%s%%' % '%'.join(l.replace("*","%").replace("?","_")
.replace("'","\\'").split()) if d: ors.append(d) print 'OROROROROROROROROROROR:',ors print 'OROROROROROROROROROROR:',[ y.items() for y in ors ] if ors: conds.append('(%s)' % ' OR '.join([ "upper(%s) LIKE upper('%s')"
% x.items()[0] for x in ors ])

 The only question Tony had was "What are the ORs for?!" Honestly, I have a few more questions than that, starting with "Why?"

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!