-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev.py
110 lines (106 loc) · 3.88 KB
/
dev.py
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
107
108
109
110
################################################################################
# #
# Exception Formatting #
# #
# Source: SO - question/666022 #
# #
################################################################################
#import sys
#import traceback
#from HTMLParser import HTMLParseError
#
#def formatExceptionInfo(maxTBlevel=5):
# cla, exc, trbk = sys.exc_info()
# excName = cla.__name__
# try:
# excArgs = exc.__dict__["args"]
# except KeyError:
# excArgs = "<no args>"
# excTb = traceback.format_tb(trbk, maxTBlevel)
# return (excName, excArgs, excTb)
#
#from bs4 import BeautifulSoup
#s = """
#<html>
#<script>
#var pstr = "<li><font color='blue'>1</font></li>";
#for(var lc=0;lc<o.length;lc++){}
#</script>
#</html>
#"""
#
#try:
# p = BeautifulSoup(s)
#
#except HTMLParseError:
# print formatExceptionInfo()
######################### END OF EXCEPTION FORMATTING ##########################
################################################################################
# #
# Code Inspection #
# #
# Print the source code of a function by name. Only works if the code is in a #
# file on disk. #
# #
################################################################################
#
#import inspect
#
#test = lambda x: x/0
#
#try:
# test(1)
#except ZeroDivisionError,msg:
# print '\n' + inspect.getsource(test).strip() + '\n'
# print msg
#
########################### END OF CODE INSPECTION #############################
################################################################################
# #
# Alternative to lambda test definitions #
# #
# #
# #
################################################################################
# Alternate way of running the tests. Define the validation function outside
# the object, and pass it in when you instantiate
#define the validation function
#def validate(*args,**kargs):
# print args[0]
# if not args[0]: # eliminate None types
# print 'None type fail'
# return False
# elif not args[0].startswith('/wiki'):
# print 'not a wiki link'
# return False
# elif not args[0].count(':') == 0:
# print 'has a colon'
# return False
# elif not args[0].count('#') == 0:
# print 'has a hash'
# return False
# else:
# print 'valid link'
# return True
#
#define your object
#class Thing1():
#
# def __init__(self,testFunction):
# self.test = testFunction # pass in the validation function
#
# def getLinks(self,alist):
# return filter(self.test,alist)
#
#aThing = Thing1(validate)
#
#someLinks = [None,'abc','/wiki/a:b','/wiki/a#b','/wiki/abc']
#
# Now we can filter a list using test
#print 'someLinks before filter'
#print someLinks
#print 'someLinks during filter'
#someLinks = aThing.getLinks(someLinks)
#print 'someLinks after filter'
#print someLinks
########################### END OF LAMBDA ALTERNATIVE ##########################