存档

‘编程技术’ 分类的存档

在Opera的UserJS里查看可用的事件类型

2012年1月25日 没有评论

最这在研究Opera的UserJS发现资料少的可怜,于是只能自己琢磨。
Opera的UserJS提供了许多事件触发点,可以帮用户做许多事,可如果才能知道页面触发了哪些事件呢?
经过我3天的研究,发现可以将页面打开过程中,所触发的事件都打印到控制台,还是挺方便的,代码如下:

window.opera.addEventListener("AfterEvent",function(e){
    console.info(e.event);
},false);

AfterEvent是在事件触发后触发你的代码,代码里的e.event是把事件的所有内容完整的打印出来,这就可以在控制台查到这个事件的type,如‘type “readystatechange”’。
找到你需要的事件,再使用AfterEvent.type就可以准确的对事件进行响应了。
关于Opera提供的事件触发点还有很多,可看我以前的文章

分类: 编程技术 标签: ,

Opera里的UserJS

2012年1月25日 没有评论

这里有两篇介绍文章,对Opera的用户还是挺珍贵的
如何使用 UserJS
UserJS 语法介绍

Opera里的window onload事件

2011年8月15日 没有评论

Opera里的用户脚本可以根据页面事件来做反应,今天想实际一个功能即在一个页面里所有内容都处理完成后(包括脚本),触发一个函数。
开始使用window的onload事件

1
2
3
window.onload = function(){
......
}

结果发现window的onload事件,是在窗口载入完成后就会被触发,这时DOM对象并没有处理完成,换句话说就是脚本还没有运行完成。
回去重看了Opera手册,里面说不建议使用window.onload=function(){}这种方法加入事件,推荐使用addEventListener方法。
于是在网上找了半天,终于找到写法

1
2
3
window.addEventListener('load',function(){
......
}

结果程序不运行,怀疑是事件对应的不正确,经过google和测试,发现应该使用‘DOMContentLoaded’事件

1
2
3
window.addEventListener('DOMContentLoaded',function(){
......
}

这样程序就可以正确的在页面所有DOM处理完成后,即脚本运行完成时,触发自定义函数了。

python 使用 openssl工具生成DES串

2011年5月21日 没有评论
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
# -*- coding: cp936 -*-
import sys
import subprocess
 
def encryptDES(key, string):
    key = "1234567890TAOBAO"
    data = args.toString()
    data = "".join(data.split())
    encryptCommand = "echo %s | openssl enc -des3 -a -k %s" % (data,key)
    oStdout = os.popen(encryptCommand)
    strStdout = oStdout.readline()
    return strStdout
#echo 123 | openssl enc -des3 -a -k 1234567890TAOBAO
 
 
def decryptDES(key, string):
    return key,string
#echo U2FsdGVkX1+ECNKhmOuBdGH8uUL4jrD+ | openssl enc -d -des3 -a -k 1234567890TAOBAO
 
def main(argv):
    try:
        opts, args = getopt.getot(argv, "edk:s:")
    except getopt.GetoptError:
        sys.exit(2)
 
    #取得加密参数
    for opt, arg in opts:
        if opt == "-k":
            key = arg
        elif opt == "-s":
            string = arg
 
    #指定运行的函数            
    for opt, arg in opts:
        if opt == "-e":
            encryptDES(key,string)
        elif opt == "-d":
            decryptDES(key,string)
 
if __name__ == "__main__":
    main(sys.argv[1:])
分类: 编程技术 标签: ,

Python 随机数与随机字符串

2010年12月12日 没有评论

随机整数:
>>> import random
>>> random.randint(0,99)
21

随机选取0到100间的偶数:
>>> import random
>>> random.randrange(0, 101, 2)
42

随机浮点数:
>>> import random
>>> random.random()
0.85415370477785668
>>> random.uniform(1, 10)
5.4221167969800881

随机字符:
>>> import random
>>> random.choice(‘abcdefg&#%^*f’)
‘d’

多个字符中选取特定数量的字符:
>>> import random
random.sample(‘abcdefghij’,3)
['a', 'd', 'b']

多个字符中选取特定数量的字符组成新字符串:
>>> import random
>>> import string
>>> string.join(random.sample(['a','b','c','d','e','f','g','h','i','j'], 3)).r
eplace(” “,”")
‘fih’

随机选取字符串:
>>> import random
>>> random.choice ( ['apple', 'pear', 'peach', 'orange', 'lemon'] )
‘lemon’

洗牌:
>>> import random
>>> items = [1, 2, 3, 4, 5, 6]
>>> random.shuffle(items)
>>> items
[3, 2, 5, 6, 4, 1]

random的函数还有很多,此处不一一列举,
参考资料: http://docs.python.org/lib/module-random.html

分类: 编程技术 标签:

使用windows 7 POSIX子系统 编译Bash shell

2010年12月2日 没有评论

前几天听说windows有个POSIX子系统,于是拿来玩一玩
不过上面的shell看着很不爽,想换成bash,但没有现成的,只能自己编
所以写这文章,算是记录一下过程
1、先下载GUN bash原码,过程不说了
2、我解压到了C:下面
3、打开POSIX的shell,我用的kore shell,进入bash目录

cd /dev/fs/C/bash-4.1

4、运行./configure

checking build system type... i586-pc-interix6.1
checking host system type... i586-pc-interix6.1
checking for emacs... no
checking for xemacs... no
 
Beginning configuration for bash-4.1-release for i586-pc-interix6.1
 
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for strerror in -lcposix... no
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... unknown
checking for _LARGE_FILES value needed for large files... unknown
checking whether gcc needs -traditional... no
checking for a BSD-compatible install... /bin/install -c
checking for ar... ar
checking for ranlib... ranlib
checking for bison... no
checking for byacc... no
checking whether make sets $(MAKE)... yes
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking whether byte ordering is bigendian... no
checking for preprocessor stringizing operator... yes
checking for long double with more range or precision than double... yes
checking for function prototypes... yes
checking whether char is unsigned... no
checking for working volatile... yes
checking for C/C++ restrict keyword... __restrict
checking whether NLS is requested... yes
checking for msgfmt... no
checking for gmsgfmt... :
checking for xgettext... no
checking for msgmerge... no
checking for off_t... yes
checking for size_t... yes
checking for working alloca.h... yes
checking for alloca... yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for getpagesize... yes
checking for working mmap... no
checking whether we are using the GNU C Library 2.1 or newer... no
checking whether integer division by zero raises SIGFPE... yes
checking for inttypes.h... no
checking for stdint.h... yes
checking for unsigned long long... yes
checking for inttypes.h... yes
checking whether the inttypes.h PRIxNN macros are broken... no
checking for ld used by GCC... /opt/gcc.3.3/i586-pc-interix3/bin/ld
checking if the linker (/opt/gcc.3.3/i586-pc-interix3/bin/ld) is GNU ld... yes
checking for shared library run path origin... done
checking argz.h usability... no
checking argz.h presence... no
checking for argz.h... no
checking limits.h usability... yes
checking limits.h presence... yes
checking for limits.h... yes
checking locale.h usability... yes
checking locale.h presence... yes
checking for locale.h... yes
checking nl_types.h usability... yes
checking nl_types.h presence... yes
checking for nl_types.h... yes
checking malloc.h usability... yes
checking malloc.h presence... yes
checking for malloc.h... yes
checking stddef.h usability... yes
checking stddef.h presence... yes
checking for stddef.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for unistd.h... (cached) yes
checking sys/param.h usability... yes
checking sys/param.h presence... yes
checking for sys/param.h... yes
checking for feof_unlocked... no
checking for fgets_unlocked... no
checking for getc_unlocked... yes
checking for getcwd... yes
checking for getegid... yes
checking for geteuid... yes
checking for getgid... yes
checking for getuid... yes
checking for mempcpy... no
checking for munmap... yes
checking for putenv... yes
checking for setenv... yes
checking for setlocale... yes
checking for localeconv... yes
checking for stpcpy... no
checking for strcasecmp... yes
checking for strdup... yes
checking for strtoul... yes
checking for tsearch... yes
checking for __argz_count... no
checking for __argz_stringify... no
checking for __argz_next... no
checking for __fsetlocking... no
checking for iconv... yes
checking for iconv declaration... 
         extern size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
checking for nl_langinfo and CODESET... yes
checking for LC_MESSAGES... yes
checking for bison... no
checking whether NLS is requested... yes
checking whether included gettext is requested... no
checking for GNU gettext in libc... no
checking for GNU gettext in libintl... no
checking whether to use NLS... yes
checking where the gettext function comes from... included intl directory
checking for dirent.h that defines DIR... yes
checking for library containing opendir... none required
checking whether time.h and sys/time.h may both be included... yes
checking for inttypes.h... (cached) yes
checking for unistd.h... (cached) yes
checking for stdlib.h... (cached) yes
checking stdarg.h usability... yes
checking stdarg.h presence... yes
checking for stdarg.h... yes
checking varargs.h usability... no
checking varargs.h presence... no
checking for varargs.h... no
checking for limits.h... (cached) yes
checking for string.h... (cached) yes
checking for memory.h... (cached) yes
checking for locale.h... (cached) yes
checking termcap.h usability... no
checking termcap.h presence... no
checking for termcap.h... no
checking termio.h usability... no
checking termio.h presence... no
checking for termio.h... no
checking termios.h usability... yes
checking termios.h presence... yes
checking for termios.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking for stddef.h... (cached) yes
checking for stdint.h... (cached) yes
checking netdb.h usability... yes
checking netdb.h presence... yes
checking for netdb.h... yes
checking pwd.h usability... yes
checking pwd.h presence... yes
checking for pwd.h... yes
checking grp.h usability... yes
checking grp.h presence... yes
checking for grp.h... yes
checking for strings.h... (cached) yes
checking regex.h usability... yes
checking regex.h presence... yes
checking for regex.h... yes
checking syslog.h usability... yes
checking syslog.h presence... yes
checking for syslog.h... yes
checking sys/pte.h usability... no
checking sys/pte.h presence... no
checking for sys/pte.h... no
checking sys/stream.h usability... no
checking sys/stream.h presence... no
checking for sys/stream.h... no
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking sys/file.h usability... yes
checking sys/file.h presence... yes
checking for sys/file.h... yes
checking sys/resource.h usability... yes
checking sys/resource.h presence... yes
checking for sys/resource.h... yes
checking for sys/param.h... (cached) yes
checking sys/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking for sys/stat.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sys/times.h usability... yes
checking sys/times.h presence... yes
checking for sys/times.h... yes
checking for sys/types.h... (cached) yes
checking sys/wait.h usability... yes
checking sys/wait.h presence... yes
checking for sys/wait.h... yes
checking netinet/in.h usability... yes
checking netinet/in.h presence... yes
checking for netinet/in.h... yes
checking arpa/inet.h usability... yes
checking arpa/inet.h presence... yes
checking for arpa/inet.h... yes
checking for sys/ptem.h... no
checking for working alloca.h... (cached) yes
checking for alloca... (cached) yes
checking whether getpgrp requires zero arguments... yes
checking for vprintf... yes
checking for _doprnt... no
checking for working strcoll... yes
checking return type of signal handlers... void
checking for __setostype... no
checking for wait3... no
checking for isinf... yes
checking for isnan... yes
checking for mkfifo... yes
checking for dup2... yes
checking for eaccess... no
checking for fcntl... yes
checking for getdtablesize... yes
checking for getgroups... yes
checking for gethostname... yes
checking for getpagesize... (cached) yes
checking for getpeername... yes
checking for getrlimit... yes
checking for getrusage... yes
checking for gettimeofday... yes
checking for kill... yes
checking for killpg... yes
checking for lstat... yes
checking for readlink... yes
checking for sbrk... yes
checking for select... yes
checking for setdtablesize... no
checking for setitimer... yes
checking for tcgetpgrp... yes
checking for uname... yes
checking for ulimit... yes
checking for waitpid... yes
checking for rename... yes
checking for bcopy... yes
checking for bzero... yes
checking for confstr... yes
checking for fnmatch... yes
checking for getaddrinfo... yes
checking for gethostbyname... yes
checking for getservbyname... yes
checking for getservent... yes
checking for inet_aton... yes
checking for memmove... yes
checking for pathconf... yes
checking for putenv... (cached) yes
checking for raise... yes
checking for regcomp... yes
checking for regexec... yes
checking for setenv... (cached) yes
checking for setlinebuf... yes
checking for setlocale... (cached) yes
checking for setvbuf... yes
checking for siginterrupt... no
checking for strchr... yes
checking for sysconf... yes
checking for syslog... yes
checking for tcgetattr... yes
checking for times... yes
checking for ttyname... yes
checking for tzset... yes
checking for unsetenv... yes
checking for vasprintf... yes
checking for asprintf... yes
checking for isascii... yes
checking for isblank... yes
checking for isgraph... yes
checking for isprint... yes
checking for isspace... yes
checking for isxdigit... yes
checking for getpwent... yes
checking for getpwnam... yes
checking for getpwuid... yes
checking for getcwd... (cached) yes
checking for memset... yes
checking for strcasecmp... (cached) yes
checking for strcasestr... yes
checking for strerror... yes
checking for strftime... yes
checking for strnlen... no
checking for strpbrk... yes
checking for strstr... yes
checking for strtod... yes
checking for strtol... yes
checking for strtoul... (cached) yes
checking for strtoll... no
checking for strtoull... no
checking for strtoimax... no
checking for strtoumax... no
checking for fdprintf... no
checking whether confstr is declared... yes
checking whether printf is declared... yes
checking whether sbrk is declared... yes
checking whether setregid is declared... yes
checking whether strcpy is declared... yes
checking whether strsignal is declared... yes
checking whether strtold is declared... no
checking for declaration of strtoimax... no
checking for declaration of strtol... yes
checking for declaration of strtoll... no
checking for declaration of strtoul... yes
checking for declaration of strtoull... no
checking for declaration of strtoumax... no
checking for sys/time.h... (cached) yes
checking for unistd.h... (cached) yes
checking for alarm... yes
checking for fpurge... yes
checking for __fpurge... no
checking for snprintf... yes
checking for vsnprintf... yes
checking for working mktime... yes
checking for argz.h... (cached) no
checking errno.h usability... yes
checking errno.h presence... yes
checking for errno.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for malloc.h... (cached) yes
checking stdio_ext.h usability... no
checking stdio_ext.h presence... no
checking for stdio_ext.h... no
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for getpagesize... (cached) yes
checking for working mmap... (cached) no
checking for __argz_count... (cached) no
checking for __argz_next... (cached) no
checking for __argz_stringify... (cached) no
checking for dcgettext... no
checking for mempcpy... (cached) no
checking for munmap... (cached) yes
checking for stpcpy... (cached) no
checking for strcspn... yes
checking for strdup... (cached) yes
checking wctype.h usability... yes
checking wctype.h presence... yes
checking for wctype.h... yes
checking wchar.h usability... yes
checking wchar.h presence... yes
checking for wchar.h... yes
checking langinfo.h usability... yes
checking langinfo.h presence... yes
checking for langinfo.h... yes
checking for mbrlen... no
checking for mbscasecmp... no
checking for mbscmp... no
checking for mbsrtowcs... no
checking for mbschr... no
checking for wcrtomb... no
checking for wcscoll... yes
checking for wcsdup... yes
checking for wcwidth... yes
checking for wctype... yes
checking whether mbrtowc and mbstate_t are properly declared... no
checking for iswlower... yes
checking for iswupper... yes
checking for towlower... yes
checking for towupper... yes
checking for iswctype... yes
checking for nl_langinfo and CODESET... yes
checking for wchar_t in wchar.h... yes
checking for wctype_t in wctype.h... yes
checking for wint_t in wctype.h... yes
checking for locale_charset... no
checking for dlopen in -ldl... yes
checking for dlopen... yes
checking for dlclose... yes
checking for dlsym... yes
checking whether sys_siglist is declared... no
checking for uid_t in sys/types.h... yes
checking type of array argument to getgroups... gid_t
checking for off_t... (cached) yes
checking for mode_t... yes
checking for uid_t in sys/types.h... (cached) yes
checking for pid_t... yes
checking for size_t... (cached) yes
checking for ssize_t... yes
checking for time_t... yes
checking for long long... long long
checking for unsigned long long... unsigned long long
checking return type of signal handlers... (cached) void
checking for sig_atomic_t in signal.h... yes
checking size of char... 1
checking size of short... 2
checking size of int... 4
checking size of long... 4
checking size of char *... 4
checking size of double... 8
checking size of long long... 8
checking for u_int... yes
checking for u_long... yes
checking for bits16_t... no
checking for u_bits16_t... no
checking for bits32_t... no
checking for u_bits32_t... no
checking for bits64_t... no
checking for ptrdiff_t... yes
checking whether stat file-mode macros are broken... no
checking whether #! works in shell scripts... yes
checking whether the ctype macros accept non-ascii characters... no
checking if dup2 fails to clear the close-on-exec flag... no
checking whether pgrps need synchronization... no
checking for type of signal functions... posix
checking for sys_errlist and sys_nerr... yes
checking for sys_siglist in system C library... no
checking for _sys_siglist in signal.h or unistd.h... yes
checking for _sys_siglist in system C library... yes
checking whether signal handlers are of type void... yes
checking for clock_t... yes
checking for sigset_t... yes
checking for quad_t... yes
checking for intmax_t... yes
checking for uintmax_t... yes
checking for socklen_t... yes
checking for size and type of struct rlimit fields... rlim_t
checking for struct termios.c_line... no
checking for struct termio.c_line... no
checking for struct dirent.d_ino... yes
checking for struct dirent.d_fileno... no
checking for struct dirent.d_namlen... yes
checking for struct winsize in sys/ioctl.h and termios.h... sys/ioctl.h
checking for struct timeval in sys/time.h and time.h... yes
checking for struct stat.st_blocks... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for struct tm.tm_zone... no
checking whether tzname is declared... yes
checking for tzname... yes
checking for struct timezone in sys/time.h and time.h... yes
checking for the existence of strsignal... yes
checking if opendir() opens non-directories... no
checking whether ulimit can substitute for getdtablesize... yes
checking whether fpurge is declared... yes
checking to see if getenv can be redefined... yes
checking if getcwd() will dynamically allocate memory with 0 size... no
checking for presence of POSIX-style sigsetjmp/siglongjmp... present
checking whether or not strcoll and strcmp differ... no
checking for standard-conformant snprintf... yes
checking for standard-conformant vsnprintf... yes
checking for standard-conformant putenv declaration... yes
checking for standard-conformant unsetenv declaration... yes
checking for printf floating point output in hex notation... no
checking if signal handlers must be reinstalled when invoked... no
checking for presence of necessary job control definitions... present
checking for presence of named pipes... present
checking whether termios.h defines TIOCGWINSZ... no
checking whether sys/ioctl.h defines TIOCGWINSZ... yes
checking for TIOCSTAT in sys/ioctl.h... no
checking for FIONREAD in sys/ioctl.h... yes
checking whether WCONTINUED flag to waitpid is unavailable or available but broken... yes
checking for speed_t in sys/types.h... no
checking whether getpw functions are declared in pwd.h... yes
checking for unusable real-time signals due to large values... no
checking for tgetent... no
checking for tgetent in -ltermcap... yes
checking which library has the termcap functions... using libtermcap
checking whether /dev/fd is available... absent
checking whether /dev/stdin stdout stderr are available... absent
checking for default mail directory... /var/mail
checking shared object configuration for loadable builtins... supported
configure: creating ./config.status
config.status: creating Makefile
config.status: creating builtins/Makefile
config.status: creating lib/readline/Makefile
config.status: creating lib/glob/Makefile
config.status: creating lib/intl/Makefile
config.status: creating lib/malloc/Makefile
config.status: creating lib/sh/Makefile
config.status: creating lib/termcap/Makefile
config.status: creating lib/tilde/Makefile
config.status: creating doc/Makefile
config.status: creating support/Makefile
config.status: creating po/Makefile.in
config.status: creating examples/loadables/Makefile
config.status: creating examples/loadables/perl/Makefile
config.status: creating config.h
config.status: executing default-1 commands
config.status: creating po/POTFILES
config.status: creating po/Makefile
config.status: executing default commands

5、运行make tests

making ./lib/intl/libintl.a in ./lib/intl
gcc -c -DLOCALEDIR=\"/usr/local/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/local/share/locale\"  -DLIBDIR=\"/usr/local/libdata\" -DIN_LIBINTL  -DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR=\"/usr/local/lib\" -DNO_XMALLOC  -Dset_relocation_prefix=libintl_set_relocation_prefix  -Drelocate=libintl_relocate  -DDEPENDS_ON_LIBICONV=1 -DHAVE_CONFIG_H -DSHELL -I. -I. -I/dev/fs/C/bash-4.1 -I../..  -g -O2  loadmsgcat.c
*** Error code 1
 
Stop in /dev/fs/C/bash-4.1/lib/intl.
*** Error code 1
 
Stop in /dev/fs/C/bash-4.1 (line 628 of Makefile).
loadmsgcat.c: In function 'get_sysdep_segment_value':
loadmsgcat.c:727: error: 'uintmax_t' undeclared (first use in this function)
loadmsgcat.c:727: error: (Each undeclared identifier is reported only once
loadmsgcat.c:727: error: for each function it appears in.)

郁闷了,解决不了……

分类: 编程技术 标签: ,

从压缩文件安装python包

2010年10月25日 没有评论

可以从ZIP文件直接安装扩展包

C:\Python26\Lib\site-packages>ez_setup.py -z mysql-connector-python-0.2.1-devel.zip
Processing mysql-connector-python-0.2.1-devel.zip
Running mysql-connector-python-0.2.1-devel\setup.py -q bdist_egg --dist-dir c:\users\admini~1\appdata\local\temp\easy_install-tp8nrn\mysql-connector-python-0.2.1-devel\egg-dist-tmp-ytwtq4
zip_safe flag not set; analyzing archive contents...
Adding mysql-connector-python 0.2.1-devel to easy-install.pth file
 
Installed c:\python26\lib\site-packages\mysql_connector_python-0.2.1_devel-py2.6.egg
Processing dependencies for mysql-connector-python==0.2.1-devel
Finished processing dependencies for mysql-connector-python==0.2.1-devel

但无法从GZ文件直接安装扩展包

C:\Python26\Lib\site-packages>ez_setup.py -z MySQL-python-1.2.3.tar.gz.gz
Processing MySQL-python-1.2.3.tar.gz.gz
Running MySQL-python-1.2.3\setup.py -q bdist_egg --dist-dir c:\users\admini~1\appdata\local\temp\easy_install-p2ogwb\MySQL-python-1.2.3\egg-dist-tmp-qpmiwi
error:
分类: 编程技术 标签:

PyMySQL使用

2010年10月25日 2 条评论

最近需要使用pymysql连接mysql,结果突然发现pymysql居然没有文档,哭死啊,就一个例子,虽然是连上了但没有文档用起来还真是很麻烦!
经过一堆无用功的测试后,在试图改原代码时发现还有以下的方法可以使用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def nextset(self):
        ''' Get the next query set '''
 
def execute(self, query, args=None):
        ''' Execute a query '''
 
def executemany(self, query, args):
        ''' Run several data against one query '''
 
def callproc(self, procname, args=()):
        ''' Call a stored procedure. Take care to ensure that procname is properly escaped. '''
 
def fetchone(self):
        ''' Fetch the next row '''
 
def fetchmany(self, size=None):
        ''' Fetch several rows '''
 
def fetchall(self):
        ''' Fetch all the rows '''
 
def scroll(self, value, mode='relative'):

真是费了我很大劲啊,可以这样使用:

1
2
3
4
5
6
7
8
9
cur.execute(sql)
rs = cur.fetchall()
print rs,type(rs)
if rs:
    for row in rs:
        for item in row:
            print item,type(item) 
else:
    print '空的'
分类: 编程技术 标签: ,

关于浏览器

2010年10月7日 没有评论

这部分说明Microsoft Internet Explorer 4.0及其后续版本结构的信息,在你重新使用这些部分时将十分有用.

包含以下主题.

结构概述

Internet Explorer 使用 Microsoft ActiveX 控制和动态文档接口连接不同部分.以下的图表提供了一个总体概括.

Internet Explorer 4.0 Architecture.

IExplore.exe 在顶层;举个例子当 Internet Explorer 装载时它只是一个小应用程序.应用程序执行时使用Internet Explorer部分完成导航,历史管理,收藏夹管理,HTML解析和翻译等等,当它提供工具条和框架支持时就成为一个卓越的浏览器.IExplorer.exe直接面对Shdocvw.dll部分.

Shdocvw.dll运转在Mshtml.dll部分上,同样的其它动态文档部分(例如Microsoft Office应用)通过操纵一个指定文档类型,使它们能够适当装载进浏览器. Shdocvw.dll提供功能性关联,像导航,适当的连接,历史管理和PICS支持. 这个DLL同样开放接口,允许个别的ActiveX控制. Shdocvw.dll 部分更多的涉及到 WebBrowser Control. 对于 WebBrowser 控制,适当连接涉及到在HTML里单击一个连接载入文档和载入一个新的HTML文档等上述实例. 如果只有Msthml.dll存在,单击连接将导致一个新的浏览器实例.

Mshtml.dll is the component that performs the HTML parsing and rendering in Internet Explorer 4.0 and later, and it also exposes the HTML document through the Dynamic HTML Object Model. This component hosts the scripting engines, Microsoft virtual machine, ActiveX Controls, plug-ins, and other objects that might be referenced in the loaded HTML document. Mshtml.dll implements the Active Document server interfaces, which allows it to be hosted using standard Component Object Model (COM) interfaces.

As this is an OLE-based architecture, the ambient properties that are commonly used by ActiveX Controls can also be applied to the Internet Explorer components. In this way, a host of the WebBrowser Control can set an ambient property that will filter down to all the frames and controls hosted in the loaded document.

选择恰当的部分

The WebBrowser Control provides a rich set of functionality that a host typically requires, such as that for in-place linking. Therefore, it is much more applicable for most applications to host this control instead of MSHTML for browsing or viewing HTML documents. Hosting MSHTML is recommended only for specialized applications, such as parsing HTML. The WalkAll Sample Source Page World Wide Web link demonstrates how to host MSHTML.

It should also be noted that although hosting MSHTML is slightly more lightweight than hosting the WebBrowser Control, the savings rarely justify the extra work involved in implementing functionality that is already available in the WebBrowser Control. It is very likely that the WebBrowser Control will already be loaded in memory, and navigating to a frameset page will also result in the WebBrowser Control being loaded as part of the standard working set.

假如需要额外控制

Hosts of the WebBrowser Control and MSHTML components have control over certain functionality. In the case of the WebBrowser Control, this includes navigation, as well as receiving events when the document is loaded. Hosts of either component can obtain extra control over functionality by implementing the IDocHostUIHandler and IDocHostShowUI interfaces. These interfaces are commonly used to override the context menus that are supplied by default for the browser. Their uses also include setting the 3-D border, overriding the location in the registry where options are stored, and extending the Dynamic HTML Object Model.

The component obtains these interfaces from the host by calling QueryInterface on the IOleClientSite interface implemented by the hosting application.

控制上下文菜单

A common requirement of hosting the WebBrowser Control is the ability to override or add to the context menus that are displayed as the result of a right-click in the browser window. This is of particular interest to applications that are using the WebBrowser Control to view rich content but do not want the user to know that HTML is being viewed. This is also advantageous for applications that do not want the user to be able to view the HTML source for the content.

There are two techniques available to achieve this. The first involves the use of the IDocHostUIHandler interface and allows an application to disable or replace the context menus. The second technique involves the use of the registry and allows the existing context menus to be extended.

Overriding the Context Menus

The WebBrowser Control‘s context menus can be overridden entirely by implementing the IDocHostUIHandler::ShowContextMenu method. Returning E_NOTIMPL or S_FALSE from this method indicates to the WebBrowser Control that it should display its own standard context menu. However, returning S_OK causes the WebBrowser Control not to display its menus, and it assumes that the host has performed the appropriate action. The host can disable all context menus or bring up its own context menus. The parameters supplied to the host that implements this method allow that host to identify which of the default menus will be displayed by the WebBrowser Control, as well as the coordinates where the menu will be displayed. This provides the host the full context for the menu. For example, the host can choose to override only the image context menus and not the standard context menus.

Adding to the Standard Context Menus

Items can be added to the existing context menus of the WebBrowser Control by placing entries in the registry and linking these to URLs that execute script. To add items to the standard WebBrowser Control context menus, create or open the following key:

HKEY_CURRENT_USER

Software

Microsoft

Internet Explorer

MenuExt

 

Under this key, you create a key whose name contains the text you want displayed in the menu. The default value for this key contains the URL that will be executed. The key name can include the ampersand (&) character, which will cause the character immediately following the & to be underlined. The URL will be loaded inside a hidden HTML dialog box, all the inline script will be executed, and the dialog box will be closed. The hidden HTML dialog’s menuArguments property (on the external object) contains the window object of the window on which the context menu item was executed.

The following registry entry adds an item with the title “My Menu Item” to the WebBrowser Control context menu and executes the inline script contained in the file c:\myscript.htm.

HKEY_CURRENT_USER

Software

Microsoft

Internet Explorer

MenuExt

My &Menu Item
(Default) = file://c:\myscript.htm

 

The contents of c:\myscript.htm are as follows:

<SCRIPT LANGUAGE="JavaScript" defer>
var parentwin = external.menuArguments;
var doc = parentwin.document;
var sel = doc.selection;
var rng = sel.createRange();
var str = new String(rng.text);
if(str.length == 0)
rng.text = "MY INSERTED TEXT";
else
rng.text =  str.toUpperCase();
</SCRIPT>

This script obtains the parent window object from external.menuArguments. The parent window object is the WebBrowser Control in which the context menu item was executed. The script then obtains the current selection and, if no selection is present, inserts the text “MY INSERTED TEXT” at the point where the context menu was executed. If there is a selection present, the selected text is changed to uppercase.

Optional keys

Under the item registry key created earlier, there are a couple of optional values. One of these specifies on which context menus this item will appear. The other specifies that the script should be run as a dialog box.

The “Contexts” DWORD value specifies the context menus in which an item will appear. This value is a bit mask consisting of the logical OR of the following values (defined in Mshtmhst.h). These values correspond to the constant passed in an IDocHostUIHandler::ShowContextMenu call.

Value Constant Name Description
0×01 CONTEXT_MENU_DEFAULT Shown on all context menus.
0×02 CONTEXT_MENU_IMAGE Context menu of images only.
0×04 CONTEXT_MENU_CONTROL Context menu of form controls only.
0×08 CONTEXT_MENU_TABLE Context menu of tables only.
0×10 CONTEXT_MENU_TEXTSELECT Context menu of selected text only, including images in a selected region.
0×20 CONTEXT_MENU_ANCHOR Context menu of links only. Does not include linked images or image maps.
0×40 CONTEXT_MENU_UNKNOWN Right-click on none of the above.

So if, for example, you want this simple extension to appear only in the default menu and the text selection menu, you could create a DWORD value in the registry under the My Menu Item key called “Contexts” and set it to 0×11. From C/C++ code, this can be expressed as:

CONTEXT_MENU_DEFAULT | CONTEXT_MENU_TEXTSELECT

The other optional registry DWORD value is “Flags”. There is only one valid bit (0×1) for this registry value; it is defined as MENUEXT_SHOWDIALOG in Mshtmhst.h. When this bit is set, the script is run just as if it had been called through the IHTMLWindow2::showModalDialog method. The window that runs the script is not hidden, and the dialog box is not automatically closed after inline and onload script finishes. The external.menuArguments value still contains the window object where the user selected the menu item.

The context menu event

Whenever a context menu extension is triggered, the event object off the main window (external.menuArguments.event) contains information about where the user clicked and which context menu was shown. The mouse coordinates are valid along with srcElement. The type value contains one of the following strings, indicating which context menu was shown to the user:

  • MenuExtDefault
  • MenuExtImage
  • MenuExtControl
  • MenuExtTable
  • MenuExtTextSelect
  • MenuExtAnchor
  • MenuExtUnknown

Another example

This example creates a new menu item on the default context menu. This item, called Show In New Window, can be used to launch a new window that displays only a specific portion of the current document. If something is deeply nested in a frameset, you can easily launch a specific frame in its own window.

Here are the contents of a .reg file that can be run to insert the correct registry settings. Call this file Example2.reg. Double-clicking this file in Windows Explorer will insert the settings in your registry.

REGEDIT4
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Show in New Window]
@="file://c:\\example2.htm"
"Contexts"=dword:00000001

Here are the contents of c:\example2.htm:

<SCRIPT LANGUAGE="JavaScript" defer>
window.open(external.menuArguments.location.href);
</SCRIPT>

For more information, see Adding Entries to the Standard Context Menu.

扩展动态HTML对象模型

It is possible for the hosting application to extend the Dynamic HTML Object Model so that scripts can refer to functionality implemented by the host. Such scripts refer to the host by specifying the external object that is available from the window object. For example, a reference to “window.external.speech” will call the host to resolve the name “speech.” All standard script within the document will be executed normally.

This extension mechanism is implemented in the host by providing an IDispatch interface for the object model extension that will have IDispatch::GetIDsOfNames and IDispatch::Invoke called on it to resolve any references to the external object. The IDispatch that the host provides is obtained by the WebBrowser Control or MSHTML component by calling the host’s IDocHostUIHandler::GetExternal method.

For an example of how to extend the Dynamic HTML Object Model, see the Driller Sample Source Page World Wide Web link.

下载控制

Hosts can control certain aspects of downloadingframes, images, Java, and so onby implementing both IOleClientSite and an ambient property defined as DISPID_AMBIENT_DLCONTROL. When the host’s IDispatch::Invoke method is called with dispidMember set to DISPID_AMBIENT_DLCONTROL, it should place zero or a combination of the following values in pvarResult.

DLCTL_BGSOUNDS The browsing component will play background sounds associated with the document.
DLCTL_DLIMAGES The browsing component will download images from the server.
DLCTL_DOWNLOADONLY The browsing component will download the page but not display it.
DLCTL_FORCEOFFLINE The browsing component will always operate in offline mode. This causes the BINDF_OFFLINEOPERATION flag to be set even if the computer is connected to the Internet when making requests through URLMON.
DLCTL_NO_BEHAVIORS The browsing component will not execute any behaviors.
DLCTL_NO_CLIENTPULL The browsing component will not perform any client pull operations.
DLCTL_NO_DLACTIVEXCTLS The browsing component will not download any ActiveX Controls in the document.
DLCTL_NO_FRAMEDOWNLOAD The browsing component will not download frames but will download and parse the frameset page. The browsing component will also ignore the frameset, and will render no frame tags.
DLCTL_NO_JAVA The browsing component will not execute any Java applets.
DLCTL_NO_METACHARSET The browsing component will suppress HTML Character Sets reflected by meta elements in the document.
DLCTL_NO_RUNACTIVEXCTLS The browsing component will not execute any ActiveX Controls in the document.
DLCTL_NO_SCRIPTS The browsing component will not execute any scripts.
DLCTL_OFFLINE Same as DLCTL_OFFLINEIFNOTCONNECTED.
DLCTL_OFFLINEIFNOTCONNECTED The browsing component will operate in offline mode if not connected to the Internet. This causes the BINDF_GETFROMCACHE_IF_NET_FAIL flag to be set if the computer is connected to the Internet when making requests through URLMON.
DLCTL_PRAGMA_NO_CACHE The browsing component will force the request through to the server and ignore the proxy, even if the proxy indicates that the data is up to date. This causes the BINDF_PRAGMA_NO_CACHE flag to be set when making requests through URLMON.
DLCTL_RESYNCHRONIZE The browsing component will ignore what is in the cache and ask the server for updated information. The cached information will be used if the server indicates that the cached information is up to date. This causes the BINDF_RESYNCHRONIZE flag to be set when making requests through URLMON.
DLCTL_SILENT The browsing component will not display any user interface. This causes the BINDF_SILENTOPERATION flag to be set when making requests through URLMON.
DLCTL_URL_ENCODING_DISABLE_UTF8 The browsing component will disable UTF-8 encoding.
DLCTL_URL_ENCODING_ENABLE_UTF8 The browsing component will enable UTF-8 encoding.
DLCTL_VIDEOS The browsing component will play any video clips that are contained in the document.

安全管理

Hosts of the browsing components can implement their own security management and override the settings that exist for the WebBrowser Control. This is achieved by implementing the IInternetSecurityManager interface. The browsing component will obtain this interface by calling the host’s IServiceProvider::QueryService method with SID_SInternetSecurityManager. For more information on security management, see About URL Security Zones.

分类: 编程技术 标签:

IE NavigateComplete2 事件说明

2010年10月7日 没有评论

导航完成事件

pDisp:返回目前正在调用此事件的对象,可能是顶层的页面就是当前页面,也可能是当前页面里的某个对象,也可能是应用程序中的WebBrowser对象
URL:返回一个标准格式化后的URL,如用Navigate或Navigate2方法打开www.microsoft.com,NavigateComplete2就会返回一个http://www.microsoft.com/

另需要注意的是NavigateComplete事件到底是什么意思!
当文档正在下载中(如在HTML中图片仍然在下载),但文档已经被服务器确认,并且文档对象在阅读器里已经被创建时,触发此事件.
所以这个事件的触发不等于文档已经打开或处理完成了,只能代表已经找到文档,并已经创建了文档对象,可以开始处理文档了,这时页面并没有完成打开而只是刚刚打开,一切都在处理中,如果想得到文档处理完毕的信息应使用DocumentComplete事件,同时应该注意的是IE处理文档时是多线程的几个过程可能同时处于工作状态.这里的文档也不是单指当前的页面文档,也包含当前页面文档内调用的其它文档内容,如其它地址的链接等,页面头部里的脚本或CSS链接不在此列.

分类: 编程技术 标签:

Cuile's Blog is Stephen Fry proof thanks to caching by WP Super Cache