This function checks if the provided pages have dynamic content. If they are dynamic, proper markings will be made >>> findDynamicContent("Lorem ipsum dolor sit amet, congue tation referrentur ei sed. Ne nec legimus habemus recusabo, natum reque et per. Facer tritani reprehendunt eos i
(firstPage, secondPage)
| 3228 | return retVal |
| 3229 | |
| 3230 | def findDynamicContent(firstPage, secondPage): |
| 3231 | """ |
| 3232 | This function checks if the provided pages have dynamic content. If they |
| 3233 | are dynamic, proper markings will be made |
| 3234 | |
| 3235 | >>> findDynamicContent("Lorem ipsum dolor sit amet, congue tation referrentur ei sed. Ne nec legimus habemus recusabo, natum reque et per. Facer tritani reprehendunt eos id, modus constituam est te. Usu sumo indoctum ad, pri paulo molestiae complectitur no.", "Lorem ipsum dolor sit amet, congue tation referrentur ei sed. Ne nec legimus habemus recusabo, natum reque et per. <script src='ads.js'></script>Facer tritani reprehendunt eos id, modus constituam est te. Usu sumo indoctum ad, pri paulo molestiae complectitur no.") |
| 3236 | >>> kb.dynamicMarkings |
| 3237 | [('natum reque et per. ', 'Facer tritani repreh')] |
| 3238 | """ |
| 3239 | |
| 3240 | if not firstPage or not secondPage: |
| 3241 | return |
| 3242 | |
| 3243 | infoMsg = "searching for dynamic content" |
| 3244 | singleTimeLogMessage(infoMsg) |
| 3245 | |
| 3246 | blocks = list(SequenceMatcher(None, firstPage, secondPage).get_matching_blocks()) |
| 3247 | kb.dynamicMarkings = [] |
| 3248 | |
| 3249 | # Removing too small matching blocks |
| 3250 | for block in blocks[:]: |
| 3251 | (_, _, length) = block |
| 3252 | |
| 3253 | if length <= 2 * DYNAMICITY_BOUNDARY_LENGTH: |
| 3254 | blocks.remove(block) |
| 3255 | |
| 3256 | # Making of dynamic markings based on prefix/suffix principle |
| 3257 | if len(blocks) > 0: |
| 3258 | blocks.insert(0, None) |
| 3259 | blocks.append(None) |
| 3260 | |
| 3261 | for i in xrange(len(blocks) - 1): |
| 3262 | prefix = firstPage[blocks[i][0]:blocks[i][0] + blocks[i][2]] if blocks[i] else None |
| 3263 | suffix = firstPage[blocks[i + 1][0]:blocks[i + 1][0] + blocks[i + 1][2]] if blocks[i + 1] else None |
| 3264 | |
| 3265 | if prefix is None and blocks[i + 1][0] == 0: |
| 3266 | continue |
| 3267 | |
| 3268 | if suffix is None and (blocks[i][0] + blocks[i][2] >= len(firstPage)): |
| 3269 | continue |
| 3270 | |
| 3271 | if prefix and suffix: |
| 3272 | prefix = prefix[-DYNAMICITY_BOUNDARY_LENGTH:] |
| 3273 | suffix = suffix[:DYNAMICITY_BOUNDARY_LENGTH] |
| 3274 | |
| 3275 | for _ in (firstPage, secondPage): |
| 3276 | match = re.search(r"(?s)%s(.+)%s" % (re.escape(prefix), re.escape(suffix)), _) |
| 3277 | if match: |
| 3278 | infix = match.group(1) |
| 3279 | if infix[0].isalnum(): |
| 3280 | prefix = trimAlphaNum(prefix) |
| 3281 | if infix[-1].isalnum(): |
| 3282 | suffix = trimAlphaNum(suffix) |
| 3283 | break |
| 3284 | |
| 3285 | kb.dynamicMarkings.append((prefix if prefix else None, suffix if suffix else None)) |
| 3286 | |
| 3287 | if len(kb.dynamicMarkings) > 0: |
no test coverage detected
searching dependent graphs…