[6c2c92]: plugin.video.vine / mycgi.py  Maximize  Restore  History

Download this file

107 lines (92 with data), 2.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
# -*- coding: utf-8 -*-
import sys
gParamDict = {}
gQSParsed = False
def EmptyQS():
qs = sys.argv[2][1:]
return ( qs == '' )
def Params( *args ):
values = []
for name in args:
values.append( Param(name) )
return values
def Param( name ):
dict = _GetParamDict()
if ( name in dict ):
return dict[name]
else: return ''
def _GetParamDict():
if ( gQSParsed == False ):
_ParseQS()
return gParamDict
def ParamCount():
return len(_GetParamDict())
def _ParseQS():
global gParamDict
global gQSParsed
qs = sys.argv[2][1:]
pairs = qs.split('&')
gParamDict = {}
for i in range(len(pairs)):
nameValue = pairs[i].split('=')
if (len(nameValue)) == 2:
name = URLUnescape(nameValue[0])
value = URLUnescape(nameValue[1])
gParamDict[name] = value
gQSParsed = True
def URLUnescape( s ):
# Unescape the pluses
if '+' in s:
s = ' '.join(s.split('+'))
return Unescape(s)
def Unescape( s ):
mychr = chr
myatoi = int
list = s.split('%')
res = [list[0]]
myappend = res.append
del list[0]
for item in list:
if item[1:2]:
try:
myappend(mychr(myatoi(item[:2], 16)) + item[2:])
except:
myappend('%' + item)
else:
myappend('%' + item)
return "".join(res)
_always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'abcdefghijklmnopqrstuvwxyz'
'0123456789' '_.-')
_fast_safe_test = _always_safe + '/'
_fast_safe = None
def _fast_quote(s):
global _fast_safe
if _fast_safe is None:
_fast_safe = {}
for c in _fast_safe_test:
_fast_safe[c] = c
res = list(s)
for i in range(len(res)):
c = res[i]
if not _fast_safe.has_key(c):
res[i] = '%%%02X' % ord(c)
return ''.join(res)
def Escape(s, safe = '/'):
safe = _always_safe + safe
if _fast_safe_test == safe:
return _fast_quote(s)
res = list(s)
for i in range(len(res)):
c = res[i]
if c not in safe:
res[i] = '%%%02X' % ord(c)
return ''.join(res)
def URLEscape(s, safe = ''):
if ' ' in s:
l = s.split(' ')
for i in range(len(l)):
l[i] = Escape(l[i], safe)
return '+'.join(l)
else:
return Escape(s, safe)

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks