def parse_ns_headers(ns_headers):
 known_attrs = ('expires', 'domain', 'path', 'secure', 'version', 'port', 'max-age')
 result = []
 for ns_header in ns_headers:
  pairs = []
  version_set = False
  for (ii, param) in enumerate(ns_header.split(';')):
   param = param.strip()
   (key, sep, val) = param.partition('=')
   key = key.strip()
   if (not key):
    if (ii == 0):
     break
    else:
     continue
   val = (val.strip() if sep else None)
   if (ii != 0):
    lc = key.lower()
    if (lc in known_attrs):
     key = lc
    if (key == 'version'):
     if (val is not None):
      val = _strip_quotes(val)
     version_set = True
    elif (key == 'expires'):
     if (val is not None):
      val = http2time(_strip_quotes(val))
   pairs.append((key, val))
  if pairs:
   if (not version_set):
    pairs.append(('version', '0'))
   result.append(pairs)
 return result

def parse_ns_headers ( ns_headers ) : known_attrs = ( 'expires' , 'domain' , 'path' , 'secure' , 'version' , 'port' , 'max-age' ) result = [ ] for ns_header in ns_headers : pairs = [ ] version_set = False for ( ii , param ) in enumerate ( ns_header . split ( ';' ) ) : param = param . strip ( ) ( key , sep , val ) = param . partition ( '=' ) key = key . strip ( ) if ( not key ) : if ( ii == 0 ) : break else : continue val = ( val . strip ( ) if sep else None ) if ( ii != 0 ) : lc = key . lower ( ) if ( lc in known_attrs ) : key = lc if ( key == 'version' ) : if ( val is not None ) : val = _strip_quotes ( val ) version_set = True elif ( key == 'expires' ) : if ( val is not None ) : val = http2time ( _strip_quotes ( val ) ) pairs . append ( ( key , val ) ) if pairs : if ( not version_set ) : pairs . append ( ( 'version' , '0' ) ) result . append ( pairs ) return result
ad-hoc parser for netscape protocol cookie-attributes .