Commits

razzmataz committed cba65d2

other changes and files added

Comments (0)

Files changed (8)

+
+import sys
+
+def triangle_number(ith):
+    result = 0
+    for item in range(1,ith+1):
+        result = result + item
+    return result
+
+number = int(sys.argv[1])
+print triangle_number(number)
+

firefox/moz-downloads.py

     for child in table_obj.get_children():
         #
         print "\t%s" % (child)
+    stmt = select([table])
 
 #children = moz_places.get_children()
 

firefox/moz-places.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+from sqlalchemy import *
+import datetime
+import cmdln
+
+def prtime_to_utc(pr_time=0):
+    return datetime.datetime(1970,1,1) + datetime.timedelta(microseconds=pr_time)
+
+#class Something():
+#    name = "something"
+#    @cmdln.alias()
+#    @cmdln.option() # multiples?
+#    def do_somethingsomething(self, subcmd, opts, *paths):
+#        pass
+
+# need a class for each history type, if it was a redirect, hidden, etc.
+#
+
+# class for doing sqlalchemy reflection, pull that in,
+# 
+
+class Hidden(cmdln.Cmdln):
+    name = "hidden"
+
+    @cmdln.alias('hidden')
+    def do_hidden_links(self, subcmd, opts, placesdb):
+        """${cmd_name}: list hidden links (type 4)
+
+        ${cmd_usage}
+        """
+        print "for hidden links"
+
+
+
+if __name__ == "__main__":
+    hidden = Hidden()
+    sys.exit( hidden.main() )

utils/libs/phone/phone.py

+import re
+
+class Phone():
+    """
+    phone number handler class
+    right now this only handles nanpa style telephone numbers, and would
+    need some work or refactoring to handle others
+    """
+
+    def __init__(self,phonenumber=None):
+        self.countrycode = None 
+        self.exchange = None  # 1st 3 digits of 7 digit phone num
+        self.npa = None # numbering plan area (npa) or area code
+        self.station = None # last 4 digits of 7 digit number
+        self.phonenumber = None
+        if phonenumber != None:
+            self.parse_number(phonenumber)
+
+
+    def parse_number(self, phonenumber):
+        # parse the npa, exchange, number
+        # country code possibly?
+        # north american style regex 
+        # P<npa>?\d{3}-{0,1}P<exch>\d{3}-{0,1}P<number>\d{4}
+        if phonenumber is None:
+            #print "no number provided"
+            return 0
+        # we would have to change this here to 
+        # handle european numbers.
+        # these regexes should be combined into one.
+        phonenumber = re.sub(r'-', '', phonenumber)
+        phonenumber = re.sub(r'\(', '', phonenumber)
+        phonenumber = re.sub(r'\)', '', phonenumber)
+        pnregex = re.compile(r'(?P<npa>\d{3}){0,1}(?P<exch>\d{3})(?P<number>\d{4})$')
+        pnmatch = pnregex.match(phonenumber)
+        if pnmatch:
+            pndict = pnmatch.groupdict()
+            self.npa = pndict["npa"]
+            self.exchange = pndict["exch"]
+            self.station = pndict["number"]
+            self.phonenumber = phonenumber
+            if self.exchange is None:
+                return 0
+            elif self.station is None:
+                return 0
+        else:
+            return 0
+        return 1
+
+    def string(self):
+        """
+        pretty printer for the phone number
+        """
+        #print self.phonenumber
+        if self.phonenumber is None:
+            return None
+        ph_string = "%s-%s-%s" % (self.npa, self.exchange, self.station)
+        return ph_string
+    

utils/libs/phone/phonetest.py

+import unittest
+import phone
+
+phonenumbers =  ("314-789-1234")
+class PhoneTest(unittest.TestCase):
+
+    def testNoNumberGiven(self):
+        ph = phone.Phone()
+        self.assertEqual(ph.phonenumber,None,"")
+
+    def testExchange(self):
+        ph = phone.Phone("314-789-1234")
+        self.assertEqual(ph.exchange, "789","exchange is there")
+
+    def testStation(self):
+        ph = phone.Phone("314-789-1234")
+        self.assertEqual(ph.station,"1234")
+
+    def testNPA(self):
+        ph = phone.Phone("314-789-1234")
+        self.assertEqual(ph.npa,"314","npa is populated")
+
+    def testString(self):
+        ph = phone.Phone("314-789-1234")
+        self.assertEqual(ph.string(),"314-789-1234", "phone number stringified")
+
+    def testNumberParse1(self):
+        ph1 = phone.Phone()
+        result1 = ph1.parse_number("1234")
+        self.assertEqual(result1, 0)
+
+    def testNumberParse2(self):
+        ph2 = phone.Phone()
+        result2 = ph2.parse_number("(989)-987-6543")
+        self.failIf(ph2.station is None)
+        self.failIf(ph2.exchange is None)
+        self.failIf(ph2.npa is None)
+        self.assertEqual(result2, 1)
+
+    def testNumberParse3(self):
+        ph3 = phone.Phone()
+        result3 = ph3.parse_number("1-(989)-456-4567")
+        #self.failIf(ph3.station is None)
+        #self.failIf(ph3.exchange is None)
+        #self.failIf(ph3.npa is None)
+        self.assertEqual(result3, 0,"parsing a number with 1 infront of npa")
+
+
+if __name__ == "__main__":
+    unittest.main()

utils/phone.py

-import re
-
-class Phone():
-    """
-    phone number handler class
-    right now this only handles nanpa style telephone numbers, and would
-    need some work or refactoring to handle others
-    """
-
-    def __init__(self,phonenumber=None):
-        self.countrycode = None 
-        self.exchange = None  # 1st 3 digits of 7 digit phone num
-        self.npa = None # numbering plan area (npa) or area code
-        self.station = None # last 4 digits of 7 digit number
-        self.phonenumber = None
-        if phonenumber != None:
-            self.parse_number(phonenumber)
-
-
-    def parse_number(self, phonenumber):
-        # parse the npa, exchange, number
-        # country code possibly?
-        # north american style regex 
-        # P<npa>?\d{3}-{0,1}P<exch>\d{3}-{0,1}P<number>\d{4}
-        if phonenumber is None:
-            #print "no number provided"
-            return 0
-        # we would have to change this here to 
-        # handle european numbers.
-        # these regexes should be combined into one.
-        phonenumber = re.sub(r'-', '', phonenumber)
-        phonenumber = re.sub(r'\(', '', phonenumber)
-        phonenumber = re.sub(r'\)', '', phonenumber)
-        pnregex = re.compile(r'(?P<npa>\d{3}){0,1}(?P<exch>\d{3})(?P<number>\d{4})$')
-        pnmatch = pnregex.match(phonenumber)
-        if pnmatch:
-            pndict = pnmatch.groupdict()
-            self.npa = pndict["npa"]
-            self.exchange = pndict["exch"]
-            self.station = pndict["number"]
-            self.phonenumber = phonenumber
-            if self.exchange is None:
-                return 0
-            elif self.station is None:
-                return 0
-        else:
-            return 0
-        return 1
-
-    def string(self):
-        """
-        pretty printer for the phone number
-        """
-        #print self.phonenumber
-        if self.phonenumber is None:
-            return None
-        ph_string = "%s-%s-%s" % (self.npa, self.exchange, self.station)
-        return ph_string
-    

utils/phonetest.py

-import unittest
-import phone
-
-phonenumbers =  ("314-789-1234")
-class PhoneTest(unittest.TestCase):
-
-    def testNoNumberGiven(self):
-        ph = phone.Phone()
-        self.assertEqual(ph.phonenumber,None,"")
-
-    def testExchange(self):
-        ph = phone.Phone("314-789-1234")
-        self.assertEqual(ph.exchange, "789","exchange is there")
-
-    def testStation(self):
-        ph = phone.Phone("314-789-1234")
-        self.assertEqual(ph.station,"1234")
-
-    def testNPA(self):
-        ph = phone.Phone("314-789-1234")
-        self.assertEqual(ph.npa,"314","npa is populated")
-
-    def testString(self):
-        ph = phone.Phone("314-789-1234")
-        self.assertEqual(ph.string(),"314-789-1234", "phone number stringified")
-
-    def testNumberParse1(self):
-        ph1 = phone.Phone()
-        result1 = ph1.parse_number("1234")
-        self.assertEqual(result1, 0)
-
-    def testNumberParse2(self):
-        ph2 = phone.Phone()
-        result2 = ph2.parse_number("(989)-987-6543")
-        self.failIf(ph2.station is None)
-        self.failIf(ph2.exchange is None)
-        self.failIf(ph2.npa is None)
-        self.assertEqual(result2, 1)
-
-    def testNumberParse3(self):
-        ph3 = phone.Phone()
-        result3 = ph3.parse_number("1-(989)-456-4567")
-        #self.failIf(ph3.station is None)
-        #self.failIf(ph3.exchange is None)
-        #self.failIf(ph3.npa is None)
-        self.assertEqual(result3, 0,"parsing a number with 1 infront of npa")
-
-
-if __name__ == "__main__":
-    unittest.main()

utils/urllister.py

 from sgmllib import SGMLParser
 
 class URLLister(SGMLParser):
+    """
+    example based off of that in dive into python
+    """
 
     def reset(self):
         SGMLParser.reset(self)