3 HCE project, Python bindings, Distributed Tasks Manager application. 4 UrlNormalize Class content main functional of support the URL_NORMALIZE properties. 8 @author Alexander Vybornyh <alexander.hce.cluster@gmail.com> 9 @link: http://hierarchical-cluster-engine.com/ 10 @copyright: Copyright © 2013-2017 IOIX Ukraine 11 @license: http://hierarchical-cluster-engine.com/license/ 24 PROPERTY_OPTIONS_MASK =
'mask' 25 PROPERTY_OPTIONS_REPLACE =
'replace' 28 ERROR_MSG_FAILED_REPLACE =
"Operation replace failed. Error: %s" 45 if siteProperties
is not None and isinstance(siteProperties, dict)
and APP_CONSTS.URL_NORMALIZE
in siteProperties
and \
46 isinstance(siteProperties[APP_CONSTS.URL_NORMALIZE], dict)
and UrlNormalize.PROPERTY_OPTIONS_MASK
in siteProperties[APP_CONSTS.URL_NORMALIZE]:
47 ret = int(siteProperties[APP_CONSTS.URL_NORMALIZE][UrlNormalize.PROPERTY_OPTIONS_MASK])
61 def execute(siteProperties, base, url, supportProtocols=None, log=None):
64 if siteProperties
is not None and isinstance(siteProperties, dict)
and APP_CONSTS.URL_NORMALIZE
in siteProperties:
66 log.info(
"!!! siteProperties['%s']: '%s', type: %s", str(APP_CONSTS.URL_NORMALIZE), str(siteProperties[APP_CONSTS.URL_NORMALIZE]),
67 str(
type(siteProperties[APP_CONSTS.URL_NORMALIZE])))
71 if isinstance(siteProperties[APP_CONSTS.URL_NORMALIZE], basestring):
72 propertyDict = Utils.jsonLoadsSafe(jsonString=siteProperties[APP_CONSTS.URL_NORMALIZE], default=propertyDict, log=log)
74 if isinstance(propertyDict, dict)
and UrlNormalize.PROPERTY_OPTIONS_REPLACE
in propertyDict:
75 replaceList = propertyDict[UrlNormalize.PROPERTY_OPTIONS_REPLACE]
78 log.debug(
"!!! replaceList: %s", str(replaceList))
80 if isinstance(replaceList, list):
81 for replaceElem
in replaceList:
82 if isinstance(replaceElem, dict):
83 for pattern, repl
in replaceElem.items():
86 log.debug(
"!!! pattern: %s, url: %s", str(pattern), str(url))
87 url = re.sub(pattern=pattern, repl=repl, string=url, flags=re.U + re.I)
89 log.debug(
"!!! res url: %s", str(url))
90 except Exception, err:
92 log.error(UrlNormalize.ERROR_MSG_FAILED_REPLACE, str(err))
94 return Utils.urlNormalization(base=base, url=url, supportProtocols=supportProtocols, log=log)
def execute(siteProperties, base, url, supportProtocols=None, log=None)
def getNormalizeMask(siteProperties, defaultValue=Utils.UrlNormalizator.NORM_DEFAULT)
get normalize mask