Beispiel #1
0
def query(**kwargs):

    good_to_go = ( kwargs is not None and
                   'url'      in kwargs and
                   'user'     in kwargs and
                   'password' in kwargs )

    # "startAt":0,"maxResults":1,"total":1,

    if good_to_go:
        url = kwargs['url']
        if kwargs['debug']:
            print 'Request: ', url

        response = requests.get(url,
                                auth=(kwargs['user'], kwargs['password']),
                                timeout=None )

        if kwargs['debug']:
            print info(response)

    else:
        msg = 'Error: '
        if kwargs is None:
            msg += 'missing kwargs '
            raise InsufficientArguments(msg)
        elif 'url' not in kwargs:
            msg += 'kwargs missing url '
        elif 'user' not in kwargs:
            msg += 'kwargs missing user '
        elif 'password' not in kwargs:
            msg += 'kwargs missing user '
        raise InsufficientArguments(msg)

    return response
    def testSpacing(self):
        """info should honor spacing argument"""
        apihelper.info(apihelper, spacing=20)
        self.redirect.seek(0)
        self.assertEqual(self.redirect.read(),
"""info                 Print methods and doc strings. Takes module, class, list, dictionary, or string.
""")
    def testApiHelper(self):
        """info should return known result for apihelper"""
        apihelper.info(apihelper)
        self.redirect.seek(0)
        self.assertEqual(self.redirect.read(),
"""info       Print methods and doc strings. Takes module, class, list, dictionary, or string.
""")
Beispiel #4
0
    def testApiHelper(self):
        """info should return known result for apihelper"""
        apihelper.info(apihelper)
        self.redirect.seek(0)
        self.assertEqual(
            self.redirect.read(),
            """info       Print methods and doc strings. Takes module, class, list, dictionary, or string.
""")
Beispiel #5
0
    def testSpacing(self):
        """info should honor spacing argument"""
        apihelper.info(apihelper, spacing=20)
        self.redirect.seek(0)
        self.assertEqual(
            self.redirect.read(),
            """info                 Print methods and doc strings. Takes module, class, list, dictionary, or string.
""")
Beispiel #6
0
def main():
    func1()
    func2()
    func3()
    print " "
    print "str sys = %s" % str(sys)
    print "dir sys = %s" % str(dir(sys))
    print " "
    print "apihelper"
    apihelper.info(sys)
    print " "
    print "fields"
    print_sys_fields()
Beispiel #7
0
from apihelper import info
import odbchelper
import turtle
import types

li = []
#info(li)

print

#info(turtle)
#info(odbchelper, 30)
#info(odbchelper, 30, 0)
#info(odbchelper, spacing=20, collapse = 1)
#info(odbchelper, collapse = 0)
info(collapse=0, spacing=0, object=odbchelper)

#Introducing type
print type(1)
print type("string")
print type([])
print type(turtle)
print type(())
print type({})
print type(info)
if type(odbchelper) == types.ModuleType:
    print True

#Introducing str
print str(1)
horsemen = ['war', 'pestilence', 'famine']
Beispiel #8
0
#!/usr/bin/python

import apihelper
import math

phi = (1 + math.sqrt(5)) / 2
print "math = %s" % str(math)

apihelper.info(math)

print "math.pi = %s" % str(math.pi)
print "math.e = %s" % str(math.e)
print "phi = %s" % str(phi)
Beispiel #9
0
#! /usr/bin/python
import sys
sys.path.append('../../')

from apihelper import info

import __builtin__

info(__builtin__, 20)
Beispiel #10
0
__author__ = 'bid'

import apihelper, my

apihelper.info(my, spacing=7, collapse=0)
from apihelper import info

li = []

info(li)
from apihelper import info
import odbchelper
import turtle
import types

li = []
#info(li)

print

#info(turtle)
#info(odbchelper, 30)
#info(odbchelper, 30, 0)
#info(odbchelper, spacing=20, collapse = 1)
#info(odbchelper, collapse = 0)
info(collapse=0, spacing=0, object=odbchelper)

#Introducing type
print type(1)
print type("string")
print type([])
print type(turtle)
print type(())
print type({})
print type(info)
if type(odbchelper) == types.ModuleType:
    print True
    
#Introducing str
print str(1)
horsemen = ['war', 'pestilence', 'famine']
Beispiel #13
0
#!/usr/bin/python

import apihelper

apihelper.info(apihelper)
Beispiel #14
0
#!/usr/bin/python

import apihelper

list1 = [ 0, 1, 2, 3, 5, 7 ]

print "list1 = %s" % str(list1)
print "list1 = %s" % str(dir(list1))
# list1 = ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
apihelper.info(list1)

list1.insert(2, 11)
print "list1 = %s" % str(list1)

index = 3
for item in [13, 17, 19]:
    list1.insert(index, item)
    index += 1
print "list1 = %s" % str(list1)
Beispiel #15
0
#!/usr/bin/python

import selenium
from selenium import webdriver
import apihelper

print "\n---------------------------------------------------------------------------------"
print "selenium"
apihelper.info(selenium)
print "selenium = %s" % str(selenium)
print "selenium = %s" % str(type(selenium))
print "selenium"
print "---------------------------------------------------------------------------------\n"


print "\n---------------------------------------------------------------------------------"
print "webdriver"
apihelper.info(webdriver)
print "webdriver = %s" % str(webdriver)
print "webdriver = %s" % str(type(webdriver))
print "webdriver"
print "---------------------------------------------------------------------------------\n"


print "\n---------------------------------------------------------------------------------"
print "webdriver.Chrome"
apihelper.info(webdriver.Chrome)
print "webdriver.Chrome = %s" % str(webdriver.Chrome)
print "webdriver.Chrome = %s" % str(type(webdriver.Chrome))
print "webdriver.Chrome"
print "---------------------------------------------------------------------------------\n"
Beispiel #16
0
#!/usr/bin/python


import apihelper

# apihelper.info(set1)

print "%s" % str(dir())
print "%s" % str(dir(__builtins__))
apihelper.info(__builtins__)
print "%s" % str(dir(__doc__))

for item1 in dir():
    print "%s" % item1

# __builtins__
# __doc__
# __file__
# __name__
# __package__
# apihelper

print "__builtins__ = %s" % str(__builtins__)
print "__builtins__ = %s" % str(type(__builtins__))
for item1 in dir(__builtins__):
    print "__builtins__.%s" % item1

print "__doc__ = %s" % str(__doc__)
print "__doc__ = %s" % str(type(__doc__))
for item1 in dir(__doc__):
    print "__doc__.%s" % item1
Beispiel #17
0
import apihelper
import subprocess
apihelper.info(subprocess)

import datetime
apihelper.info(datetime)

import taskschedule
apihelper.info(taskschedule)
Beispiel #18
0
from apihelper import info
import __builtin__

info(getattr)
'''
Veamos que mas podemos hacer con listas
'''
from apihelper import info

info([])

'''
append     Agrega UN elemento al final de la lista
clear      Elimina todos los elementos de una lista
copy       Devuelve una copia de la lista
count      Devuelve la cantidad de veces que un elemento esta en la lista
extend     Permite agregar mas de un elemento a la vez
index      Devuelve la posicion del valor indicado
insert     inserta un valor en el medio de la lista, en una posicion indicada
pop        Elimina y devuelve el valor eliminado en la posicion indicada. Ultimo valor indicado por defecto
remove     Remueve el primer valor indicado.
reverse    Revierte la lista.
sort       Ordena la lista de menor a mayor.

---------------------------------------------------

Todos estos atributos son del tipo
lista.atributo(valor)
Cambian la naturaleza de la lista
'''

#las variables en scripts son guardadas en el Pyton Shell

lista1 = [1, 2, 3, 4, 5, 6]
Beispiel #20
0
#!/usr/bin/python

import apihelper
import sys
import os
import platform


has_argparse = False
try:
    import argparse
    has_argparse = True
except Exception, e:
    print "e = %s" % str(e)
if has_argparse:
    apihelper.info(argparse)


has_bcrypt = False
try:
    import bcrypt
    has_bcrypt = True
except Exception, e:
    print "e = %s" % str(e)
if has_bcrypt:
    apihelper.info(bcrypt)


has_openssl = False
try:
    import OpenSSL
Beispiel #21
0
#!/usr/bin/python


import apihelper

set1 = set()

apihelper.info(set1)
Beispiel #22
0
# -*-coding: utf -8 -*-
def sum(a,b):
    u"""finkcja bedzie zwracala sume"""
    return a*b
print sum(3,4)
slownik = {"imie":"kkk", "nazwisko":"myszka"}
lista = ["a","b","c"]
krotka = ("1","2","3","4")
print krotka[1]
print slownik.values()
print slownik["imie"]
lista.append("grzyb")
print lista

from apihelper import info
print info(krotka,20,1)
c= 2323
d="dsdss"
#print d+c
d= d +str(c)
print d
li=["JJ","Moris"]
print  li.pop
print getattr(li,"pop")
getattr(li,"append")("Mort")
li.append(u"CzerwonyWiewór")
print li
getattr({},"clear")
print li
li.append("Eminem")
print li
# a04_przyklad
#
##############################
# przyklad dzialania na liscie

from apihelper import info
li = []
info(li)

##############################
# przyklad dzialania na module

import math
info(math)
info(math, 30)
info(math, 20, 0)

##############################
# Funkcja: type
type(1)

li = []
type(li)

import apihelper
type(apihelper)

import types
type(apihelper) == types.ModuleType
type(types.ModuleType)
Beispiel #24
0
#!/usr/bin/python

import ctypes
# from ctypes import create_string_buffer
import apihelper

buf = ctypes.create_string_buffer(10)
print "buf = %s" % str(buf)
print "buf = %s" % str(type(buf))
print "buf = %s" % str(dir(buf))
buf[0] = 'a'
print "buf = %s" % str(buf.raw)
print "buf = %s" % str(buf[0])
print "buf = %x" % ord(buf[0])

apihelper.info(ctypes)

ba1 = bytearray('bytearray')
apihelper.info(bytearray)
apihelper.info(ba1)

# __add__    x.__add__(y) <==> x+y
# __alloc__  B.__alloc__() -> int Returns the number of bytes actually allocated.
# __class__  bytearray(iterable_of_ints) -> bytearray. bytearray(string, encoding[, errors]) -> bytearray. bytearray(bytes_or_bytearray) -> mutable copy of bytes_or_bytearray. bytearray(memory_view) -> bytearray. Construct an mutable bytearray object from: - an iterable yielding integers in range(256) - a text string encoded using the specified encoding - a bytes or a bytearray object - any object implementing the buffer API. bytearray(int) -> bytearray. Construct a zero-initialized bytearray of the given length.
# __contains__ x.__contains__(y) <==> y in x
# __delattr__ x.__delattr__('name') <==> del x.name
# __delitem__ x.__delitem__(y) <==> del x[y]
# __eq__     x.__eq__(y) <==> x==y
# __format__ default object formatter
# __ge__     x.__ge__(y) <==> x>=y
# __getattribute__ x.__getattribute__('name') <==> x.name
Beispiel #25
0
#!/usr/bin/python

import apihelper

import jinja2


apihelper.info(jinja2)
Beispiel #26
0
)  # 1 argument to co przekonwertowac a 2gi to jakiego kodowania uzywano przy tworzeniu

#kolejną funkcją jest dir() ktora zwraca atrybuty czegos co podamy w naiwasie np modułu
print dir(odbchelper)

print "-------------------"
#kolejne jest callable(): zwraca true jak mozna wywolac dana funkcje/obiekt itp
import string
print string.punctuation
print string.join
print callable(string.punctuation)
print callable(string.join)

#Wyswietla nam wbudowane funkcje w pajtonie
import __builtin__
info(__builtin__, 20)

print "--------------------------"

print "--------------------------"

print "--------------------------"

print "--------------------------"
#teraz funkcja getattr zwraca referencje do wybranej metody w konk. objekcie

object = odbchelper
method = "buildConnectionString"
print getattr(object, method)
lista = []
print getattr(lista, "append")
Beispiel #27
0
from apihelper import info
import __builtin__
li = []
print dir(li)
print info(__builtin__, 20)
from apihelper import info

li = {} 

print info(li)
Beispiel #29
0
# -*- coding: utf-8 -*-
print "---------------4.1-----------------"
#def info(object, spacing=10, collapse=1):
#    u"""Wypisuje metody i ich notki dokumentacyjne.
#
#    Argumentem może być moduł, klasa, lista, słownik, czy też łańcuch znaków."""
#    methodList = [e for e in dir(object) if callable(getattr(object,e))]
#    processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
#    print "\n".join(["%s %s" % (method.ljust(spacing),
#                                               processFunc(unicode(getattr(object, method).__doc__)))
#                                    for method in methodList])
#if __name__ =="__main__":
#    print info.__doc__
print "---------------4.2-----------------"
from apihelper import info
li = []
info(li)
print "---------------4.3-----------------"
#import odbchelper
info(li, 30)
info(li, 30, 0)
Beispiel #30
0
import re
from BaseHTMLProcessor import BaseHTMLProcessor
import apihelper

if __name__ == "__main__":
    pass
else:
    print(re.sub.__doc__)
    apihelper.info(re.sub)


class Dialectizer(BaseHTMLProcessor):
    subs = ()

    def reset(self):
        self.verbatim = 0
        BaseHTMLProcessor.reset(self)

    def start_pre(self, attrs):
        self.verbatim += 1
        self.unknown_starttag("pre", attrs)

    def end_pre(self):
        self.unknown_endtag("pre")
        self.verbatim -= 1

    def handle_data(self, text):
        # wierd usage of process
        self.pieces.append((self.verbatim and text) or self.process(text))

    def process(self, text):
Beispiel #31
0
#!/usr/bin/python

import apihelper

dict1 = dict()

apihelper.info(dict1)
Beispiel #32
0
from apihelper import info
import odbchelper
li = []
print(info(li))
print(info(odbchelper))
Beispiel #33
0
        item = item.decode('gb2312')
        FileInfo.__setitem__(self, key, item)


def listDirectory(directory, fileExtList):
    "get list of file info objects for files of particular extensions"
    fileList = [os.path.normcase(f) for f in os.listdir(directory)]
    fileList = [
        os.path.join(directory, f) for f in fileList
        if os.path.splitext(f)[1] in fileExtList
    ]

    def getFileInfoClass(filename, module=sys.modules[FileInfo.__module__]):
        "get file info class from filename extension"
        subclass = "%sFileInfo" % os.path.splitext(filename)[1].upper()[1:]
        return hasattr(module, subclass) and getattr(module,
                                                     subclass) or FileInfo

    return [getFileInfoClass(f)(f) for f in fileList]


if __name__ == "__main__":
    # sys.exit()
    directory = os.path.join(os.path.dirname(__file__), 'mp3')
    for info in listDirectory(directory, [".mp3"]):
        print("\n".join(["%s=%s" % (k, v) for k, v in info.items()]))
else:
    apihelper.info(os.path.splitext)

# end of file
Beispiel #34
0
import keyword
import apihelper

print type(keyword)

print dir(keyword)

print keyword.kwlist

apihelper.info(keyword)

# ['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'iskeyword', 'kwlist', 'main']

print "\nSECTION API HELPER"
print "\nkeyword.__all__"
apihelper.info(keyword.__all__)

print "\nkeyword.__builtins__"
apihelper.info(keyword.__builtins__)

print "\nkeyword.__doc__"
apihelper.info(keyword.__doc__)

print "\nkeyword.__file__"
apihelper.info(keyword.__file__)

print "\nkeyword.__name__"
apihelper.info(keyword.__name__)

print "\nkeyword.__package__"
apihelper.info(keyword.__package__)
Beispiel #35
0
from apihelper import info
import odbchelper
info(odbchelper)
info(odbchelper, 30)
info(odbchelper, 30, 0)
info(odbchelper, collapse=0)
info(spacing=15, object=odbchelper)
from apihelper import info

print(info([], 30, 0))
print(info('', 30, 0))
Beispiel #37
0
# -*- coding: utf-8 -*-
print"---------------4.4-----------------"
from apihelper import info
li=[]
info(li)
info(li, 12)
info(li, collapse=0)
info(spacing=15, object=li)

Beispiel #38
0
from apihelper import info
li = []
info(li)
'''
info 函数的设计意图是提供给工作在 Python IDE 中的开发人员使用,
它可以使用任何含有函数或者方法的对象(比如模块,含有函数,又比如list,含有方法)
作为参数,并打印出对象的所有函数和它们的 doc string

由于返回结果太多,省略结果
结果是List所有可调用方法的__doc__
'''

import odbchelper_re
info(odbchelper_re)
'''
输出结果:
buildConnectionString Build a connection string from a dictionary Returns string.
'''

info(odbchelper_re, 30)
'''
输出结果:
buildConnectionString          Build a connection string from a dictionary Returns string.
'''
'''
输出结果:
buildConnectionString          Build a connection string from a dictionary Returns string.
'''

info(odbchelper_re, 30, 0)
'''
Beispiel #39
0
def pinfo(object):
    print
    print "--------------------------------------------------------------------------------"
    print "| %s" % str(object)
    print "--------------------------------------------------------------------------------"
    apihelper.info(object)
Beispiel #40
0
from apihelper import info
li = []
info(li)
Beispiel #41
0
    def __init__(self,name,age,sex='male',id=0):
        Person.__init__(self,name,age,sex)
        self.id=id

    def displayInfo(self):
        Person.displayInfo(self)
        print "id    :   %20d" % self.id

p=Person("ben",28)
p.displayInfo()

s=Student("Guan",21,"female",2)
s.displayInfo()

from apihelper import info
info(dict)

def foo():
    l = range(10)
    l.sort()
    return l
import profile
profile.run('foo()')
        
'''
八荣八耻
以动手实践为荣 , 以只看不练为耻;
以打印日志为荣 , 以单步跟踪为耻;
以空格缩进为荣 , 以制表缩进为耻;
以单元测试为荣 , 以人工测试为耻;
Beispiel #42
0
from apihelper import info
import odbchelper
import types

info(odbchelper, collapse=0)

print type(odbchelper) == types.ModuleType

print type(odbchelper)

print str(odbchelper)

print dir(odbchelper)
# a04_przyklad
#
##############################
# przyklad dzialania na liscie

from apihelper import info
li = []
info(li)

##############################
# przyklad dzialania na module

import math
info(math)
info(math, 30)
info(math, 20, 0)

##############################
# Funkcja: type
type(1)

li = []
type(li)

import apihelper
type(apihelper)

import types
type(apihelper) == types.ModuleType
type(types.ModuleType)
Beispiel #44
0
import odbchelper
from apihelper import info
li=[]
"""print info(li)
print info(odbchelper)
print info(odbchelper, 30)
print info(odbchelper, 30, 0)"""

print info(odbchelper, collapse=0)
print info(spacing=15, object=odbchelper)

print type(1)
print type(li)
print type(odbchelper)

print str(1)
horsemen = ['war','pestilance', 'famine']
print horsemen
horsemen.append('Powerbuilder')
print str(horsemen)
print str(odbchelper)

print dir(li)
d={}
print dir(d)
Beispiel #45
0
#! /usr/bin/python

import sys
sys.path.append('../../')

from apihelper import info

import odbchelper

info(odbchelper)

print '=========================='

info(odbchelper, 30)

print '========================='

info(odbchelper, 30, 0)
Beispiel #46
0
print(date1.strftime("%w"))
print date1.weekday()

print(datetime.datetime.now().strftime("%w"))


li = ["Larry","Curly"]
print li.pop()
print len(li)
print getattr(li,'pop')

from apihelper import info
import odbchelper
import types
li = []
info(li)
info(odbchelper)
print type(odbchelper)

print type(odbchelper) == types.ModuleType

horsemen = ['war', 'pestilence', 'famine']
horsemen.append('Powerbuilder')
print horsemen

print(str(horsemen))
print(str(odbchelper))
print(str(None))  #A subtle but important behavior of str is that it works on None, the Python null value. It returns the string 'None'. You'll use this to your advantage in the info function, as you'll see shortly.

li=[]
print dir(li)
Beispiel #47
0
#!/usr/bin/python

import apihelper
import aerospike

if '__version__' in dir(aerospike):
    print "Python client version is %s" % aerospike.__version__

print "---------------------------------------------------------------------------------"
print "aerospike"
apihelper.info(aerospike)

print
print "---------------------------------------------------------------------------------"
print "aerospike.Client"
apihelper.info(aerospike.Client)


print
print "---------------------------------------------------------------------------------"
print "aerospike.GeoJSON"
apihelper.info(aerospike.GeoJSON)


# print
# print "---------------------------------------------------------------------------------"
# print "aerospike.Key"
# apihelper.info(aerospike.Key)


print
Beispiel #48
0
#!usr/bin/python
# Description: Advanced Usage of apihelper.py

from apihelper import info
import odbchelper

info(odbchelper)

info(odbchelper, 12)

info(odbchelper, collapse=0)

info(spacing=15, object=odbchelper)
Beispiel #49
0
# -*- coding: utf-8 -*-
print "---------------4.4-----------------"
from apihelper import info
li = []
info(li)
info(li, 12)
info(li, collapse=0)
info(spacing=15, object=li)
Beispiel #50
0
#!/usr/bin/python

import apihelper
import os

apihelper.info(os.path)

pathname = "/data/downloads/release/tools/3.11.0/aerospike-tools-3.11.0-debian8.tgz"
print "pathname = %s" % str(pathname)
basename = os.path.basename(pathname)
print "basename = %s" % str(basename)
root, ext = os.path.splitext(basename)
print "root = %s" % str(root)
print "ext = %s" % str(ext)
tgzdir = os.path.join(os.getcwd(), root)
print "tgzdir = %s" % str(tgzdir)


# 
# 
# _joinrealpath
#     None
# 
# _unicode  
#     unicode(object='') -> unicode object unicode(string[, encoding[, errors]]) -> unicode object Create a new Unicode object from the given encoded string. encoding defaults to the current default string encoding. errors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'.
# 
# abspath   
#     Return an absolute path.
# 
# basename  
#     Returns the final component of a pathname
Beispiel #51
0
from apihelper import info
import __builtin__

print info(__builtin__, 20)