<file_sep>from re import sub

def psec( cfg, arg ):
  ### return option from cfg
  for c in cfg:
     c = str( c )
     if arg in c:
        c = str( c.split(':')[-1] ).strip()
        return c
  return



def pcfg( cfg, sec ):
  ### parse lines of cfg for section
  g = []
  x = 0

  for ln in cfg:
     ln = str( ln )

     if x == 1:
       if 'END' in ln:
          break

       else:
          ln = str( sub( '\n', '', ln ) ).strip()
          ln = str( sub( '  ', ' ', ln ) )
          ll = len( ln )

          if ll > 1:
             g.append( ln )

     if sec in ln:
         x = 1

  return g
<file_sep>#!/usr/bin/env python
### convert directory of images for b64css div template

from base64 import b64encode
from sys import argv, exit
from os import path, listdir, remove, getcwd
from re import sub


exist  = path.exists
join   = path.join
sep    = path.sep

def fatal( err ):
  err = str( 'FATAL :  %s' % err )
  print( err )
  exit(1)

def Usage():
  print('USAGE :  ./b64dir.py /image/directory /out/file.css')
  exit(1)

def crender( md, b6, ires ):
  ### css
  src= ''' div.%s {
    background:url(data:image/svg+xml;base64,%s);
    width: %spx; height: %spx;
    background-size: %spx %spx;
    background-repeat: no-repeat;
  }''' % ( md, b6, ires, ires, ires, ires )
  return src

def invertHex(hexNumber):
    #invert a hex number
    inverse = hex(abs(int(hexNumber, 16) - 255))[2:]
    # if the number is a single digit add a preceding zero
    if len(inverse) == 1:
        inverse = '0'+inverse
    return inverse


def colorInvert(hexCode):
    #define an empty string for our new colour code
    inverse = ""
    # if the code is RGB
    if len(hexCode) == 6:
        R = hexCode[:2]
        G = hexCode[2:4]
        B = hexCode[4:]
    # if the code is ARGB
    elif len(hexCode) == 8:
        A = hexCode[:2]
        R = hexCode[2:4]
        G = hexCode[4:6]
        B = hexCode[6:]
       # don't invert the alpha channel
        inverse = inverse + A
    else:
        # do nothing if it is neither length
        return hexCode
    inverse = inverse + invertHex(R)
    inverse = inverse + invertHex(G)
    inverse = inverse + invertHex(B)
    return inverse

def sixfo( img ):
  ### convert image to base64
  icn = open(img, 'rb')
  icondata = icn.read()

  nsvg = ''
  for line in icondata.split('\n'):
     line = str( line )
     if 'fill' in line:
        fill = str( line.split('#')[-1] )
        fill = str( fill.split('"')[0] )
        newf = colorInvert( fill )
        line = str(  sub( fill, newf, line ) )
        nsvg = str( '%s%s' % ( nsvg, line ) )
     else:
        nsvg = str( '%s%s' % ( nsvg, line ) )

  #  print(nsvg)
  #  print(icondata)
  icondata = b64encode(nsvg)
  return icondata

def pcss( fdir, ocss, mat, ires ):
  ### main, convert every image to b64 - stream output
  scss = ''
  if not fdir.startswith('/'):
    if exist( fdir ):
       cw   = str( getcwd() )
       fdir = str( join( sep, cw,  fdir ) )

  for itm in listdir( fdir ):
    itm = str( itm )
    if itm.endswith( mat ):
      fp = str( join( sep, fdir, itm ) )
      md = str( itm.split( mat )[0] )
      md = str( itm.split('.')[0] )
      b6 = str( sixfo( fp ) )
      cs = str( crender( md, b6, ires ) )

      ### Direct Stream From arg
      if ocss == '-v':
        scss = str( '%s\n%s' % ( scss, cs ) )

      else:
        a = open( ocss, 'a' )
        a.write( cs )
        a.write('')
        a.close()

  if ocss == '-v':
     return scss
  return

def carg( fdir, ocss ):
  ### check paths
  fdir = str( fdir )
  if exist( fdir ):
     if not listdir( fdir ):
       err  = str( 'cannot stat %s' % fdir )
       fatal( err )

  if ocss == '-v' :
     pass
  else:
     try:
       a = open( ocss, 'w' )
       a.write('')
       a.close()
     except:
       err = str( 'can not open %s for writing' % ocss )
       fatal( err )


def vert():
  mat  = 'svg'
  ires = '32'
  ocss = '-v'

  ### as argument
  la  = len( argv )
  if la < 2:
     Usage()

  ### input directory for images
  fdir = str( argv[1] )
  if la > 2:
     ### optional out css file
     ocss = str( argv[2] )

  carg( fdir, ocss )
  cssl = pcss( fdir, ocss, mat, ires )
  if ocss == '-v':
     for line in cssl.split('\n'):
        print( line )
  else:
     print( 'Contents of %s Converted to css file  %s'  % ( fdir, ocss ) )


def cvert(  fdir ):
  ### as method
  mat  = 'svg'
  ires = '32'
  ocss = '-v'
  carg( fdir, ocss )
  cssl = pcss( fdir, ocss, mat, ires )
  return cssl

if __name__ == "__main__":
  if len( argv ) > 0:
     vert()
<file_sep>from re import sub


def heads( raw, opt, proc=None ):

  def all():
     h = []
     for e in str( raw ).split('\n'):
       e = str( e )
       f = ''

       if ": " in e:
           f = str( e.split(': ')[0] )
           e = str( e.split(': ')[-1] )

       if proc:
         if proc in e:
           f = str( '%s ' % proc )
           e = str( sub( f, '', e ) )
           e = str( e.split(' ')[0] )
           f = str( 'METHOD:%s' % proc )

       if '\r' in e:
         e = str( sub( '\\r', '', e ) )

       g = [ f, e ]
       h.append( g )

     return h

  def item():
     for e in str( raw ).split('\n'):
       e = str( e )
       if '-' in e:
          if '_' in e:
            itm = str( e.split('=')[0] )
            id  = str( itm.split('_')[-1] )
            if len( id ) == 25:
               if id[0].isdigit():
                 return itm

  t = eval( opt )
  return t()


def headerz( raw, opt, proc=None ):
  raw   = str( raw )
  opt  = str( opt )
  hary  = heads( raw, opt, proc )
  return hary
<file_sep>from os import path, getcwd
from re import sub

join  = path.join
sep   = path.sep
exist = path.exists


def bxcss( clz ):
  src = '''\
section.prv button  { color: #fff; height: 20px: width: 10px; margin-right: 1;  margin-top: 5; background-color: #000000; text-shadow: -1px 1px #417cb8; border: none; }
.btn              { width: 25px; height: 25px; -webkit-transform: perspective(1px) translateZ(0); transform: perspective(1px) translateZ(0); -webkit-transition-duration: 0.1s; transition-duration: 0.1s; -webkit-transition-property: transform; transition-property: transform; }
.btn:hover        { -webkit-transform: scale(1.4); transform: scale(1.4); -webkit-transition-duration: 0.1s; transition-duration: 0.1s;  -webkit-transition-property: transform; transition-property: transform; js:click(); }

section.hvb button  { color: #fff; height: 20px: width: 10px; margin-right: 1;  margin-top: 5; background-color: #000000; text-shadow: -1px 1px #417cb8; border: none; }

'''


  for c in clz:
     c = str( c )
     src = str( '''%s\
section.c%s button  { color: #fff; height: 20px: width: 10px; margin-right: 1;  margin-top: 5; background-color: #%s; text-shadow: -1px 1px #417cb8; border: none; }
''' % ( src, c, c ) )

  return src


def bxhtml( clz ):
  x   = 1
  rt  = []
  src = ''

  row = 13
  cl  = len( clz )

  for c in clz:
     c   = str( c )
     #cl  = str( '#%s' % c )
     src = str( '''%s\
<section class="c%s"><button class="btn" onClick="reply_click('%s')" onmouseover="hv_over('%s')"> </button></section>
''' % ( src, c, c, c ) )

     if ( x % row == 0 ):
          rt.append( src )
          src = ''
          x = x + 1

     else:
       x = x + 1

  src = str( '''%s<section class="c000000"><button class="btn"  onClick="reply_click(c000000)"> </button></section>''' % src )
  rt.append( src )

  x   = 0
  src = '<div id="column"><div class = "blocks"><table>'

  for r in rt:
     r   = str( r )
     src = str( '%s<td>%s</td>' % ( src, r ) )
     x   = x + 1

  src = str( '''%s\n</table></div>''' % src )
  return src

def bxjsp():
  src = '''\
function reply_click( hv_clr )
{
   var ful = '#' + hv_clr
   document.getElementById( 'tinput' ).value = ful;
   document.getElementById( 'prv' ).style.backgroundColor = ful;
}

function hv_over( hv_clr )
{
  var ful = '#' + hv_clr
  document.getElementById( 'hvb' ).style.backgroundColor = ful;
}

 '''
  return src

def pclrs( fp ):
  ### parse file for hex colors, return as array
  clz = []

  if exist( fp ):
     a   = open( fp, 'r' )

     for ln  in a.readlines():
       ln = str( ln )
       ln = str( sub( '\n', '', ln ) )
       la = len( ln )

       if la == 7:
          if ln.startswith('#'):
            ln = str( sub( '#', '', ln ) )
            clz.append( ln )

  else:
     return

  return clz


def vym():

  cwd = str( getcwd() )
  dp  = str( join( sep, cwd, 'figc'  ) )
  fp  = str( join( sep, dp, 'safe.txt' ) )
  clz = pclrs( fp )

  if clz:
     cs  = str( bxcss( clz ) )
     h5  = str( bxhtml( clz ) )
     jsp = str( bxjsp() )
     src = str( '\n\n<style>%s</style><script>%s</script>\n\n%s' % ( cs, jsp, h5 ) )
     return src

  else:
    return str( '%s color config not found' % fp )
<file_sep>from random import choice, randrange
from string import ascii_lowercase, ascii_uppercase


def ranstr( sln ):
  ### return random string with a leading character

  upr = choice( ascii_uppercase )
  lwr = choice( ascii_lowercase )
  num = randrange( 0, 9)

  opt  = [ 'upr', 'lwr' ]
  opts = [ 'upr', 'lwr', 'num' ]

  ret = choice( opt )
  ret = str( eval( ret ) )

  for i in xrange( 1, sln ):
     t   = choice( opts )
     t   = eval( t )
     ret = str( '%s%s' % ( ret, t ) )

  return ret
<file_sep>

def sidebar():
  sbr = '''\
  .modalPage {
                position: absolute;
                font-family: Arial, Helvetica, sans-serif;
                top: 80;
                right: 0;
                bottom: 0;
                left: 40;
                margin-left:20;
                padding-left: 50;
                width: 505px;  height: 460px;
                background: rgba(0,0,0,0.8);
                z-index: 99999;
                opacity:0;
                border-radius: 25px;
                -webkit-transition: opacity 1s ease-in;
                -moz-transition: opacity 1s ease-in;
                transition: opacity 1s ease-in;
                pointer-events: none;
        }

        .modalPage:target {
                opacity:1;
                position: fixed;
                top: 80; left: 40; right: 0; bottom: 0;
                pointer-events: auto;
                width: 505px; height: 460px;
                border-radius: 25px;
        }

        .modalPage > div {
                margin-top: 30;
                top 80:
                left:5; right: 5;
                margin-top: 10;
                margin-right: 5;
                margin-left: 2;
                padding-left: 2;
                margin-bottom: 5;
                width: 530px;
                height: 440px;

                position: absolute;
                border-radius: 25px;
                background: -moz-linear-gradient(#fff, #999);
                background: -webkit-linear-gradient(#fff, #999);
                background: -o-linear-gradient(#fff, #999);
        }

  '''

  dbr = '''\
  .modalDialog {
                position: absolute;
                font-family: Arial, Helvetica, sans-serif;
                top: 80;
                right: 0;
                bottom: 0;
                left: 40;
                margin-left:20;
                padding-left:20;
                width: 265px;  height: 120px;
                background: rgba(0,0,0,0.8);
                z-index: 99999;
                opacity:0;
                border-radius: 25px;
                -webkit-transition: opacity 1s ease-in;
                -moz-transition: opacity 1s ease-in;
                transition: opacity 1s ease-in;
                pointer-events: none;
        }

        .modalDialog:target {
                opacity:1;
                position: fixed;
                top: 80; left: 40; right: 0; bottom: 0;
                pointer-events: auto;
                width: 265px; height: 120px;
                border-radius: 25px;
        }

        .modalDialog > div {
                margin-top: 30;
                top 80:
                left:5; right: 5;
                margin-top: 10;
                margin-right: 5;
                margin-left: 2;
                padding-left: 2;
                margin-bottom: 5;
                width: 265px;
                height: 100px;

                position: absolute;
                border-radius: 25px;
                background: -moz-linear-gradient(#fff, #999);
                background: -webkit-linear-gradient(#fff, #999);
                background: -o-linear-gradient(#fff, #999);
        }

  '''

  rbr = '''\
  .modalPopup {
                position: absolute;
                font-family: Arial, Helvetica, sans-serif;
                top: 80;
                right: 0;
                bottom: 0;
                left: 40;
                margin-left:5;
                padding-left:5;
                margin-top:4; padding-top:4;
                margin-bottom:4; padding-bottom:4;
                width: 390px;  height: 50px;
                background: rgba(0,0,0,0.8);
                z-index: 99999;
                opacity:0;
                border-radius: 25px;
                -webkit-transition: opacity 1s ease-in;
                -moz-transition: opacity 1s ease-in;
                transition: opacity 1s ease-in;
                pointer-events: none;
        }

        .modalPopup:target {
                opacity:1;
                position: fixed;
                top: 80; left: 40; right: 0; bottom: 0;
                pointer-events: auto;
                width: 410px; height: 95px;
                border-radius: 25px;
                padding-left:5;
                margin-left:5;
        }

        .modalPopup > div {
                top 80:
                left:5; right: 5;
                margin-right: 5;
                margin-left: 2;
                padding-left: 2;
                width: 390px;
                margin-top;5;
                margin-bottom:5;
                height: 50x;
                position: absolute;
                border-radius: 25px;
                background: -moz-linear-gradient(#fff, #999);
                background: -webkit-linear-gradient(#fff, #999);
                background: -o-linear-gradient(#fff, #999);
        }

  '''



  src = str( '%s\n\n%s\n\n%s' % ( sbr, dbr , rbr ) )
  return src
<file_sep># -*- coding: utf-8 -*-

from os import path
from re import sub

join  = path.join
sep   = path.sep
exist = path.exists



def psec( cfg, arg ):
  ### return option from cfg
  for c in cfg:
     c = str( c )
     if arg in c:
        c = str( c.split(':')[-1] ).strip()
        return c
  return



def pcfg( cfg, sec ):
  ### parse lines of cfg for section
  g = []
  x = 0

  for ln in cfg:
     ln = str( ln )

     if x == 1:
       if 'END' in ln:
          break

       else:
          ln = str( sub( '\n', '', ln ) ).strip()
          ln = str( sub( '  ', ' ', ln ) )
          ll = len( ln )

          if ll > 1:
             g.append( ln )

     if sec in ln:
         x = 1

  return g



def dbfg( lns, zf ):
  sec   = pcfg( lns, 'GENERAL' )
  kuid  = str( psec( sec, 'localuid' ) )
  kn    = str( psec( sec, 'kartname' ) )
  print(sec)
  print
  print(kuid)
  print
  print(kn)
  kdb  = str( '%s.db' % kuid )
  zdb  = str( join( sep, zf, kdb ) )
  if exist( zdb ):
     pass
  else:
     print( '%s does not exist!' % zdb  )
<file_sep># -*- coding: utf-8 -*-

from re import sub


def psec( cfg, arg ):
  ### return option from cfg
  for c in cfg:
     c = str( c )
     if arg in c:
        c = str( c.split(':')[-1] ).strip()
        return c
  return



def pcfg( cfg, sec ):
  ### parse lines of cfg for section
  g = []
  x = 0

  for ln in cfg:
     ln = str( ln )

     if x == 1:
       if 'END' in ln:
          break

       else:
          ln = str( sub( '\n', '', ln ) ).strip()
          ln = str( sub( '  ', ' ', ln ) )
          ll = len( ln )

          if ll > 1:
             g.append( ln )

     if sec in ln:
         x = 1

  return g



def cssc( cfg ):
  ### parse main css by section

  def headc( hic, tlc ):
     print(hic)
     src = '''\
div#header-wrapper {
    background-color: %s;
    font-color:yellow;
    width:100%%;       top:0;
    left:0;           right:0;
    height:66px;
}

body>div#header-wrapper {
    position:fixed;
    margin:0 auto;
    top:0; left:0;
    right:0;
}

div#header {
    height:66px;
    left:0; right:0;
    font-color: yellow;
    margin:0 auto;
    background-color: %s;
    color: %s;
    font-style: oblique;
    font-size: 36px;
    text-align: center;
    left: 15; right: 15;
}

''' % ( hic, hic, tlc )
     return src

  def contc( acc ):
     src = str( '''\
div#content-wrapper {
    margin-left:0; top:66;
    voice-family: "\\"}\\""; 
    voice-family:inherit;
    padding-bottom:0px;
    background-color: %s;
    position:absolute;
}

body>div#content-wrapper {
    margin-left:0;
    background-color: %s;
    margin:0 auto; left: 0;
    top:66; right: 0;
    height:25; width:670px;
    position:fixed;
}

div#content {
    width:720px;
    margin:0 auto;
    background-color: %s;
}
''' % ( acc, acc, acc ) )
     return src

  def footc( acc ):
     src = str( '''\
div#footerwrap {
    width:100%%;
    position:absolute;
    bottom:25; left:0;
    right:0; height:50px;
}

body>div#footerwrap {
   position:absolute;
   left:0; right:0;
}

div#footer {
    height:50px; bottom:0;
    left: 0; right: 0;
    margin:0 auto;
    font-style: oblique;
    color: yellow;
    font-size: 22px;
    text-align: center;
    background-color: %s;
    position:fixed;
}
''' % acc )
     return src

  def malc( prc ):
     src = str( '''\

div#maltent-wrapper {
    background-color: %s;
    font-color: yellow;
    width:100%%;
    top:66;  left:75;
    right:0; potision: absolute;
    height:100%%;
}

body>div#maltent-wrapper {
    margin-left:0; background-color: %s;
    margin:0 auto;
    left: auto; right:0;
    position:fixed right: 15;
    z-index: -3; top:0;
    bottom:auto; width:640px;
}

div#maltent {
    width:719px;
    font-color: yellow;
    margin:0 auto;
    background-color: %s;
    color: #ff0a00;
    font-style: oblique;
    font-size: 36px;
    text-align: center;
    left: 15; right:  15;
    top:   0; bottom: auto;
}
''' % ( prc, prc, prc ) )
     return src


  def glblc( txc, lkc ):
     ### instance or wrapper based css
     src = str('''\
\\a:link { color: %s;
  text-decoration: none; }
label {   color: %s; }
h1 { text-align: center; }


.column-left{ float: left; width: 33%%; margin-left:5; margin-top:5; }
.column-right{ float: right; width: 33%%; margin-top:5; }
.column-center{ display: inline-block; width: 33%%; }
.c-left{ float: left; width:43%%; margin-left:5;  line-height: 2.5; padding-top: 15; top: 15;}
.c-center{ left:50; top:0; padding-left: 25; display: inline-block; width: 33%%; line-height:0.4;}
.f-bottom{ float: bottom; bottom:5; }
.c-l{ float: left; width: 33%%; margin-left:5; margin-top:5; font-size: 135%%;}
.c-r{ float: right; width: 43%%; margin-top:5; }
.cr{ float: right; width: 0%%; top:0; display: inline-block;}
.i-l{ inline-block; top: 0; left: 0; right: 0;}

a:link {
  text-decoration: none;
}

a:visited {
  text-decoration: none;
}

a:active {
  text-decoration: none;
}


body {background-color: #69b543;}

div#wrapper {
  width: 100%%;
  right: 0;
  left: 75;
}

body>div#wrapper-wrapper {
    width: 730px;    top: 90;
    left: 0;    right: 0;
    position: fixed;
    border: 1px solid black;
}

/* from pages */
.close {
  background: #606061;  color: #FFFFFF;
    line-height: 25px;  position: absolute;
         right: -12px;  text-align: center;
           top: -10px;  width: 24px;
             display:   inline-block;
 text-decoration: none;  font-weight: bold;
  -webkit-border-radius: 12px;  -moz-border-radius: 12px;
          border-radius: 12px;   -moz-box-shadow: 1px 1px 3px #000;
  -webkit-box-shadow: 1px 1px 3px #000;  box-shadow: 1px 1px 3px #000;
}

.close:hover { background: #00d9ff; }

.closel {
  background: #606061;  color: #FFFFFF;
    line-height: 25px;  position: absolute;
         left: -12px;  text-align: center;
           top: -10px;  width: 24px;
            display; inline-block;
 text-decoration: none;  font-weight: bold;
  -webkit-border-radius: 12px;  -moz-border-radius: 12px;
          border-radius: 12px;   -moz-box-shadow: 1px 1px 3px #000;
  -webkit-box-shadow: 1px 1px 3px #000;  box-shadow: 1px 1px 3px #000;
}

.closel:hover { background: #00d9ff; }

.closem {
  background: #606061;  color: #FFFFFF;
    line-height: 25px;  position: relative;
         left: 0px;  text-align: center;
         right: auto; margin-left: 60px;
         margin-right: 60px;
           top: -12px;
            display; inline-block;
 text-decoration: none;  font-weight: bold;
  -webkit-border-radius: 12px;  -moz-border-radius: 12px;
          border-radius: 12px;   -moz-box-shadow: 1px 1px 3px #000;
  -webkit-box-shadow: 1px 1px 3px #000;  box-shadow: 1px 1px 3px #000;
}


/* buttons */
.styled-button-5 {
	background-color:#ed8223;
	color:#fff;
	font-family:'Helvetica Neue',sans-serif;
	font-size:18px;
	line-height:30px;
        margin-top: 12px;
        margin-left 12px;

	-webkit-border-radius:20px;
	-moz-border-radius:20px;
	border:2px solid #ed8223;
	text-shadow:#C17C3A 0 -1px 0;
	width:120px;
	height:32px;
        disaplay: inline;
}

.styled-button-5:hover {
  color:purple;
  text-decoration: none;
  border:2px solid purple;
}


/* highlight form */
.form-style-6 input[type="submit"], .form-style-6 input[type="button"] {
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    width: 100%%;
    margin-top:3; margin-bottom: 3;
    padding: 5%%;
    background: #43d1af;
    border-bottom: 2px solid #30c29e;
    border-top-style: none;
    border-right-style: none;
    border-left-style: none;
    color: #fff;
    font-size: 14px;
}

/* orange circle button */
h8 {
       margin-left: 0;  margin-right: 0;
        align: center;  text-align: center;
    font-weight: bold;  length: 35px;
   box-shadow:inset 2px 2px 2px 2px black;
              display:  inline;
             position: relative;
             overflow: hidden;
}

h5  {
    font-family: times;
    font-size: 50%%;
    display: inline;
    padding-left: 25px;
    padding-right: 25px;
    padding-top:0;
    margin-bottom:10px;
}

h2 {
  padding-bottom:0;
  display: inline-block;
}

''' % ( txc, lkc ) )
     return src

  ### define colors from cfg
  clr  = pcfg( cfg, 'COLOR' )

  icc  = str( psec( clr, 'icon-color' ) )
  prc  = str( psec( clr, 'primary-color' ) )
  acc  = str( psec( clr, 'accent-color' ) )
  hic  = str( psec( clr, 'highlight-color' ) ).encode('utf-8')
  lkc  = str( psec( clr, 'link-color' ) )
  txc  = str( psec( clr, 'text-color' ) )
  tlc  = str( psec( clr, 'title-color' ) )

  ### pass colors through css template
  head = str( headc( hic, tlc ) )
  cont = str( contc( acc ) )
  foot = str( footc( acc ) )
  mal  = str( malc( prc ) )
  glbl = str( glblc( txc, lkc ) )
  src  = str( '%s\n\n%s\n\n%s\n\n%s\n\n%s\n' % ( head, cont, foot, mal, glbl ) )

  return src
<file_sep>#!/usr/bin/env python
### convert directory of images for b64css div template

from base64 import b64encode
from sys import argv, exit
from os import path, listdir, remove, getcwd
from re import sub


exist  = path.exists
join   = path.join
sep    = path.sep


def psec( cfg, arg ):
  ### return option from cfg
  for c in cfg:
     c = str( c )
     if arg in c:
        c = str( c.split(':')[-1] ).strip()
        return c
  return



def pcfg( cfg, sec ):
  ### parse lines of cfg for section
  g = []
  x = 0

  for ln in cfg:
     ln = str( ln )

     if x == 1:
       if 'END' in ln:
          break

       else:
          ln = str( sub( '\n', '', ln ) ).strip()
          ln = str( sub( '  ', ' ', ln ) )
          ll = len( ln )

          if ll > 1:
             g.append( ln )

     if sec in ln:
         x = 1

  return g


def lrender( md, b6 ):
  ### css
  src= ''' div.%s {
    background:url(data:image/svg+xml;base64,%s);
    width: 280px; height: 32px;
    background-size: 280px 32px;
    background-repeat: no-repeat;
    top: 15; display: inline-block;
    padding-top: 15px; margin-top: 15px;

  }''' % ( md, b6 )
  return src


def trender( md, b6, ires ):
  ### css
  src= ''' div.%s {
    background:url(data:image/svg+xml;base64,%s);
    width: %spx; height: %spx;
    background-size: %spx %spx;
    background-repeat: no-repeat;
    top: 0; display: inline-block;
  }''' % ( md, b6, ires, ires, ires, ires )
  return src


def crender( md, b6, ires ):
  ### css
  src= ''' div.%s {
    background:url(data:image/svg+xml;base64,%s);
    width: %spx; height: %spx;
    background-size: %spx %spx;
    background-repeat: no-repeat;
  }''' % ( md, b6, ires, ires, ires, ires )
  return src

def invertHex(hexNumber):
    #invert a hex number
    inverse = hex(abs(int(hexNumber, 16) - 255))[2:]
    # if the number is a single digit add a preceding zero
    if len(inverse) == 1:
        inverse = '0'+inverse
    return inverse


def colorInvert(hexCode):
    #define an empty string for our new colour code
    inverse = ""
    # if the code is RGB
    if len(hexCode) == 6:
        R = hexCode[:2]
        G = hexCode[2:4]
        B = hexCode[4:]
    # if the code is ARGB
    elif len(hexCode) == 8:
        A = hexCode[:2]
        R = hexCode[2:4]
        G = hexCode[4:6]
        B = hexCode[6:]
       # don't invert the alpha channel
        inverse = inverse + A
    else:
        # do nothing if it is neither length
        return hexCode
    inverse = inverse + invertHex(R)
    inverse = inverse + invertHex(G)
    inverse = inverse + invertHex(B)
    return inverse

def sixfo( img, icc ):
  ### convert image to base64
  icc = str( icc.split('#')[-1] )
  icn = open(img, 'rb')
  icondata = icn.read()


  nsvg = ''
  for line in icondata.split('\n'):
     line = str( line )
     if 'fill' in line:
        fill = str( line.split('#')[-1] )
        fill = str( fill.split('"')[0] )
#        icc = colorInvert( fill )
        line = str(  sub( fill, icc, line ) )
        nsvg = str( '%s%s' % ( nsvg, line ) )
     else:
        nsvg = str( '%s%s' % ( nsvg, line ) )

  #  print(nsvg)
  #  print(icondata)
  icondata = b64encode(nsvg)
  return icondata

def pcss( fdir, mat, ires, cfg ):
  ### main, convert every image to b64 - stream output
  scss = cs = ''
  clr  =  pcfg( cfg, 'COLOR' )
  icc  =  str( psec( clr, 'icon-color' ) )

  if not fdir.startswith('/'):
     if exist( fdir ):
       cw   = str( getcwd() )
       fdir = str( join( sep, cw,  fdir ) )

  for itm in listdir( fdir ):
     itm = str( itm )

     if itm.endswith( mat ):
       fp = str( join( sep, fdir, itm ) )
       md = str( itm.split( mat )[0] )
       md = str( itm.split('.')[0] )
       b6 = str( sixfo( fp, icc ) )


       if fdir.endswith( 'sidebar' ):
          cs = str( crender( md, b6, ires ) )

       if fdir.endswith( 'topbar' ):
          cs = str( trender( md, b6, ires ) )

       if fdir.endswith( 'ttl' ):
          cs = str( lrender( md, b6 ) )


       ### Direct Stream From arg
       scss = str( '%s\n\n%s' % ( scss, cs ) )

  return scss

def carg( fdir, ocss ):
  ### check paths
  fdir = str( fdir )
  if exist( fdir ):
     if not listdir( fdir ):
       err  = str( 'cannot stat %s' % fdir )
       fatal( err )


def cvert(  fdir, cfg ):
  ### as method
  mat  = 'svg'
  ires = '32'
  cssl = pcss( fdir, mat, ires, cfg )
  return cssl

#if __name__ == "__main__":
 # if len( argv ) > 0:
 #    vert()
<file_sep>This is my intro to SVGs.  Template based CGI configuration.  Reads through SVG files to dynamically change at the moment color, but size is the easy next step.  I also wrote a color wheel for this which I am quite proud of. CSS HTML, JS, and CGI based logic.
<file_sep>from . import dbfg
<file_sep># -*- coding: utf-8 -*-

#TODO:  OS-SPECIFIC < AGNOSTIC
#TODO:  TMP/static conf file? tmpfs/ram
#TODO:  Remote Backup/Restore cf.db
#TODO:  Windows compatable paths

from os     import environ, path, listdir, mkdir
from random import choice, randrange
from string import ascii_lowercase, ascii_uppercase

exist = path.exists
join  = path.join
sep   = path.sep

hdir  = environ['HOME']


def ranstr( sln ):
  ### return random string with a leading character
  ### for kart uuid
  upr = choice( ascii_uppercase )
  lwr = choice( ascii_lowercase )
  num = randrange( 0, 9)

  opt  = [ 'upr', 'lwr' ]
  opts = [ 'upr', 'lwr', 'num' ]

  ret = choice( opt )
  ret = str( eval( ret ) )

  for i in xrange( 1, sln ):
     t   = choice( opts )
     t   = eval( t )
     ret = str( '%s%s' % ( ret, t ) )

  return ret


def dcf( kuid ):
  ### default config
  ### TODO: list parsable uri's as resource

  ret = str( ''' \
### COLOR START

  icon-color:      #69b543
  primary-color:   #664b4b
  accent-color:    #7d8182
  highlight-color: #272c2e
  link-color:      yellow
  text-color:      purple
  title-color:     red

### COLOR END


### RES SMALL START

  width:           640
  height:          580
  icon-size:       32

### RES SMALL END


### RESOURCE START

  sidebar-icons:bins/icn/sidebar
  sync:local
  #sync:imgur


### RESOURCE END


### GENERAL START

   kartname:      MyKart
   localuid:      %s

### GENERAL END
''' % kuid )

  return ret


def cdir():
  ### locate-create-return work dir

  if exist( hdir ):
     ret = str( join( sep, hdir, '.zkart' ) )
     zdb = str( join( sep, ret, 'zdb' ) )

     for z in [ ret, zdb ]:
        z = str( z )
        if exist( z ):
          return z

        else:
          try:
             mkdir( z )

          except:
             return

     return ret
  return


def cfp():
  ### locate-create-return conf file

  if cdir():
     dp  = str( cdir() )
     ret = str( join( sep, dp, 'zkart.cfg' ) )
     if exist( ret ):
       return ret

     else:
       try:
          kuid = str( ranstr( 8 ) )
          cfg  = str( dcf( kuid ) )
          fd   = open( ret, 'w' )
          fd.write( cfg )
          fd.close()
          return ret

       except:
          return
  return
<file_sep>from . import jscr
<file_sep>from . import pcfg

psec = pcfg.psec
pcfg = pcfg.pcfg

def spages( lns, whl ):

  def pnew():
     src = ''' \
<div id="newp" class="modalPage"><div>
  <a href="#close" title="Close" class="close">X</a>

  <form action="#" enctype="multipart/form-data">
     <div class="c-left">
     <div>TITLE:    <br></div>
     <div>CATEGORY: <br></div>
     <div>DESCRIPTION: <br><br><br><br></div>
     <div>PRICE:    <br></div>
     <div>PIECESPR: <br></div>
     <div>QUANTITY: <br></div>



    <div class="f-bottom">
           <input type="submit" class="styled-button-5" id="newitem" name="newitem" value="Commit" data="dtails" action="#"/>
    </form></div>

     </div>
      <div class="c-center"><div class="form-style-6">
 <div><input type="text" name="title"><br><br></div>
 <div><input type="text" name="category"><br><br></div>
 <div><textarea name="description" rows="10" cols="30" resize="none"> DESCRIPTION</textarea><br><br></div>
 <div><input type="text" name="price"><br><br></div>
 <div><input type="text" name="pcspr" value="1"><br><br></div>
 <div><input type="text" name="totalq" value="unlimited"><br><br></div>

</div></div></div></div>

'''
     return src


  def pcal():
     src = ''' \
<div id="calp" class="modalPage"><div>
  <a href="#close" title="Close" class="close">X</a>

  <h2>Calender Box</h2>
   <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  <p>You could do a lot of things here like have a pop-up ad that shows when your></p>

</div></div>

'''
     return src


  def pitm():
     src = ''' \
<div id="itmp" class="modalPage"><div>
  <a href="#close" class="close">X</a>

  <h2>Items Box</h2>

  <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  <p>You could do a lot of things here like have a pop-up ad that shows when your></p>

</div></div>

'''
     return src


  def pmet():
     src = ''' \
<div id="metp" class="modalPage"><div>
  <a href="#close" class="close">X</a>

  <h2>Metric Box</h2>
  <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  <p>You could do a lot of things here like have a pop-up ad that shows when your></p>

</div></div>

'''
     return src

  def pord():
     src = ''' \

<div id="ordp" class="modalPage"><div>
  <a href="#close" title="Close" class="close">X</a>

  <h2>Orders Box</h2>
  <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  <p>You could do a lot of things here like have a pop-up ad that shows when your></p>

</div></div>

'''
     return src


  def ppic():
     src = ''' \
<div id="picp" class="modalPage"><div>
  <a href="#close" title="Close" class="close">X</a>

  <h2>Picture Box</h2>
  <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  <p>You could do a lot of things here like have a pop-up ad that shows when your></p>

</div></div>

'''
     return src


  def ppri():
     src = ''' \
<div id="prip" class="modalPage"><div>
  <a href="#close" title="Close" class="close">X</a>

  <h2>Pricing Box</h2>
  <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  <p>You could do a lot of things here like have a pop-up ad that shows when your></p>

</div></div>

'''
     return src


  def dbse():
     src = ''' \
<div id="database" class="modalPage"><div>
  <a href="#confp" class="close">&lt;</a>
  <a href="#close" class="closel">X</a>

  <h2>Database Box</h2>
  <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  <p>You could do a lot of things here like have a pop-up ad that shows when your></p>

</div></div>

'''
     return src


  def crdz():
     src = ''' \
<div id="creds" class="modalPage"><div>
  <a href="#confp" class="close">&lt;</a>
  <a href="#close" class="closel">X</a>

  <h2>Creds  Box</h2>
  <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  <p>You could do a lot of things here like have a pop-up ad that shows when your></p>

</div></div>

'''
     return src


  def imgz():
     src = ''' \
<div id="images" class="modalPage"><div>
  <a href="#confp" class="close">&lt;</a>
  <a href="#close" class="closel">X</a>

  <h2>images Box</h2>
  <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  <p>You could do a lot of things here like have a pop-up ad that shows when your></p>

 </div></div>

'''
     return src


  def userz():
     src = ''' \
<div id="userz" class="modalPage"><div>
  <a href="#confp" class="close">&lt;</a>
  <a href="#close" class="closel">X</a>

  <h2>Users Box</h2>
   </center><h5><hr =""\></h5><br>

  <select id="uzern">
  <option> Rahoul Utilizator</option>
  </select>      <a id="plusmin"  href="#plusmin"><div class="plusmin" onclick="rmin('uzr')"></div></a>


</div></div>

'''
     return src


  def lgz():
     src = ''' \
<div id="logs" class="modalPage"><div>
  <a href="#confp" class="close">&lt;</a>

  <h2>Logs Box</h2>
  <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  <p>You could do a lot of things here like have a pop-up ad that shows when your></p>
</div></div>

'''
     return src


  def hlp():
     src = ''' \
<div id="help" class="modalPage"><div>
  <a href="#confp" class="close">&lt;</a>

  <h2>Help Box</h2>
  <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  <p>You could do a lot of things here like have a pop-up ad that shows when your></p>

</div></div>

'''
     return src


  def pcnf():
     src = ''' \
<div id="confp" class="modalPage"><div>
  <a href="#close" class="close">X</a><br><center>

      <a id="paint"     href="#pntp">     <div class="paint">    </div></a>
      <a id="database"  href="#database"> <div class="database"> </div></a>
      <a id="creds"     href="#creds">    <div class="lock">     </div></a>
      <a id="images"    href="#images">   <div class="images">   </div></a>
      <a id="userz"     href="#userz">    <div class="userz">     </div></a>
      <a id="logs"      href="#logs">     <div class="logs">     </div></a>
      <a id="help"      href="#help">     <div class="help">     </div></a>

  </center><h5><hr =""\></h5><br>

<select id="kartn">
 <option> MyKart</option>
</select>      <a id="plusmin"  href="#plusmin"><div class="plusmin" onclick="rmin('krt')"></div></a>


</div></div>

'''
     return src

  def ppnt( clr ):
     icr = str( psec( clr, 'icon-color' ) )
     lcr = str( psec( clr, 'link-color' ) )
     pcr = str( psec( clr, 'primary-color' ) )
     acr = str( psec( clr, 'accent-color' ) )
     hcr = str( psec( clr, 'highlight-color' ) )
     txt = str( psec( clr, 'text-color' ) )
     ttl = str( psec( clr, 'title-color' ) )

     syl = str('''\
     <style>
section.icrx button  { color: #fff; height: 20px: width: 10px; margin-right: 1;  margin-top: 5; background-color: %s; text-shadow: -1px 1px #417cb8; border: none; }
section.lcrx button  { color: #fff; height: 20px: width: 10px; margin-right: 1;  margin-top: 5; background-color: %s; text-shadow: -1px 1px #417cb8; border: none; }
section.pcrx button  { color: #fff; height: 20px: width: 10px; margin-right: 1;  margin-top: 5; background-color: %s; text-shadow: -1px 1px #417cb8; border: none; }
section.acrx button  { color: #fff; height: 20px: width: 10px; margin-right: 1;  margin-top: 5; background-color: %s; text-shadow: -1px 1px #417cb8; border: none; }
section.hcrx button  { color: #fff; height: 20px: width: 10px; margin-right: 1;  margin-top: 5; background-color: %s; text-shadow: -1px 1px #417cb8; border: none; }
section.txtx button  { color: #fff; height: 20px: width: 10px; margin-right: 1;  margin-top: 5; background-color: %s; text-shadow: -1px 1px #417cb8; border: none; }
section.ttlx button  { color: #fff; height: 20px: width: 10px; margin-right: 1;  margin-top: 5; background-color: %s; text-shadow: -1px 1px #417cb8; border: none; }

     </style>
''' % ( icr, lcr, pcr, acr, hcr, txt, ttl ) )

     src = str( ''' \
<div id="pntp" class="modalPage"><div>
  <a href="#confp" class="close">&lt;</a>
  <a href="#close" class="closel">X</a>
  <h2>Color Box</h2>


  <div class="c-l"><br>
  <section class="icrx"><button id="icrb" class="btn" onclick="window.location.href='#whlp'; sselect('icri')">&nbsp;</button> ICON      </section>
  <section class="pcrx"><button id="pcrb" class="btn" onclick="window.location.href='#whlp'; sselect('pcri')">&nbsp;</button> PRIMARY   </section>
  <section class="acrx"><button id="acrb" class="btn" onclick="window.location.href='#whlp'; sselect('acri')">&nbsp;</button> ACCENT    </section>
  <section class="hcrx"><button id="hcrb" class="btn" onclick="window.location.href='#whlp'; sselect('hcri')">&nbsp;</button> HIGHLIGHT </section>
  <section class="lcrx"><button id="lcrb" class="btn" onclick="window.location.href='#whlp'; sselect('lcri')">&nbsp;</button> LINK      </section>
  <section class="txtx"><button id="txtb" class="btn" onclick="window.location.href='#whlp'; sselect('txti')">&nbsp;</button> TEXT      </section>
  <section class="ttlx"><button id="ttlb" class="btn" onclick="window.location.href='#whlp'; sselect('ttli')">&nbsp;</button> TITLE     </section>
  </div>


  <div class="c-r"><form action="#">
  <input name="iconc"  type="text" id="icri" value="%s"></input>
  <input name="primec" type="text" id="pcri" value="%s"></input>
  <input name="acrc"   type="text" id="acri" value="%s"></input>
  <input name="highc"  type="text" id="hcri" value="%s"></input>
  <input name="lcrc"   type="text" id="lcri" value="%s"></input>
  <input name="txtc"   type="text" id="txti" value="%s"></input>
  <input name="ttlc"   type="text" id="ttli" value="%s"></input>

  <br><pre>paint stuff
  <input type="submit" class="styled-button-5" id="saveclr" name="saveclr" value="SaveClr" /></form></div>
  <input id="cslct" type="hidden"></input>
</div></div>

''' % ( icr, pcr, acr, hcr, lcr, txt, ttl ) )

     src = str( '%s\n%s' % ( syl, src ) )
     return src

  def pwhl( whl ):
     src = ''' \
<div id="whlp" class="modalPage"><div>
  <a href="#pntp"  class="close"  > &lt; </a>
  <a href="#close" class="closel" > X    </a>
  %s

  <section onclick="window.location.href='#pntp'; setcc();"><center>
  <button>SET</button>&emsp;<button class="btn" id="prv" onclick="window.location.href='#pntp'; setcc();"></button>
  <input type="text" id="tinput" value="wtf"></input>
  <button class="btn" id="hvb"></button>
  &emsp;<button>ADD^</button></center>

</section>
</div></div>

''' % whl
     return src


  def pmn():
     src = ''' \
<div id="plusmin"   class="modalDialog"><div>
  <a href="#userz"  class="close">&lt;</a>
  <a href="#close"  class="closel">X</a>
  <div class="i-l">

  <a href="#umit">
     <input type="submit" class="styled-button-5"  id="unew"     name="NEW"     value="NEW"    onclick="fjava('uname');"   >
     <input type="submit" class="styled-button-5"  id="urename"  name="RENAME"  value="RENAME" onclick="fjava('urename');" >
     <input type="submit" class="styled-button-5"  id="ucopy"    name="COPY"    value="COPY"   onclick="fjava('ucopy');"   >
     <input type="submit" class="styled-button-5"  id="udelete"  name="DELETE"  value="DELETE" onclick="fjava('udelete');" ></a>
  </div></div></div>

</div></div></div>

'''
     return src

  def pmr():
     src = ''' \
<div id="umit" class="modalPopup"><div>
  <a href="#plusmin" class="close">&lt;</a>
  <a href="#close" class="closel">X</a>
   <div class="closem">POOP</div>
     <div class="i-l">
     <form style="{display: inline-block}">
         &nbsp;<input type="text"   id="urin" name="urin" value="">&nbsp;
               <input type="hidden" id="uref" name="uref" value="">
               <input type="text"   id="refu" name="refu" value="">
               <input type="submit" class="styled-button-5"  value="Commit" >
      </form></input></intput></input>

</div></div></div>

'''
     return src



  ### main
  clr = pcfg( lns, 'COLOR' )

  pn  = str( pnew() )
  pc  = str( pcal() )
  pi  = str( pitm() )
  pm  = str( pmet() )
  po  = str( pord() )
  pp  = str( ppic() )
  pr  = str( ppri() )
  pf  = str( pcnf() )
  pt  = str( ppnt( clr ) )
  pw  = str( pwhl( whl ) )
  db  = str( dbse() )
  cd  = str( crdz() )
  ig  = str( imgz() )
  uz  = str( userz() )
  lg  = str( lgz() )
  hp  = str( hlp() )
  pd  = str( pmn() )
  pz  = str( pmr() )

  src = str( '%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s' % ( pd, pn, pz, pc, pi, pm, po, pp, pr, db, cd, ig, uz, lg, hp, pf, pt, pw ) )
  return src
<file_sep>import webapp2

#from metric.header import headerz





class MainPage(webapp2.RequestHandler):
  def do( self, proc ):
     raw  = self.request
     proc = str( proc )

     HTML = '<html><body>mwahaha</body></hmtl>'

     self.response.headers['Content-Type'] = 'text/html'
     self.response.write(HTML)


  def post( self, proc=None ):
     self.do('POST')

  def get( self, proc=None ):
     self.do('GET')



app = webapp2.WSGIApplication([
    ( '/', MainPage,),
], debug=True,)
<file_sep>#!/usr/bin/python

from binascii import hexlify

import pyelliptic

# Symmetric encryption
iv = pyelliptic.cipher.gen_IV('aes-256-cfb')
ctx = pyelliptic.cipher("secretkey", iv, 1, ciphername='aes-256-cfb')

ciphertext = ctx.update('test1')
ciphertext += ctx.update('test2')
ciphertext += ctx.final()

ctx2 = pyelliptic.Cipher("secretkey", iv, 0, ciphername='aes-256-cfb')
print(ctx2.ciphering(ciphertext))

# Asymmetric encryption
alice = pyelliptic.ECC() # default curve: sect283r1
bob = pyelliptic.ECC(curve='sect571r1')

ciphertext = alice.encrypt("Hello Bob", bob.get_pubkey(),
                           ephemcurve='sect571r1')
print(bob.decrypt(ciphertext))

signature = bob.sign("Hello Alice")
# alice's job :
print(pyelliptic.ECC(pubkey=bob.get_pubkey(),
                     curve='sect571r1').verify(signature, "Hello Alice"))

# ERROR !!!
try:
    key = alice.get_ecdh_key(bob.get_pubkey())
except:
    print("For ECDH key agreement, the keys must be defined on the same curve !")

alice = pyelliptic.ECC(curve='sect571r1')
print(hexlify(alice.get_ecdh_key(bob.get_pubkey())))
print(hexlify(bob.get_ecdh_key(alice.get_pubkey())))
<file_sep># -*- coding: utf-8 -*-

### Handles dynamic variables of cgi runtime such as headers


from . import header
<file_sep># -*- coding: utf-8 -*-
#from pcfg import pcfg

def rcfg( fd, spec=None ):
  ### parse descriptor, return cfg options

  def popt( line ):
     ### split line, return deliminator
     opt = str( line.split(':')[0] ).strip()
     arg = str( line.split(':')[-1] ).strip()
     return opt, arg

  def cres( sg ):
     ### match resolution options, from cfg segment

     width  = height = isize = None

     for line in sg.split('\n'):
        line = str( line )
        line = popt( line )
        opt  = str( line[0] )
        arg  = str( line[1] )

        if opt == 'width':
          width = arg
        if opt == 'height':
          height = arg
        if opt == 'icon-size':
          isize =  arg

     return  width, height, isize


  def crec( sg ):
     ### parse resources, images, uris, etc
     isbr = ''

     for line in sg.split('\n'):
       line = str( line )
       line = popt( line )
       opt  = str( line[0] )
       arg  = str( line[1] )

       if opt == 'sidebar-icons':
          isbr = arg

     return isbr

  def clr( sg ):
     ### return color options from cfg
     ### icon - link - primary - accent - highlight {-color}
     iclr = lclr = pclr = aclr = hclr = None

     for line in sg.split('\n'):
        line = str( line )
        line = popt( line )
        opt  = str( line[0] )
        arg  = str( line[1] )

        if opt == 'icon-color':
          iclr = arg
        if opt == 'link-color':
          lclr = arg
        if opt == 'primary-color':
          pclr = arg
        if opt == 'accent-color':
          aclr = arg
        if opt == 'highlight-color':
          hclr =  arg

     return iclr, lclr, pclr, aclr, hclr


  ### main
  lines = ''

  if not spec:
     spec ='SMALL'

  if type(fd) == list:
     for f in fd:
       f     = str( f )
       lines = str( '%s\n%s' % ( lines, f ) )
  else:
     lines = fd

  sg   = str( lines.split( '### RES %s START' % spec )[-1] )
  sg   = str( sg.split( '### RES %s END' % spec )[0] )

  ### this preset cfg should already be loaded
  if len( sg ) < 4:
     return

  sz   = cres( sg )

  sg   = str( lines.split( '### COLOR START' )[-1] )
  sg   = str( sg.split( '### COLOR END' )[0] )

  if len( sg ) < 4:
     return

  cl   = clr( sg )

  sg   = str( lines.split( '### RESOURCE START' )[-1] )
  sg   = str( sg.split( '### RESOURCE END' )[0] )

  rc   = crec( sg )

  return sz, cl, rc


#f = open('/media/.zkart/zkart.cfg','r')
#h = f.readlines()
#j = rcfg( h )

#from pcfg import pcfg, psec
#k = pcfg( h, 'COLOR' )
#ic = psec( k, 'icon-color' )
#print(ic)
<file_sep>from re import sub


def pcfg( cfg, sec ):
  ### parse lines of cfg for section
  g = []
  x = 0

  for ln in cfg:
     ln = str( ln )

     if x == 1:
       if 'END' in ln:
          break

       else:
          ln = str( sub( '\n', '', ln ) ).strip()
          ln = str( sub( '  ', ' ', ln ) )
          ll = len( ln )

          if ll > 1:
             g.append( ln )

     if sec in ln:
         x = 1

  return g



def tsec( sec ):
  ### trim section to add alterd
  new  = []
  cfsn = [ 'COLOR', 'RES SMALL', 'RESOURCE' ]

  for c in cfsn:
     c = str( c )

     if c == sec:
       pass

     else:
       new.append( c )

  return new


def upcfg( new, sec, cur ):
  ### overwrite cfg: new 2 section 2 current 2 file


  def colr(  new ):
     ovr  = icc = prc = acc = hlc = lkc = txc = tlc  = ''

     for arg in new.split( '&' ):
       arg = str( arg )

       if '%' in arg:
          arg = str( sub( '%23', '#', arg ) )

       opt = str( arg.split('=')[-1] )

       if arg.startswith( 'iconc' ):
          icc = opt
       if arg.startswith( 'primec' ):
          prc = opt
       if arg.startswith( 'acrc' ):
          acc = opt
       if arg.startswith( 'highc' ):
          hlc = opt
       if arg.startswith( 'lcrc' ):
          lkc = opt
       if arg.startswith( 'txtc' ):
          txc = opt
       if arg.startswith( 'ttlc' ):
          tlc = opt

     ovr = str( '''### COLOR START\n\nicon-color: %s\nprimary-color: %s\naccent-color: %s\n
highlight-color: %s\nlink-color: %s\ntext-color: %s\ntitle-color: %s\n\n### COLOR END''' % ( icc, prc, acc, hlc, lkc, txc, tlc ) )
     return ovr



  ### add unalterd section to new
  ret  = ''
  x    = 1
  unlt = tsec( sec )

  if sec  == 'COLOR':
     ovr = colr( new )

  for c in unlt:
     c   = str( c )
     cfs = pcfg( cur, c )
     lc  = len( cfs )

     for f in cfs:
       f = str( f )

       if x == 1:
          ret = str( '%s### %s START\n' % ( ret, c) )

       ret = str( '%s\n%s' % ( ret, f ) )

       if x == lc:
          ret = str( '%s\n\n### %s END\n\n' % ( ret, c ) )
          x   = 1

       else:
          x = x + 1

  ret = str( '%s\n\n%s' % ( ret, ovr ) )

  return ret
<file_sep># -*- coding: utf-8 -*-

from os import getcwd, path

from wsgiref.util import setup_testing_defaults
from wsgiref.simple_server import make_server

from metric.header import headerz

from figc.cenv     import cfp
from figc.chrt     import vym
from figc.upcfg    import upcfg

from cssc.cssc     import cssc
from cssc.b64dir   import cvert
from cssc.sbar     import sidebar

from magik.jscr    import jscr

from httpc.spage   import spages
from httpc         import webc

from sql.dbfg      import dbfg

webc  = webc.webc
join  = path.join
sep   = path.sep


def read(environ):
    length = int(environ.get('CONTENT_LENGTH', 0))
    stream = environ['wsgi.input']
    body   = TemporaryFile( mode='w+b' )

    while length > 0:
        part = stream.read(min(length, 1024*200)) # 200KB buffer size
        if not part: break
        body.write( part )
        length -= len( part )
    body.seek(0)
    environ['wsgi.input'] = body
    return body


def zkart( environ, start_response ):
  setup_testing_defaults(environ)
  cf   = str( cfp() )
  zf   = str( join( sep, cf, 'zdb' ) )
  cwd  = str( getcwd() )
  bins = str( join( sep, cwd, 'bins' ) )
  icn  = str( join( sep, bins, 'icn' ) )
  bmp  = str( join( sep, bins, 'bmp' ) )
  tlb  = str( join( sep, bmp, 'ttl' ) )
  sbr  = str( join( sep, icn, 'sidebar' ) )
  tbr  = str( join( sep, icn, 'topbar' ) )

  qstring = None

  cfd = open( cf, 'r' )
  lns = cfd.readlines()
  cfd.close()

  zfg = dbfg( lns, zf )

  try:
     req_page  = str( environ['PATH_INFO'] )
     method    = str( environ['REQUEST_METHOD'] )
     rhost     = str( environ['REMOTE_HOST'] )

  except:
      return '<html><body>bad juju</body></hmtl>'

  try:
     qstring   = str( environ['QUERY_STRING'] )

  except:
      pass

  if qstring:
     if qstring.endswith( 'SaveClr' ):

       ncf     = upcfg( qstring, 'COLOR', lns )

       a = open( cf, 'w' )
       a.write( ncf )
       a.close()

       cfd     = open( cf, 'r' )
       lns     = cfd.readlines()
       cfd.close()


##### parse image on post todo: change qstring, add method
#  if 'title' in qstring:


#  try:
#       body    = read(environ)
#       print(body)
#       path    = FieldStorage(fp=body, environ=environ, keep_blank_values=True)
#       title   = str( path )
#       print( title )
      # title   = str( title.split("dtails', '")[-1] )
      # title   = str( title.split(",")[0] )
      # path    = path["dtails"].value
      # print(path)
#  except:
#        pass


  ### CSS
  cbar = str( cvert( sbr, lns ) )
  tbar = str( cvert( tbr, lns ) )
  tlc  = str( cvert( tlb, lns ) )
  csc  = str( cssc( lns ) )
  csp  = str( sidebar() )
  cs   = str( '%s\n%s\n%s\n%s\n%s\n' % ( cbar, tbar, tlc, csc, csp ) )

  ### JAVA
  jsp  = str( jscr() )

  ### HTML
  whl  = str( vym() )
  body = str( webc( 'body', '/', environ ) )
  pgs  = str( spages( lns, whl ) )

  ### Return Response
  html           = str( '<html><head><style>%s</style><script>%s</script></head><body>%s\n%s</body></html>' % ( cs, jsp, body, pgs ) )

  headers        = [ ('Server', 'ZenKart-0.0.0'),('Content-type', 'text/html'),( 'charset','utf-8') ]
  status         = '200 OK'

  start_response( status, headers )
  return html



def phew():
  try:
     from sys import argv
     port        = int( argv[1] )
  except:
     port        = 8080

  httpd          = make_server('127.0.0.1', port, zkart )


  print( "Accepting on port %d" % port )
  httpd.serve_forever()
  con.close()

phew()
<file_sep># -*- coding: utf-8 -*-

def webc( mthd, pth, vars=None ):
  ### parse mathod, path, vars, return html

  ### bounds
  if pth:
     mthd = str( mthd )
     pth  = str( pth )
  else:
     return


  def body( head ):
     html = str( '''\
<div id="header-wrapper"><div id="header">
  <center><div class="zkart"/></center>
</div></div>

<div id="content-wrapper" >
  <a id="users"     href="#entance"><div class="user"> </a></div>
</div>

<div id="maltent-wrapper" ><br><br><br>
<br><br><div><div class="column-left"><br>
  <a id="new"      href="#newp"><div class="new"></div></a><br>
  <a id="calender" href="#calp"><div class="calender"></div></a><br>
  <a id="items"    href="#itmp"><div class="items"></div></a><br>
  <a id="metrics"  href="#metp"><div class="metrics"></div></a><br>
  <a id="ordering" href="#ordp"><div class="ordering"></div></a><br>
  <a id="pictures" href="#picp"><div class="pictures"></div></a><br>
  <a id="pricing"  href="#prip"><div class="pricing"></div></a><br>
</div></div>
<div class="column-center">
mooo<br>%s<br><br><br><br>

</div>
<div class="column-right"></div>

<!--
<div id="wrapper">
  <form action="/" method="post" type="image" class="bi"><div class="bi"></div></form>

  <br><br><br><br>-->
  <div id="footerwrap"><div id="footer">
   <div class="column-left"> <a href="#savep"><div class="save"></div></a></div>
   <div class="column-center"><label>Some Tail</div>
   <div class="column-right"> <a href="#confp"><div class="conf"></div></a></div>
</div>
</div>''' % head )
     return html


  def lost():
     html = 'are you lost, would like some candy?'
     return html

  def landing():
     html = str( body() )
     return html

  ### main
#  try:
#     ret  = eval( mthd )
#     ret  = str( ret() )
#     return ret
#  except:
#     return 'The Wizard is unavailable at the moment.'

  if mthd == 'body':
     src = str( body( vars ) )
     return src
<file_sep># -*- coding: utf-8 -*-

from . import cenv, ccfg, chrt
<file_sep>def jscr():
  ### select, set - color, conf
  src = str( '''\
function sselect( fid )
{
   document.getElementById('cslct').value = fid;
}

function setcc()
{
  var clr = document.getElementById('tinput').value;
  var fig = document.getElementById('cslct').value;
  var pbx = fig.substring(0, fig.length - 1) + 'b';
  console.log( 'pbx ' + pbx );


  document.getElementById( fig ).value = clr;
  document.getElementById( pbx ).style.backgroundColor = clr;

}

function svclr()
{
  var icr = document.getElementById('icri').value;
  var pcr = document.getElementById('pcri').value;
  var acr = document.getElementById('acri').value;
  var hcr = document.getElementById('hcri').value;

  var lcr = document.getElementById('lcri').value;
  var txt = document.getElementById('txti').value;
  var ttl = document.getElementById('ttli').value;
  var str = icr + ' ' + pcr + ' ' + acr + ' ' + hcr + ' ' + lcr + ' ' +txt + ' ' + ttl;
  console.log( str );
}

function fjava( btn )
{
  document.getElementById( 'uref' ).value = btn;
  if ( btn == 'udelete' )
     document.getElementById( 'urin' ).value = "Delete User?";
  else
     document.getElementById( 'urin' ).value = "";
}

function rmin( str )
{
   document.getElementById( 'refu' ).value = str;
}


''' )
  return src



#'iconc=%2369b543&primec=%23664b4b&accentc=%237d8182&highc=%23272c2e&linkc=yellow&txtc=purple&ttlc=yellow'
