mirror of https://github.com/dnomd343/ProxyC
				
				
			
				 15 changed files with 148 additions and 110 deletions
			
			
		@ -1,60 +1,27 @@ | 
				
			|||||
#!/usr/bin/env python3 | 
					#!/usr/bin/env python3 | 
				
			||||
# -*- coding: utf-8 -*- | 
					# -*- coding: utf-8 -*- | 
				
			||||
 | 
					
 | 
				
			||||
""" | 
					from Filter.Brook import brookFilter | 
				
			||||
xxObject = {  # a dict that describe multi-field | 
					from Filter.VMess import vmessFilter | 
				
			||||
    'field_1': { | 
					from Filter.VLESS import vlessFilter | 
				
			||||
        'optional': ...,  # field force require or not | 
					from Filter.Trojan import trojanFilter | 
				
			||||
        'default': ...,  # default value when field is not exist (optional == True) | 
					from Filter.Shadowsocks import ssFilter | 
				
			||||
        'allowNone': ...,  # whether the value can be None (override the format and filter process) | 
					from Filter.ShadowsocksR import ssrFilter | 
				
			||||
        'type': ...,  # type of field content (in filter process) (any / type / list / dict) | 
					from Filter.TrojanGo import trojanGoFilter | 
				
			||||
        'multiSub': ...,  # whether there are multi subObject (type is dict) | 
					from Filter.Hysteria import hysteriaFilter | 
				
			||||
        'indexKey': ...,  # index key of subObject (type is dict and multiSub == True) | 
					
 | 
				
			||||
        'format': ...,  # format function (before filter process) (invalid content -> throw error) | 
					filterEntry = { | 
				
			||||
        'filter': ...,  # filter function -> bool (throw error when return False) | 
					    'ss': ssFilter, | 
				
			||||
        'errMsg': ...,  # raise message if there is something error | 
					    'ssr': ssrFilter, | 
				
			||||
    }, | 
					    'vmess': vmessFilter, | 
				
			||||
    'field_2': { | 
					    'vless': vlessFilter, | 
				
			||||
        ... | 
					    'trojan': trojanFilter, | 
				
			||||
    }, | 
					    'trojan-go': trojanGoFilter, | 
				
			||||
    ... | 
					    'brook': brookFilter, | 
				
			||||
 | 
					    'hysteria': hysteriaFilter, | 
				
			||||
} | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					def Filter(proxyType: str, proxyInfo: dict) -> dict: | 
				
			||||
default value | 
					    if proxyType not in filterEntry: | 
				
			||||
  + optional: False | 
					        raise RuntimeError('Unknown proxy type') | 
				
			||||
  + default: None | 
					    return filterEntry[proxyType](proxyInfo) | 
				
			||||
  + allowNone: False | 
					 | 
				
			||||
  + format: lambda -> return same thing | 
					 | 
				
			||||
  + type: force require | 
					 | 
				
			||||
  + multiSub: False | 
					 | 
				
			||||
  + indexKey: 'type' | 
					 | 
				
			||||
  + filter: lambda -> return True | 
					 | 
				
			||||
  + errMsg: 'filter error' | 
					 | 
				
			||||
 | 
					 | 
				
			||||
 | 
					 | 
				
			||||
pre process | 
					 | 
				
			||||
  => field not exist | 
					 | 
				
			||||
    => optional == False -> throw errMsg | 
					 | 
				
			||||
    => optional == True -> set as default value -> continue | 
					 | 
				
			||||
  => field exist | 
					 | 
				
			||||
    => filed is None | 
					 | 
				
			||||
      => allowNone is False -> throw errMsg | 
					 | 
				
			||||
      => allowNone is True -> break | 
					 | 
				
			||||
    => field is not None -> continue | 
					 | 
				
			||||
 | 
					 | 
				
			||||
format process -> set as field value (maybe throw error -> catch and throw errMsg) | 
					 | 
				
			||||
 | 
					 | 
				
			||||
filter process | 
					 | 
				
			||||
  => type is `any` -> filter function check (skip type compare) | 
					 | 
				
			||||
  => type is `type` -> compare with field type -> filter function check | 
					 | 
				
			||||
  => type is `list` -> compare every type in list with field -> filter function check | 
					 | 
				
			||||
  => type is `dict` | 
					 | 
				
			||||
    => multiSub == False -> recursive check | 
					 | 
				
			||||
    => multiSub == True | 
					 | 
				
			||||
      => field content is not dict or not include indexKey -> throw error | 
					 | 
				
			||||
      => others | 
					 | 
				
			||||
        => indexKey's content not in type (dict) -> throw error | 
					 | 
				
			||||
        => others -> recursive check | 
					 | 
				
			||||
 | 
					 | 
				
			||||
""" | 
					 | 
				
			||||
 | 
				
			|||||
					Loading…
					
					
				
		Reference in new issue