[issue44039] Duplicated assignment in Modules/_randommodule.c

2021-05-05 Thread Brad Larsen


Brad Larsen  added the comment:

> Just curious, how did you find this?

I am working on some new CodeQL queries 
(https://securitylab.github.com/tools/codeql/) and saw a warning about this 
self-assignment from one of the existing queries.

LGTM apparently regularly scans cpython: 
https://lgtm.com/projects/g/python/cpython

Thanks for the quick review.

--

___
Python tracker 
<https://bugs.python.org/issue44039>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44039] Duplicated assignment in Modules/_randommodule.c

2021-05-04 Thread Brad Larsen


Change by Brad Larsen :


--
keywords: +patch
pull_requests: +24572
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25904

___
Python tracker 
<https://bugs.python.org/issue44039>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44039] Duplicated assignment in Modules/_randommodule.c

2021-05-04 Thread Brad Larsen


New submission from Brad Larsen :

In Modules/_randommodule.c:600, `longval` is used in its own initialization.  
This seems to be a typo introduced in commit cc0cd43c0f9 for bpo-1635741.

  585 static int
  586 _random_exec(PyObject *module)
  587 {
  588 _randomstate *state = get_random_state(module);
  589
  590 state->Random_Type = PyType_FromModuleAndSpec(
  591 module, _Type_spec, NULL);
  592 if (state->Random_Type == NULL) {
  593 return -1;
  594 }
  595 if (PyModule_AddType(module, (PyTypeObject *)state->Random_Type) < 0) 
{
  596 return -1;
  597 }
  598
  599 /* Look up and save int.__abs__, which is needed in random_seed(). */
* 600 PyObject *longval = longval = PyLong_FromLong(0);
  601 if (longval == NULL) {
  602 return -1;
  603 }
  604
  605 PyObject *longtype = PyObject_Type(longval);
  606 Py_DECREF(longval);
  607 if (longtype == NULL) {
  608 return -1;
  609 }
  610
  611 state->Long___abs__ = PyObject_GetAttrString(longtype, "__abs__");
  612 Py_DECREF(longtype);
  613 if (state->Long___abs__ == NULL) {
  614 return -1;
  615 }
  616 return 0;
  617 }

--
components: Extension Modules
messages: 392949
nosy: blarsen, christian.heimes
priority: normal
severity: normal
status: open
title: Duplicated assignment in Modules/_randommodule.c
versions: Python 3.10, Python 3.11

___
Python tracker 
<https://bugs.python.org/issue44039>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43631] Update to OpenSSL 1.1.1k

2021-03-30 Thread Brad Warren


Brad Warren  added the comment:

To be fair, I doubt my project is affected by the CVEs. I was just looking to 
upgrade instead of trying to verify that.

--

___
Python tracker 
<https://bugs.python.org/issue43631>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43631] Update to OpenSSL 1.1.1k

2021-03-29 Thread Brad Warren


Brad Warren  added the comment:

When do you expect there will be new macOS and Windows downloads available at 
https://www.python.org/downloads/ that use OpenSSL 1.1.1k?

One of my projects is relying on these files and I wasn't sure the ETA here.

--

___
Python tracker 
<https://bugs.python.org/issue43631>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43631] Update to OpenSSL 1.1.1k

2021-03-29 Thread Brad Warren


Change by Brad Warren :


--
nosy: +bmw

___
Python tracker 
<https://bugs.python.org/issue43631>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42650] Can people use dest=argparse.SUPPRESS in custom Action classes?

2020-12-21 Thread Brad Warren


Brad Warren  added the comment:

Thanks for the help! I was mistaken here.

The behavior I want is to not add the option to the namespace regardless of 
whether or not the user set it. I was initially under the impression that 
dest=SUPPRESS caused this behavior, however, it seems to have the same behavior 
as default=SUPPRESS due to the code at 
https://github.com/python/cpython/blob/711381dfb09fbd434cc3b404656f7fd306161a64/Lib/argparse.py#L1838-L1841.
 By using default=SUPPRESS which is documented and a custom __call__ method on 
an Action class, I can get the behavior I want so I'm closing this issue.

Thanks again and sorry for the noise!

--
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue42650>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42650] Can people use dest=argparse.SUPPRESS in custom Action classes?

2020-12-15 Thread Brad Warren


New submission from Brad Warren :

argparse internally sets dest=SUPPRESS in action classes like _HelpAction and 
_VersionAction to prevent an attribute from being created for that option on 
the resulting namespace.

Can users creating custom Action classes also use this functionality without 
worrying about it suddenly breaking in a new version of Python? If so, can we 
document this functionality? I'd be happy to submit a PR.

--
assignee: docs@python
components: Documentation
messages: 383089
nosy: bmw, docs@python
priority: normal
severity: normal
status: open
title: Can people use dest=argparse.SUPPRESS in custom Action classes?
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 
<https://bugs.python.org/issue42650>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41697] Heap buffer overflow in the parser

2020-09-03 Thread Brad Larsen


Brad Larsen  added the comment:

Nice work with the quick fix!  I'm also happy to see the addition of the Linux 
ASAN builder -- that should help detect memory errors earlier on in the future.

--

___
Python tracker 
<https://bugs.python.org/issue41697>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41697] Heap buffer overflow in the parser

2020-09-02 Thread Brad Larsen


New submission from Brad Larsen :

It looks like commit 4a97b1517a6b5ff22e2984b677a680b07ff0ce11 introduced a heap 
buffer overflow:

commit 4a97b1517a6b5ff22e2984b677a680b07ff0ce11 (HEAD -> master, 
origin/master, origin/HEAD)
Author: Pablo Galindo 
Date:   Wed Sep 2 17:44:19 2020 +0100

bpo-41690: Use a loop to collect args in the parser instead of 
recursion (GH-22053)

This program can segfault the parser by stack overflow:

```
import ast

code = "f(" + ",".join(['a' for _ in range(10)]) + ")"
print("Ready!")
ast.parse(code)
```

the reason is that the rule for arguments has a simple recursion when 
collecting args:

args[expr_ty]:
[...]
| a=named_expression b=[',' c=args { c }] {
[...] }


If you try building with clang-10 with `--with-pydebug 
--with-address-sanitizer`, you should see a crash like the following during the 
`generate-posix-vars` step:

=
==39814==ERROR: AddressSanitizer: heap-buffer-overflow on address 
0x625000264148 at pc 0x01ff3be8 bp 0x7ffec90e5d00 sp 0x7ffec90e5cf8
READ of size 4 at 0x625000264148 thread T0
#0 0x1ff3be7 in _PyPegen_collect_call_seqs 
/build/python/cpython/Parser/pegen.c:2253:61
#1 0x218ab08 in args_rule /build/python/cpython/Parser/parser.c:12240:20
#2 0x20f8906 in arguments_rule 
/build/python/cpython/Parser/parser.c:12159:18
#3 0x2158c61 in t_primary_raw 
/build/python/cpython/Parser/parser.c:14063:18
#4 0x21416fb in t_primary_rule 
/build/python/cpython/Parser/parser.c:13896:22
#5 0x246d944 in single_subscript_attribute_target_rule 
/build/python/cpython/Parser/parser.c:13265:18
#6 0x2433a19 in _tmp_20_rule 
/build/python/cpython/Parser/parser.c:16717:54
#7 0x24016e3 in assignment_rule 
/build/python/cpython/Parser/parser.c:2093:18
#8 0x23e6617 in small_stmt_rule 
/build/python/cpython/Parser/parser.c:1526:31
#9 0x2018581 in simple_stmt_rule 
/build/python/cpython/Parser/parser.c:1424:18
#10 0x200c22c in statement_rule 
/build/python/cpython/Parser/parser.c:1258:32
#11 0x2007026 in _loop1_11_rule 
/build/python/cpython/Parser/parser.c:16174:30
#12 0x200455a in statements_rule 
/build/python/cpython/Parser/parser.c:1193:18
#13 0x230193f in block_rule 
/build/python/cpython/Parser/parser.c:6257:18
#14 0x205886b in function_def_raw_rule 
/build/python/cpython/Parser/parser.c:4927:18
#15 0x20229a4 in function_def_rule 
/build/python/cpython/Parser/parser.c:4856:37
#16 0x200e2da in compound_stmt_rule 
/build/python/cpython/Parser/parser.c:1872:33
#17 0x200a873 in statement_rule 
/build/python/cpython/Parser/parser.c:1234:18
#18 0x2007026 in _loop1_11_rule 
/build/python/cpython/Parser/parser.c:16174:30
#19 0x200455a in statements_rule 
/build/python/cpython/Parser/parser.c:1193:18
#20 0x230193f in block_rule 
/build/python/cpython/Parser/parser.c:6257:18
#21 0x2392ac3 in class_def_raw_rule 
/build/python/cpython/Parser/parser.c:6196:18
#22 0x202fb74 in class_def_rule 
/build/python/cpython/Parser/parser.c:6139:34
#23 0x2010e47 in compound_stmt_rule 
/build/python/cpython/Parser/parser.c:1914:30
#24 0x200a873 in statement_rule 
/build/python/cpython/Parser/parser.c:1234:18
#25 0x2007026 in _loop1_11_rule 
/build/python/cpython/Parser/parser.c:16174:30
#26 0x200455a in statements_rule 
/build/python/cpython/Parser/parser.c:1193:18
#27 0x230193f in block_rule 
/build/python/cpython/Parser/parser.c:6257:18
#28 0x238f31b in else_block_rule 
/build/python/cpython/Parser/parser.c:3787:18
#29 0x204e3c4 in try_stmt_rule 
/build/python/cpython/Parser/parser.c:4460:19
#30 0x2014f68 in compound_stmt_rule 
/build/python/cpython/Parser/parser.c:1977:29
#31 0x200a873 in statement_rule 
/build/python/cpython/Parser/parser.c:1234:18
#32 0x2007026 in _loop1_11_rule 
/build/python/cpython/Parser/parser.c:16174:30
#33 0x200455a in statements_rule 
/build/python/cpython/Parser/parser.c:1193:18
#34 0x1ff8c93 in file_rule /build/python/cpython/Parser/parser.c:726:18
#35 0x1ff742d in _PyPegen_parse 
/build/python/cpython/Parser/parser.c:24794:18
#36 0x1fc1128 in _PyPegen_run_parser 
/build/python/cpython/Parser/pegen.c::17
#37 0x1fc5e38 in _PyPegen_run_parser_from_string 
/build/python/cpython/Parser/pegen.c:1238:14
#38 0x1a8952b in PyParser_ASTFromStringObject 
/build/python/cpython/Parser/peg_api.c:27:21
#39 0x1339bef in Py_CompileStringObject 
/build/python/cpython/Python/pythonrun.c:1203:11
#40 0x1f2ac43 in builtin_compile_impl 
/build/python/cpython/Python/bltinmodule.c:819:

[issue41204] Use of unitialized variable `fields` along error path in code generated from asdl_c.py

2020-07-03 Thread Brad Larsen


New submission from Brad Larsen :

In commit b1cc6ba73 from earlier today, an error-handling path can now read an 
uninitialized variable.

https://github.com/python/cpython/commit/b1cc6ba73a51d5cc3aeb113b5e7378fb50a0e20a#diff-fa7f27df4c8df1055048e78340f904c4R695-R697

In particular, asdl_c.py is used to generate C source, and when building that 
code with Clang 10, there is the attached warning.

Likely fix: initialize `fields` to `NULL`. Also, perhaps a CI loop that has 
`-Werror=sometimes-uninitialized` would help detect these.

Compiler warning:

Python/Python-ast.c:1147:9: warning: variable 'fields' is used uninitialized 
whenever 'if' condition is true [-Wsometimes-uninitialized]
if (state == NULL) {
^
Python/Python-ast.c:1210:16: note: uninitialized use occurs here
Py_XDECREF(fields);
   ^~
./Include/object.h:520:51: note: expanded from macro 'Py_XDECREF'
#define Py_XDECREF(op) _Py_XDECREF(_PyObject_CAST(op))
  ^~
./Include/object.h:112:41: note: expanded from macro '_PyObject_CAST'
#define _PyObject_CAST(op) ((PyObject*)(op))
^~
Python/Python-ast.c:1147:5: note: remove the 'if' if its condition is always 
false
if (state == NULL) {
^~~~
Python/Python-ast.c:1145:35: note: initialize the variable 'fields' to silence 
this warning
PyObject *key, *value, *fields;
  ^
   = NULL
1 warning generated.

--
components: Interpreter Core
messages: 372963
nosy: blarsen, vstinner
priority: normal
severity: normal
status: open
title: Use of unitialized variable `fields` along error path in code generated 
from asdl_c.py
type: compile error
versions: Python 3.10

___
Python tracker 
<https://bugs.python.org/issue41204>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40561] Provide docstrings for public-facing webbrowser functions

2020-05-09 Thread Brad Solomon


Brad Solomon  added the comment:

To no surprise, not a lot of activity with the module over the last few years 
as it is fairly cut-and-dry.

$ git shortlog -sn --since '5 years ago' Lib/webbrowser.py
 3  Serhiy Storchaka
 1  David Steele
 1  Guido van Rossum
 1  Michael Haas
 1  Nick Coghlan
 1  Steve Dower
 1  Bumsik Kim
 1  Zhiming Wang

--

___
Python tracker 
<https://bugs.python.org/issue40561>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40561] Provide docstrings for public-facing webbrowser functions

2020-05-09 Thread Brad Solomon


Brad Solomon  added the comment:

The module source notes "Maintained by Georg Brandl."

--

___
Python tracker 
<https://bugs.python.org/issue40561>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40561] Provide docstrings for public-facing webbrowser functions

2020-05-09 Thread Brad Solomon


Change by Brad Solomon :


--
nosy: +georg.brandl

___
Python tracker 
<https://bugs.python.org/issue40561>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40561] Provide docstrings for public-facing webbrowser functions

2020-05-08 Thread Brad Solomon


Change by Brad Solomon :


--
keywords: +patch
pull_requests: +19312
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/1

___
Python tracker 
<https://bugs.python.org/issue40561>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40561] Provide docstrings for public-facing webbrowser functions

2020-05-08 Thread Brad Solomon


New submission from Brad Solomon :

Currently 'pydoc webbrowser.open' simply displays the function signature 
without a useful explanation of what 'new' does (and the parameter name/value 
set is not intuitive by name alone).

--
assignee: docs@python
components: Documentation
messages: 368435
nosy: bsolomon1124, docs@python
priority: normal
severity: normal
status: open
title: Provide docstrings for public-facing webbrowser functions
type: enhancement
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue40561>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38387] Document PyDoc_STRVAR

2019-10-06 Thread Brad Solomon


New submission from Brad Solomon :

The C-API reference would benefit from a short mention of PyDoc_STRVAR usage, 
since it is used so frequently within Modules/.

--
assignee: docs@python
components: Documentation
messages: 354053
nosy: bsolomon1124, docs@python
priority: normal
pull_requests: 16195
severity: normal
status: open
title: Document PyDoc_STRVAR
type: enhancement

___
Python tracker 
<https://bugs.python.org/issue38387>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37982] Add a --minify argument to json.tool

2019-08-29 Thread Brad Solomon


Brad Solomon  added the comment:

> json.tool produces more readable representation. Your option is opposite to 
> this purpose.

That is correct, though I'm not sure what point you're trying to make.  The 
purpose of minifying isn't to make the input more readable; it's to condense it 
in the interest of sending fewer bytes over a network.  Unless I'm missing 
something, json.tool doesn't have the single express purpose of prettifying, 
since it also serves to be a validator as stated in its help message.  This is 
just aadding another commonly-sought option.

--

___
Python tracker 
<https://bugs.python.org/issue37982>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37982] Add a --minify argument to json.tool

2019-08-29 Thread Brad Solomon


Brad Solomon  added the comment:

Since, as you point out, json.tool is made for convenience, I see the reverse 
of pretty-printing (minifying) being just as convenient:

$ cat > expanded.json < {
> "foo": "bar",
> "json": "obj"
> }
> EOF
$ ./python.exe -m json.tool --minify expanded.json minf.json
$ cat minf.json 
{"foo":"bar","json":"obj"}

--

___
Python tracker 
<https://bugs.python.org/issue37982>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37982] Add a --minify argument to json.tool

2019-08-29 Thread Brad Solomon


Change by Brad Solomon :


--
keywords: +patch
pull_requests: +15277
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/15601

___
Python tracker 
<https://bugs.python.org/issue37982>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37982] Add a --minify argument to json.tool

2019-08-29 Thread Brad Solomon


New submission from Brad Solomon :

I propose adding a command line `--minify` flag to the json/tool.py module. 

This flag, if specified, uses `indent=None` and `separators=(',', ':')` to 
eliminate indent and separator whitespace in the output.

Minifying JSON (as is also done frequently with JS, CSS, and sometimes HTML) is 
common practice, and would be useful to have as a command-line tool rather than 
a user needing to use an online resource to do so.

--
components: IO
messages: 350817
nosy: bsolomon1124
priority: normal
severity: normal
status: open
title: Add a --minify argument to json.tool
type: enhancement
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue37982>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12178] csv writer doesn't escape escapechar

2019-08-14 Thread Brad MacGregor


Brad MacGregor  added the comment:

I needed this patch for a project, so I compiled python with the patch applied, 
and tested my specific use case, and it worked. Thanks for the patch!

--
nosy: +avatarofhope

___
Python tracker 
<https://bugs.python.org/issue12178>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36960] Make datetime docs more user-friendly

2019-05-18 Thread Brad Solomon


New submission from Brad Solomon :

The datetime docs are chalk full of detail.  This is a positive aspect,
and represents a huge amount of work by Tim Peters and A.M. Kuchling.
However, it also may function as an obstacle for beginner readers and
those simply seeking to answer a basic question or see a straightforward
usage example.  Rather than seeing an example-based explanation of
a common use-case, they are bombarded with technical detail and
edge cases.

I propose some restructuring of the datetime docs with the goal of
making them more reader-friendly.  The goal is not to eliminate any
of the detail, but to restructure things so as to bring the "everyday"
parts into more prominent real estate.

The changes here all make an effort to reflect what's espoused by
"Documenting Python" at https://devguide.python.org/documenting/.

I have some additional changes in mind but wanted to put this here now
to gauge receptiveness to the existing changes.

--
assignee: docs@python
components: Documentation
messages: 342813
nosy: bsolomon1124, docs@python
priority: normal
pull_requests: 13321
severity: normal
status: open
title: Make datetime docs more user-friendly
type: enhancement
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue36960>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36496] Local variables can be used uninitialized in _PyPreConfig_Read()

2019-03-31 Thread Brad Larsen


Change by Brad Larsen :


--
keywords: +patch
pull_requests: +12576
stage:  -> patch review

___
Python tracker 
<https://bugs.python.org/issue36496>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36496] Local variables can be used uninitialized in _PyPreConfig_Read()

2019-03-31 Thread Brad Larsen


New submission from Brad Larsen :

In bpo-36301, in commit f72346c47537657a287a862305f65eb5d7594fbf, a couple 
possible uses of uninitialized variables were introduced into 
Python/preconfig.c.

In particular, in _PyPreConfig_Read(), along an error-handling path, the 
`init_utf8_mode` and `init_legacy_encoding` variables will be read 
uninitialized.

_PyInitError
_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
{
/* ... */

if (args) {
err = _PyPreCmdline_SetArgv(, args);
if (_Py_INIT_FAILED(err)) {
goto done;/* ERROR 
HANDLING DONE HERE */
}
}

int init_utf8_mode = Py_UTF8Mode; /* 
VARIABLE INITIZLIED HERE */
#ifdef MS_WINDOWS
int init_legacy_encoding = Py_LegacyWindowsFSEncodingFlag;/* 
VARIABLE INITIZLIED HERE */
#endif

/* ... */

done:
if (init_ctype_locale != NULL) {
setlocale(LC_CTYPE, init_ctype_locale);
PyMem_RawFree(init_ctype_locale);
}
_PyPreConfig_Clear(_config);
Py_UTF8Mode = init_utf8_mode ;/* 
UNINITIALIZED READ HERE */
#ifdef MS_WINDOWS
Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding;/* 
UNINITIALIZED READ HERE */
#endif
_PyPreCmdline_Clear();
return err;
}

--
components: Interpreter Core
messages: 339268
nosy: blarsen
priority: normal
severity: normal
status: open
title: Local variables can be used uninitialized in _PyPreConfig_Read()
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue36496>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36495] Out-of-bounds array reads in Python/ast.c

2019-03-31 Thread Brad Larsen


New submission from Brad Larsen :

There are currently 2 places in Python/ast.c on master where an out-of-bounds
array read can occur.

Both were introduced with the merge of of typed_ast into CPython in commit
dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c (bpo-35766, GH-11645).

In both places, the out-of-bounds array read occurs when an index variable is
incremented, then used before checking that it is still valid.

The first out-of-bounds read, in `handle_keywordonly_args()`, around line 1403:

case vfpdef:
case tfpdef:
if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) {
expression = ast_for_expr(c, CHILD(n, i + 2));
if (!expression)
goto error;
asdl_seq_SET(kwdefaults, j, expression);
i += 2; /* '=' and test */
}
else { /* setting NULL if no default value exists */
asdl_seq_SET(kwdefaults, j, NULL);
}
if (NCH(ch) == 3) {
/* ch is NAME ':' test */
annotation = ast_for_expr(c, CHILD(ch, 2));
if (!annotation)
goto error;
}
else {
annotation = NULL;
}
ch = CHILD(ch, 0);
argname = NEW_IDENTIFIER(ch);
if (!argname)
goto error;
if (forbidden_name(c, argname, ch, 0))
goto error;
arg = arg(argname, annotation, NULL, LINENO(ch), ch->n_col_offset,
  ch->n_end_lineno, ch->n_end_col_offset,
  c->c_arena);
if (!arg)
goto error;
asdl_seq_SET(kwonlyargs, j++, arg);
i += 1; /* the name */
if (TYPE(CHILD(n, i)) == COMMA)   /* HERE, OOB read */
i += 1; /* the comma, if present */
break;

The second out-of-bounds read, in `ast_for_arguments()`, around line 1602:

/* ... */
case DOUBLESTAR:
ch = CHILD(n, i+1);  /* tfpdef */
assert(TYPE(ch) == tfpdef || TYPE(ch) == vfpdef);
kwarg = ast_for_arg(c, ch);
if (!kwarg)
return NULL;
i += 2; /* the double star and the name */
if (TYPE(CHILD(n, i)) == COMMA)   /* HERE, OOB read */
i += 1; /* the comma, if present */
break;
/* ... */

You might see these out-of-bounds reads as crashes at various points during the
build process if you configure as so:

$ clang --version
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

$ clang++ --version
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

$ export ASAN_OPTIONS=detect_leaks=0 CC=clang CXX=clang++
$ ./configure --with-address-sanitizer --without-pydebug

$ make   # might fail partway through, but a python binary should still be 
produced

Finally, to see crashes from the out-of-bounds reads:

$ ./python.exe -c 'def foo(f, *args, kw=None): pass'
=
==59698==ERROR: AddressSanitizer: heap-buffer-overflow on address 
0x61306740 at pc 0x009aff20 bp 0x7ffe94660260 sp 0x7ffe94660258
READ of size 2 at 0x61306740 thread T0
#0 0x9aff1f in handle_keywordonly_args /cpython/Python/ast.c:1403:21
#1 0x9af034 in ast_for_arguments /cpython/Python/ast.c:1588:31
#2 0x9bb174 in ast_for_funcdef_impl /cpython/Python/ast.c:1748:12
#3 0x99ce99 in PyAST_FromNodeObject /cpython/Python/ast.c:806:25
#4 0x7bc4a2 in PyParser_ASTFromStringObject 
/cpython/Python/pythonrun.c:1216:15
#5 0x7ba4cf in PyRun_StringFlags /cpython/Python/pythonrun.c:963:11
#6 0x7ba422 in PyRun_SimpleStringFlags /cpython/Python/pythonrun.c:461:9
#7 0x512c5e in pymain_run_command /cpython/Modules/main.c:220:11
#8 0x512c5e in pymain_run_python /cpython/Modules/main.c:501
#9 0x512c5e in _Py_RunMain /cpython/Modules/main.c:583
#10 0x5144e2 in pymain_main /cpython/Modules/main.c:612:12
#11 0x51485f in _Py_UnixMain /cpython/Modules/main.c:636:12
#12 0x7f62e8f92b96 in __libc_start_main 
/build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
#13 0x437729 in _start (/cpython/python.exe+0x437729)

0x61306740 is located 0 bytes to the right of 384-byte region 
[0x613065c0,0x61306740)
allocated by thread T0 here:
#0 0x4e34ef in realloc 
/tmp/tmp.XYTE7P6bCb/final/llvm.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:165:3
#1 0x8fa635 in PyNode_AddChild /cpython/Parser/node.c:120:22
#2 0x9d16f6 in shift /cpython/Parser/parser.c:114:11
#3 0x9d16f6 in PyParser_AddToken /cpython/Parser/parser.c:285
#4 0x8fbee3 in parsetok /cpython/Parser/parsetok.c:332:14
#5 0x7bc44a in PyParser_ASTFromStringObject 
/cpython/Python/pythonrun.c:1206

[issue36253] Use after free in ctypes test suite

2019-03-31 Thread Brad Larsen


Brad Larsen  added the comment:

I was just going to submit a patch for this, then I found this issue.

I can confirm; I see the same use-after-free without the fix.

--
nosy: +blarsen

___
Python tracker 
<https://bugs.python.org/issue36253>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33797] json int encoding incorrect for dbus.Byte

2018-06-07 Thread Brad Bishop


New submission from Brad Bishop :

JSON does not correctly encode dbus.Byte from dbus-python on 2.7:

dbus.Byte is a subclass of int with its own __str__ implementation.

>>> import json
>>> import dbus
>>> json.dumps(dbus.Byte(0))
'\x00'

On 3.x:

>>> import json
>>> import dbus
>>> json.dumps(dbus.Byte(0))
'0'

This seems to have been fixed in 3.x here:
https://bugs.python.org/issue18264
and subsequently:
https://bugs.python.org/issue26719

I'm interested in backporting these but they are marked as enhancements.  
However a backport for a similar issue:
https://bugs.python.org/issue27934

was accepted.  Would the maintainers be amenable to a backport of 18264 & 26719?

--
components: Library (Lib)
messages: 318954
nosy: radsquirrel
priority: normal
severity: normal
status: open
title: json int encoding incorrect for dbus.Byte
type: behavior
versions: Python 2.7

___
Python tracker 
<https://bugs.python.org/issue33797>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31670] Associate .wasm with application/wasm

2018-05-10 Thread Brad Nelson

Brad Nelson <bradnel...@google.com> added the comment:

We have a provisional registration for application/wasm now with IANA:
https://www.iana.org/assignments/provisional-standard-media-types/provisional-standard-media-types.xhtml

This is also shipping in Firefox and Chrome.

Would it be possible to merge this?

Thanks!

--

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31670>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31456] SimpleCookie fails to parse any cookie if an entry has whitespace in the name

2017-10-10 Thread Brad Smith

Brad Smith <bra...@gmail.com> added the comment:

According to RFC-6265 (which also references RFC-2616 to define "tokens"), the 
space character (and whitespace in general) is not valid in cookie-names or 
cookie-values.

RFC-6265: https://tools.ietf.org/html/rfc6265#section-4.1.1
RFC-2616: https://tools.ietf.org/html/rfc2616#section-2.2

I think it's reasonable for Python to quietly throw away malformed NAME=VALUE 
pairs since web browsers are likely doing the same.

--
nosy: +infinitewarp

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31456>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31670] Associate .wasm with application/wasm

2017-10-03 Thread Brad Nelson

Brad Nelson <bradnel...@google.com> added the comment:

Tentative might be an understatement.
There was 4 browser sign-off on using that mime type within the WebAssembly CG, 
which has drafted the spec so far.
We're in the process of handing v1 of the spec off to the WebAssembly Working 
Group on our way to a good and proper W3C REC.
However, use of the mime type is already shipping in Chrome and I believe on 
the way with other browsers (and just got added to our shared toolchain).

That said we should get a proper allocation with IANA.
I've added an agenda item to our next Working Group meeting to have the group 
explicitly empower me to approach IANA:
https://github.com/WebAssembly/meetings/blob/master/2017/WG-10-23.md

Be back in month with a IANA request email to reference.

Assuming we've sorted out a proper allocation, do you have a sense of if 
getting the file type into python2.7 is likely?

Thanks!

--

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31670>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31670] Associate .wasm with application/wasm

2017-10-03 Thread Brad Nelson

Change by Brad Nelson <bradnel...@google.com>:


--
keywords: +patch
pull_requests: +3841
stage:  -> patch review

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31670>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31670] Associate .wasm with application/wasm

2017-10-03 Thread Brad Nelson

New submission from Brad Nelson <bradnel...@google.com>:

WebAssembly is tentatively spec'ed to require the application/wasm mime type 
for download sources:
https://github.com/WebAssembly/design/blob/master/Web.md

The mimetype module should associate .wasm with this mimetype to allow users of 
SimpleHTTPServer etc. to be able to easily use WebAssembly.

--
components: IO
messages: 303578
nosy: flagxor
priority: normal
severity: normal
status: open
title: Associate .wasm with application/wasm
type: enhancement
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31670>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13402] Document absoluteness of sys.executable

2016-07-11 Thread Brad Larsen

Brad Larsen added the comment:

@eryksun, you are right!  The output *is* an absolute path as far as 
`os.path.isabs` is concerned.

@ned.deily, you are right about my example --- I transcribed it wrong, and it 
should be `-c`.

The system in question is not a Mac OS system, but a Linux system with newer 
Python versions than what come with the system installed to /opt/local.  These 
are compiled from source, but without any modifications.

I'm commenting here because I'm seeing the `test_sys` test from the regression 
suite fail in a slightly modified version of Python that ships with a product.  
In particular, in Lib/test/test_sys.py around line 640, we have this:

@unittest.skipIf(sys.base_prefix != sys.prefix,
 'Test is not venv-compatible')
def test_executable(self):
# sys.executable should be absolute
self.assertEqual(os.path.abspath(sys.executable), sys.executable)

Yes, /opt/local/bin/../bin/python3.5 is an absolute path as far as 
`os.path.isabs` is concerned, but 
`os.path.abspath('/opt/local/bin/../bin/python3.5')` gives 
'/opt/local/bin/python3.5', and the test fails.  So maybe the documentation is 
fine but the test is wrong?

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13402>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13402] Document absoluteness of sys.executable

2016-07-11 Thread Brad Larsen

Brad Larsen added the comment:

It looks like sys.executable is *not* always an absolute path.  In Python 2.7:

$ which python2.7
/opt/local/bin/python2.7
$ cd /opt/local/bin
$ ../bin/python2.7 -m 'import sys; print(sys.executable)'
/opt/local/bin/../bin/python2.7

Also in Python 3.5:

$ which python3.5
/opt/local/bin/python3.5
$ cd /opt/local/bin
$ ../bin/python3.5 -m 'import sys; print(sys.executable)'
/opt/local/bin/../bin/python3.5

--
nosy: +blarsen

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13402>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7159] Urllib2 authentication memory.

2016-05-24 Thread Brad Olson

Brad Olson added the comment:

Yes, Go ahead. Thanks.

On Tue, May 24, 2016 at 1:56 AM, Terry J. Reedy <rep...@bugs.python.org>
wrote:

>
> Terry J. Reedy added the comment:
>
> Should this be closed?  A substantial patch was pushed year ago and I see
> no indication of further issue.
>
> --
> nosy: +terry.reedy
>
> ___
> Python tracker <rep...@bugs.python.org>
> <http://bugs.python.org/issue7159>
> ___
>

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue7159>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24630] null pointer dereference in `load_newobj_ex`

2015-07-16 Thread Brad Larsen

Brad Larsen added the comment:

Yeah, this appears to be fixed along with #24552.

--
status: open - pending

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24630
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24630] null pointer dereference in `load_newobj_ex`

2015-07-14 Thread Brad Larsen

Brad Larsen added the comment:

Both test cases cause segfaults for me:
(1) on 64-bit Python 3.4.3 built from source on Mac OS X
(2) on the system 64-bit Python 3.4.3 from Debian Jessie

I do not see the segfaults with a 64-bit build of the latest sources (cpython 
`default` branch at 231bf0840f8f).  Instead, I see an unhandled 
`_pickle.UnpicklingError`.

--
status: pending - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24630
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24630] null pointer dereference in `load_newobj_ex`

2015-07-13 Thread Brad Larsen

New submission from Brad Larsen:

`load_newobj_ex` in can crash with a null pointer dereference.


File Modules/_pickle.c:

static int
load_newobj_ex(UnpicklerObject *self)
{
PyObject *cls, *args, *kwargs;
PyObject *obj;
PickleState *st = _Pickle_GetGlobalState();

// ...

PDATA_POP(self-stack, cls);  // *** 1 ***
if (cls == NULL) {
Py_DECREF(kwargs);
Py_DECREF(args);
return -1;
}

if (!PyType_Check(cls)) { // *** 2 ***
Py_DECREF(kwargs);
Py_DECREF(args);
Py_DECREF(cls);
PyErr_Format(st-UnpicklingError,
 NEWOBJ_EX class argument must be a type, not %.200s,
 Py_TYPE(cls)-tp_name);  // *** 3 ***
return -1;
}

// ...
}

1. `cls` is successfully unpickled, but has an ob_type field set to 0
2. `cls` is determined not to be a `PyType` object
3. `Py_TYPE(cls)` gives a null pointer that is dereferenced via `-tp_name`


Environment:

$ python3.4 --version
Python 3.4.2

$ uname -a
Linux debian-8-amd64 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 
(2015-04-24) x86_64 GNU/Linux


POC:

from io import BytesIO
from pickle import load

payload = 
b']\x8f\x8f\x8f\x8f\x8f\x8f\x8f\x8fGGbG\x10GGG?GGG:gB(GRUGGhZGGGJGTGCgGG7GB(GRvG\xff\xff\x00\x00GGJGTGGGZCCC\x00GGG\xff\xffdGG
 
hGGG\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85CC\x85\x91\x85\x85\x85\x85\xccCCC\x92\x92\x92\x92\x04\x00\x92\x92\x92\x92\x92\x92\x92\x92\x92\x92\x92\x92\x92\x92\x92GGCCC\x03\xe8CeCCC_CTRCCCGCCGG\x80\x00C\x00\x80\x00\x00$CC,\x00\x80\x00\x00$CCCBB
 
hGGGCCCQCGCCCBCCPCACCCcCCKCCC
 CC 
hCCGGCC\xa7\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85CCC$_CCC@GGZKCCG?gG\xeb\xeb\xebQCGCCCcCC@CCC@C\x10\x00\x7fCGCC\x10\x00\x00\x00CBCC_CACCCBCCF\x00\x00\x00\x80CC\x85\x85\x85\x85\x85\x91\x85\x85b\x85\x85\x85\x85\x85\x85G\x00Gh?GGFGgG\xeb\xeb\xeb\xeb\xeb\xeb\xeb\xeb'
load(BytesIO(payload))

--
components: Extension Modules
files: bug.py
messages: 246710
nosy: blarsen
priority: normal
severity: normal
status: open
title: null pointer dereference in `load_newobj_ex`
type: crash
versions: Python 3.4
Added file: http://bugs.python.org/file39921/bug.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24630
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24630] null pointer dereference in `load_newobj_ex`

2015-07-13 Thread Brad Larsen

Brad Larsen added the comment:

Seems to be similar to #24552, but not the same problem.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24630
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24630] null pointer dereference in `load_newobj_ex`

2015-07-13 Thread Brad Larsen

Brad Larsen added the comment:

Also, it appears that the `ob_type` field of `cls` need not be NULL; it can be 
an arbitrary value treated as a memory location.

Attached another POC that triggers this case.

--
Added file: http://bugs.python.org/file39922/bug-nonnull.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24630
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24618] Invalid read in PyCode_New

2015-07-12 Thread Brad Larsen

New submission from Brad Larsen:

`PyCode_New` can read invalid heap memory.


File Objects/codeobject.c:

PyCodeObject *
PyCode_New(int argcount, int kwonlyargcount,
   int nlocals, int stacksize, int flags,
   PyObject *code, PyObject *consts, PyObject *names,
   PyObject *varnames, PyObject *freevars, PyObject *cellvars,
   PyObject *filename, PyObject *name, int firstlineno,
   PyObject *lnotab)
{
PyCodeObject *co;
unsigned char *cell2arg = NULL;
Py_ssize_t i, n_cellvars;

// ...

n_cellvars = PyTuple_GET_SIZE(cellvars);

// ...

/* Create mapping between cells and arguments if needed. */
if (n_cellvars) {
Py_ssize_t total_args = argcount + kwonlyargcount +
((flags  CO_VARARGS) != 0) + ((flags  CO_VARKEYWORDS) != 0); 
// *** 1 ***

// ...

/* Find cells which are also arguments. */
for (i = 0; i  n_cellvars; i++) {
Py_ssize_t j;
PyObject *cell = PyTuple_GET_ITEM(cellvars, i); 
for (j = 0; j  total_args; j++) {
PyObject *arg = PyTuple_GET_ITEM(varnames, j); 
// *** 2 ***
if (!PyUnicode_Compare(cell, arg)) {   
// *** 3 ***
cell2arg[i] = j;
used_cell2arg = 1;
break;
}   
}   
}

// ...
}

// ...
}

1. `total_args` is determined from parameters that are user-controlled
   (see `r_object` in `Python/marshal.c`, in the `TYPE_CODE` case,
   lines 1265--1277).
2. the `varnames` tuple is indexed with a value in the range [0, total_args),
   which could be larger than the range of valid indexes for `varnames`.
3. `arg` is now a bogus PyObject value, and causes a segfault in
   `PyUnicode_Compare`.


Environment:

$ python3.4 --version
Python 3.4.2

$ uname -a
Linux debian-8-amd64 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 
(2015-04-24) x86_64 GNU/Linux


POC:

from marshal import load
from io import BytesIO

payload = 
b'\xe3\x01\x00\xff\x00\x00\x00\x00\xfc\x01\x00\x00\x00\x02\x00\x00\x00C\x00\x00\x00s\n\x00\x00\x00k\x00\x00|\x00\x00\x83\x01\x00S)\x01N)\x01\xda\x03foo)\x01\xda\x01x\xa9\x01\xda|x\xa9x\xa9\x00\xe3\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00C\x00\x00\x00s\n\x00\x00\x00t\x00\x00|\x00\x00\x83\x01\x00S)\x01N)\x01\xda\x03foo)\x01\xda\x01x\xa9\x00r\x03\x00\x00\x00\xfa\x0fmk_tesTgases.py\xda\x08lambda\x01\x00\x00\x00s\x00\x00\x00\x00r\x03\x00\x00\x00\xfa\x0fmk_testck_te\x00)\x01\xda\x01x\xa9x\xa9\x00\xe3\x01\x00\x00\x00\x00\x00\x80\x00\x01\x00\x00\x00\x02\x00\x00\x00C\x00\x00\x00s\n\x00\x00\x00t\x00\x00\x00\x00\x83\x01\x00S)\x01N)\x01\xda\x03foo)\x01\xda\x01x\xa9\x00r\x03\x00\x00\x00\xfa\x0fmk_tMstgases\x11py\xda\x08lambda$\x00\x00\x12s\x00\x00\x00\x00r\x03\x00'
load(BytesIO(payload))

--
components: Interpreter Core
files: invalid_read.py
messages: 246658
nosy: blarsen
priority: normal
severity: normal
status: open
title: Invalid read in PyCode_New
type: crash
versions: Python 3.4
Added file: http://bugs.python.org/file39914/invalid_read.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24618
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Google Web Search API

2015-04-29 Thread brad . ahlers
Does anyone know of any current Python projects that utilize Google's search 
engine to return quick answers to questions? For example, if you Google When 
did Abraham Lincoln die, Google returns April 15, 1865 before listing any 
results. I know of many projects that utilize Google search to return actual 
search results (pygoogle) but not the quick answers above the results. 

I appreciate any responses!
-- 
https://mail.python.org/mailman/listinfo/python-list


subprocess command fails

2015-02-20 Thread Brad s
# cat makekeys.py
#!/usr/bin/python3.4
import subprocess
import sys
import string
import os.path
import datetime
import shlex
from time import gmtime, strftime
from subprocess import Popen, PIPE, STDOUT

pretime = strftime(%Y%m%d%H, gmtime())
time = datetime.datetime.strptime(pretime,'%Y%m%d%H')
print (time)
plustime = datetime.timedelta(days=730)
timeadd = (time + plustime)
str(timeadd)
#ndate = datetime.strptime(timeadd, '%Y%m%d%H')
#timeadd = timeadd.replace(tzinfo=UTC())
print (timeadd)

dname = input(Enter the domain to configure keys for? )
if os.path.exists(dname+.external.signed):
os.remove(dname+.external.signed)
#os.remove(dname+.external)
os.remove(dname+.ksk.key)
os.remove(dname+.zsk.key)
os.remove(dname+.ksk.private)
os.remove(dname+.zsk.private)
fd = open( dname+.external, 'w')
fd.write($TTL 86400\n)
fd.write($ORIGIN +dname+.\n)
fd.write(@  1D  IN SOA yoda.ex-mailer.com.  admin@+dname+.(\n)
fd.write(  +strftime(%Y%m%d%H, gmtime())+\n)
#fd.write( +repr(timeadd)+\n)
fd.write(  3h\n)
fd.write(  1h\n)
fd.write(  1w\n)
fd.write(  1h)\n)
fd.write(  IN NS   yoda.ex-mailer.com.\n)
fd.write(  IN NS   r2d2.ex-mailer.com.\n)
fd.write(dname+.   IN TXT  v=spf1 mx a:r2d2.ex-mailer.com -all\n)
fd.write(dname+.   MX 0r2d2.ex-mailer.com.\n)
fd.write(mail.+dname+.   IN A107.191.60.48\n)
fd.write($include /usr/local/etc/namedb/K+dname+.zsk.key ; ZSK\n)
fd.write($include /usr/local/etc/namedb/K+dname+.ksk.key ; KSK\n)
fd.close()


result = subprocess.check_output([dnssec-keygen, -f, KSK, -r, 
/dev/urandom, -a, RSASHA256, -b, 2048, -n, ZONE, dname])
result_utf8 = result.decode(utf-8).strip()
mylist = list(result_utf8)
print (mylist[0])
listlen= len(mylist)
array = list()
listlen -= 11
i = 0
while( i  listlen ):
#if mylist != '\n' ^ mylist != '':
array.insert(i, mylist[i])
i = i + 1
combined = .join(array)
print ('combined')
print (combined)
fmove = subprocess.call([mv, result_utf8+.key,combined +.ksk.key])
fmove = subprocess.call([mv, result_utf8+.private,combined +.ksk.private])

zresult = 
subprocess.check_output([dnssec-keygen,-r,/dev/urandom,-a,RSASHA256,-b,2048,-n,ZONE,
 dname])
zresult_utf8 = zresult.decode(utf-8).strip()
myzlist = list(zresult_utf8)
print (myzlist[0])
zlistlen= len(myzlist)
zarray = list()
zlistlen -= 11
zi = 0
while( zi zlistlen ):
zarray.insert(zi, myzlist[zi])
zi = zi + 1
zcombined = .join(zarray)
zfmove = subprocess.call([mv, zresult_utf8+.key,zcombined+.zsk.key])
zfmove = subprocess.call([mv, 
zresult_utf8+.private,zcombined+.zsk.private])

sfmove = subprocess.call(['dnssec-signzone','-e',strftime('%Y%m%d%H', 
gmtime())+'','-p','-t','-g','-k',zcombined+'.ksk.key','-o',dname,dname+'.external',zcombined+'.zsk.key'])
#cmd = dnssec-signzone','-e',strftime('%Y%m%d%H', 
gmtime())+'','-p','-t','-g','-k','K'+dname+'.ksk.key','-o',dname,dname+'.external','K+dname+'.zsk.key'
#subprocess.check_call(shlex.split(cmd))






# python3.4 makekeys.py
2015-02-20 23:00:00
2017-02-19 23:00:00
Enter the domain to configure keys for? test123.com
Generating key pair.+++ ...+++
K
combined
Ktest123.com
Generating key pair...+++ 
.+++
K
dnssec-signzone: fatal: No self-signed KSK DNSKEY found.  Supply an active
key with the KSK flag set, or use '-P'.

I am trying to execute a subprocess, something done in my script a couple of 
times. But on the last one, it outputs an error I cannot find the solution to. 
The exact same command using the same files produced at the command line works 
just fine.



command works on the command line:

dnssec-signzone -e2018033000 -p -t -g -k Ktest123.com.ksk.key -o 
test123.com test123.com.external Ktest123.com.zsk.key
Verifying the zone using the following algorithms: RSASHA256.
Zone fully signed:
Algorithm: RSASHA256: KSKs: 1 active, 0 stand-by, 0 revoked
  ZSKs: 1 active, 0 stand-by, 0 revoked
test123.com.external.signed
Signatures generated:9
Signatures retained: 0
Signatures dropped:  0
Signatures successfully verified:0
Signatures unsuccessfully verified:  0
Signing time in seconds: 0.010
Signatures per second: 875.401
Runtime in seconds:  0.013
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess command fails

2015-02-20 Thread Brad s
', dname,
  dname+'.external',
  zcombined+'.zsk.key'
]
print(command = %r % (cmdargv,))
sfmove = subprocess.call(cmdargv)



also, is the % to Python what precision is to C++?





On Friday, February 20, 2015 at 6:30:51 PM UTC-5, Brad s wrote:
 # cat makekeys.py
 #!/usr/bin/python3.4
 import subprocess
 import sys
 import string
 import os.path
 import datetime
 import shlex
 from time import gmtime, strftime
 from subprocess import Popen, PIPE, STDOUT
 
 pretime = strftime(%Y%m%d%H, gmtime())
 time = datetime.datetime.strptime(pretime,'%Y%m%d%H')
 print (time)
 plustime = datetime.timedelta(days=730)
 timeadd = (time + plustime)
 str(timeadd)
 #ndate = datetime.strptime(timeadd, '%Y%m%d%H')
 #timeadd = timeadd.replace(tzinfo=UTC())
 print (timeadd)
 
 dname = input(Enter the domain to configure keys for? )
 if os.path.exists(dname+.external.signed):
 os.remove(dname+.external.signed)
 #os.remove(dname+.external)
 os.remove(dname+.ksk.key)
 os.remove(dname+.zsk.key)
 os.remove(dname+.ksk.private)
 os.remove(dname+.zsk.private)
 fd = open( dname+.external, 'w')
 fd.write($TTL 86400\n)
 fd.write($ORIGIN +dname+.\n)
 fd.write(@  1D  IN SOA yoda.ex-mailer.com.  admin@+dname+.(\n)
 fd.write(  +strftime(%Y%m%d%H, gmtime())+\n)
 #fd.write( +repr(timeadd)+\n)
 fd.write(  3h\n)
 fd.write(  1h\n)
 fd.write(  1w\n)
 fd.write(  1h)\n)
 fd.write(  IN NS   yoda.ex-mailer.com.\n)
 fd.write(  IN NS   r2d2.ex-mailer.com.\n)
 fd.write(dname+.   IN TXT  v=spf1 mx a:r2d2.ex-mailer.com 
 -all\n)
 fd.write(dname+.   MX 0r2d2.ex-mailer.com.\n)
 fd.write(mail.+dname+.   IN A107.191.60.48\n)
 fd.write($include /usr/local/etc/namedb/K+dname+.zsk.key ; ZSK\n)
 fd.write($include /usr/local/etc/namedb/K+dname+.ksk.key ; KSK\n)
 fd.close()
 
 
 result = subprocess.check_output([dnssec-keygen, -f, KSK, -r, 
 /dev/urandom, -a, RSASHA256, -b, 2048, -n, ZONE, dname])
 result_utf8 = result.decode(utf-8).strip()
 mylist = list(result_utf8)
 print (mylist[0])
 listlen= len(mylist)
 array = list()
 listlen -= 11
 i = 0
 while( i  listlen ):
 #if mylist != '\n' ^ mylist != '':
 array.insert(i, mylist[i])
 i = i + 1
 combined = .join(array)
 print ('combined')
 print (combined)
 fmove = subprocess.call([mv, result_utf8+.key,combined +.ksk.key])
 fmove = subprocess.call([mv, result_utf8+.private,combined 
 +.ksk.private])
 
 zresult = 
 subprocess.check_output([dnssec-keygen,-r,/dev/urandom,-a,RSASHA256,-b,2048,-n,ZONE,
  dname])
 zresult_utf8 = zresult.decode(utf-8).strip()
 myzlist = list(zresult_utf8)
 print (myzlist[0])
 zlistlen= len(myzlist)
 zarray = list()
 zlistlen -= 11
 zi = 0
 while( zi zlistlen ):
 zarray.insert(zi, myzlist[zi])
 zi = zi + 1
 zcombined = .join(zarray)
 zfmove = subprocess.call([mv, zresult_utf8+.key,zcombined+.zsk.key])
 zfmove = subprocess.call([mv, 
 zresult_utf8+.private,zcombined+.zsk.private])
 
 sfmove = subprocess.call(['dnssec-signzone','-e',strftime('%Y%m%d%H', 
 gmtime())+'','-p','-t','-g','-k',zcombined+'.ksk.key','-o',dname,dname+'.external',zcombined+'.zsk.key'])
 #cmd = dnssec-signzone','-e',strftime('%Y%m%d%H', 
 gmtime())+'','-p','-t','-g','-k','K'+dname+'.ksk.key','-o',dname,dname+'.external','K+dname+'.zsk.key'
 #subprocess.check_call(shlex.split(cmd))
 
 
 
 
 
 
 # python3.4 makekeys.py
 2015-02-20 23:00:00
 2017-02-19 23:00:00
 Enter the domain to configure keys for? test123.com
 Generating key pair.+++ ...+++
 K
 combined
 Ktest123.com
 Generating key pair...+++ 
 .+++
 K
 dnssec-signzone: fatal: No self-signed KSK DNSKEY found.  Supply an active
 key with the KSK flag set, or use '-P'.
 
 I am trying to execute a subprocess, something done in my script a couple of 
 times. But on the last one, it outputs an error I cannot find the solution 
 to. The exact same command using the same files produced at the command line 
 works just fine.
 
 
 
 command works on the command line:
 
 dnssec-signzone -e2018033000 -p -t -g -k Ktest123.com.ksk.key -o 
 test123.com test123.com.external Ktest123.com.zsk.key
 Verifying the zone using the following algorithms: RSASHA256.
 Zone fully signed:
 Algorithm: RSASHA256: KSKs: 1 active, 0 stand-by, 0 revoked
   ZSKs: 1 active, 0 stand-by, 0 revoked
 test123.com.external.signed
 Signatures generated:9
 Signatures retained: 0
 Signatures dropped:  0
 Signatures successfully verified:0
 Signatures unsuccessfully verified:  0
 Signing time in seconds: 0.010
 Signatures per second: 875.401
 Runtime in seconds

Re: subprocess command fails

2015-02-20 Thread Brad s
Time adjustment error:

# python3.4 timefix.py
2015022105
2015-02-21 05:00:00
Traceback (most recent call last):
  File timefix.py, line 15, in module
ndate = datetime.datetime.strptime(timeadd, '%Y%m%d%H')
TypeError: must be str, not datetime.datetime



# cat timefix.py
#!/usr/bin/python3.4
import subprocess
import sys
from datetime import datetime
import datetime
from time import gmtime, strftime

pretime = strftime(%Y%m%d%H, gmtime())
time = datetime.datetime.strptime(pretime,'%Y%m%d%H')
print(pretime)
print (time)
plustime = datetime.timedelta(days=730)
timeadd = (time + plustime)
str(timeadd)
ndate = datetime.datetime.strptime(timeadd, '%Y%m%d%H')
#timeadd = timeadd.replace(tzinfo=UTC())
print (timeadd)
print (ndate)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess command fails

2015-02-20 Thread Brad s
fixed with 

now = datetime.datetime.now()
later = now + datetime.timedelta(days=2*365)
striplater = later.strftime('%Y%m%d%H')




# python3.4 makekeys.py
Enter the domain to configure keys for? test1234.com
Generating key 
pair...+++
 
..+++
K
Generating key pair.+++ 
.+++
K
Verifying the zone using the following algorithms: RSASHA256.
Zone fully signed:
Algorithm: RSASHA256: KSKs: 1 active, 0 stand-by, 0 revoked
  ZSKs: 1 active, 0 stand-by, 0 revoked
test1234.com.external.signed
Signatures generated:9
Signatures retained: 0
Signatures dropped:  0
Signatures successfully verified:0
Signatures unsuccessfully verified:  0
Signing time in seconds: 0.010
Signatures per second: 883.392
Runtime in seconds:  0.013

-- 
https://mail.python.org/mailman/listinfo/python-list


[issue21488] codecs.encode/decode documentation inconsistency

2014-05-12 Thread Brad Aylsworth

New submission from Brad Aylsworth:

The documentation page for codecs 
(https://docs.python.org/2/library/codecs.html) shows keyword arguments for 
codecs.encode and codecs.decode, but they throw an error if keyword arguments 
are used. codecs.decode.__doc__ reports 'decode(obj, [encoding[,errors]]) - 
object.

This happens on both 2.7.6 and 3.4.0.

--
assignee: docs@python
components: Documentation
messages: 218380
nosy: Ouaouaron, docs@python
priority: normal
severity: normal
status: open
title: codecs.encode/decode documentation inconsistency
type: resource usage
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21488
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Venus / GuthVenus for iPhone, Nexus, Droid and Android Jelly Bean

2014-03-17 Thread Brad Guth

On 3/17/2014 3:33 PM, Thrinaxodon wrote:

In article 71ab5220-6d5d-46bf-b33a-16aae6c87...@googlegroups.com,
bradg...@gmail.com says...


On Wednesday, February 5, 2014 2:59:23 PM UTC-8, Brad Guth wrote:

On Saturday, January 11, 2014 3:52:10 PM UTC-8, Brad Guth wrote:


NOVA and Discovery Channel each missed this one as of 13+ years ago;







GuthVenus 1:1, plus 10x resample/enlargement of the area in question







  http://bradguth.blogspot.com/2009/07/brad-guth-index.html







  http://nssdc.gsfc.nasa.gov/imgcat/hires/mgn_c115s095_1.gif















Our NASA and all of their contracted universities plus numerous others 
associated somehow missed this one, even after they'd been explicitly informed. 
Go figure.















  Be my guest and apply your very own photographic enlargement software, as to 
viewing this one small but rather interesting topography area of Venus, using 
your independent deductive expertise as to further enlarge or magnify and 
simply interpret this extensively mountainous and canyon populated terrain area 
of Venus that I've focused upon (roughly one third up from the bottom and 
roughly center), honestly shouldn't be asking too much.  Most of modern 
PhotoZoom and

numerous other photographic software variations tend to accomplish this digital 
enlargement process automatically on the fly, (including iPhone, Safari, 
Android, Mozilla FireFox, Google Chrome and most other internet browsing forms 
of image viewing and zooming), although some extra applied filtering and 
thereby image enhancing for dynamic range compensations (aka contrast boosting) 
can further improve upon the end result (no direct pixel modifications should 
ever be
necessary, because it's all a derivative from the original Magellan radar 
imaging that's offering a composite of 36 confirming radar scans per pixel, 
that can always be 100% verified from scratch).















Using Ctrl+,+,+ gets most older PCs and even the basic Apple notebooks to 
quickly zoom in, whereas iPhone, Android and MS-W8 as well as Google Chrome 
accepts touch-pad or screen touch zooming with even somewhat better results of 
automatic image resampling, so as to keeping the image context reasonably clear 
or in focus.  However, a regular photographic editing app or software solution 
like PhotoShop is still going to provide some of the best results plus offering

dynamic range compensation for a version of added contrast without actually 
modifying a damn thing as to the raw context of the original, because 
everything always remains as a direct image derivative.







  http://photo-editing-software-review.toptenreviews.com/












HERE'S THE ANSWER:

===

BREAKING NEWS

===



RICHARD LEAKEY JUST DIED DUE TO HEART FAILURE!



THE REASONS DESCRIBED BY THE MEDICAL TEAM IS THAT HIS WORK WAS
DISPROVEN, BY NONE OTHER THAN YOUR OWN BASTARD, THRINAXODON.



THIS CAUSED LEAKEY'S HEART TO EXPLODE!



THRINAXODON DANCED WITH JOY AS HE WAS GRANTED $600,000,000,000.000!



TO WASTE YOUR TIME EVEN FURTHER, CHECK OUT THESE LINKS BELOW.
===
EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:

https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa
d/6f501c469c7af24f#


https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa
d/3aad75c16afb0b82#




http://thrinaxodon.wordpress.com/

===

THRINAXODON ONLY HAD THIS TO SAY:

I..I...I...Can't believe it. This completely disproved Darwinian
orthodoxy.

===

THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING
WITH FEAR.

===
THESE ASSHOLES ARE GOING TO DIE:
THOMAS AQUINAS;
ALDOUS HUXLEY;
BOB CASANVOVA;
SkyEyes;
DAVID IAIN GRIEG;
MARK ISAAK;
JOHN HARSHAM;
RICHARD NORMAN;
DR. DOOLITTLE;
CHARLES DARWIN;
MARK HORTON;
ERIK SIMPSON;
HYPATIAB7;
PAUL J. GANS;
JILLERY;
WIKI TRIK;
THRINAXODON;
PETER NYIKOS;
RON OKIMOTO;
JOHN S. WILKINS
===

THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A
HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT
THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD
TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY
FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, We want to keep
people thinking that humans evolved 2 Ma. THRINAXODON BROUGHT HIS
SWORD, AND SAID, SCIENCE CORRECTS ITSELF. RICHARD LEAKEY SAID, That
is a myth, for people to believe in science. THRINAXODON PLANS TO
BRING DOOM TO SCIENCE, ITSELF.



THRINAXODON IS NOW ON REDDIT


Direct death threats should be kept to a minimum.

 ===
 THESE ASSHOLES ARE GOING TO DIE:
 THOMAS AQUINAS;
 ALDOUS HUXLEY;
 BOB CASANVOVA;
 SkyEyes;
 DAVID IAIN GRIEG;
 MARK ISAAK;
 JOHN HARSHAM;
 RICHARD NORMAN;
 DR. DOOLITTLE;
 CHARLES DARWIN;
 MARK HORTON

PyTexas: last day for $25 registration, talk proposal

2012-09-01 Thread Brad Allen
Just wanted to send out this quick reminder--today is the last day for
PyTexas $25 registration; starting tomorrow it will cost $50.

http://www.pytexas.org/chance/1/register/

Today is also your last day to post your talk proposals.

http://www.pytexas.org/chance/1/talks/add/

Btw, there is going to be a PyTexas t-shirt given away with every
registration. I've seen advance drafts which are beautiful, drawn and
colored by Kat Metgzer, the same artist who did the PyTexas 2010
t-shirt.  This evening after work I might be able to post the artwork
on the PyTexas blog.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: PyTexas: last day for $25 registration, talk proposal

2012-09-01 Thread Brad Allen
Whoops, false alarm. Tomorrow, August 31 is actually the last day to
register and pay at the $25 rate for PyTexas. Likewise for talk
proposals.

On Thu, Aug 30, 2012 at 3:36 PM, Brad Allen bradallen...@gmail.com wrote:
 Just wanted to send out this quick reminder--today is the last day for
 PyTexas $25 registration; starting tomorrow it will cost $50.

 http://www.pytexas.org/chance/1/register/

 Today is also your last day to post your talk proposals.

 http://www.pytexas.org/chance/1/talks/add/

 Btw, there is going to be a PyTexas t-shirt given away with every
 registration. I've seen advance drafts which are beautiful, drawn and
 colored by Kat Metgzer, the same artist who did the PyTexas 2010
 t-shirt.  This evening after work I might be able to post the artwork
 on the PyTexas blog.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[issue15100] Race conditions in shutil.copy, shutil.copy2 and shutil.copyfile

2012-07-05 Thread Brad Tilley
Additionally, shutil.copyfile procedure seems to have a problem with
symlinks that could result in the corruption of content of any file on
filesystem (in favorable conditions).

---

Does the shutil.copyfile corruption issue impact Python 2.6? And, what
sort of favorable conditions need to exist for this to happen? I ask
because we are seeing some file corruption on a GPFS filesystem where we
are using Python 2.6 and shutil.copyfile with symlinks.

I'm not on this list, so cc me if you reply to the list and want me to see
the response.

Thanks,

Brad

___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: emacs user interface design? a talk by Bret Victor

2012-02-27 Thread Brad
On Feb 26, 7:01 pm, NanoThermite FBibustards
nanothermitefbibustardsa...@gmail.com wrote:
 @Xah Lee, he only tell one point, fast interpreter avoiding Edit-
 Compile-Run cycle, and make it INTERACTIVE, the guy did not teach
 nothing of design. The principle was first given by Margaret Hamilton
 and Zeldin.

Bret's main point is that creators need immediate feedback. Okay,
that's Forth. But he illustrated something else about the Forth way of
working. When you try ideas out immediately, you discover things you
wouldn't have thought of if you had written the whole program and then
worked through debugging and integration.

Another point he made is about crusaders (my word), people who see
something wrong with the status quo and make it their business to
change it based on principle. Chuck wasn't the crusader type (maybe he
didn't look good in spandex).
-- 
http://mail.python.org/mailman/listinfo/python-list


signed to unsigned

2012-02-17 Thread Brad Tilley
In C or C++, I can do this for integer conversion:

unsigned int j = -327681234; // Notice this is signed.

j will equal 3967286062. I thought with Python that I could use struct
to pack the signed int as an unsigned int, but that fails:

 x = struct.pack(I, -327681234)
Traceback (most recent call last):
  File stdin, line 1, in module
struct.error: integer out of range for 'I' format code

Is there an easy way in Python to do the same conversion that C or C++
code does? Thanks for any advice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: signed to unsigned

2012-02-17 Thread Brad Tilley
 Pack it as the actual type, then unpack it as the desired type:

 Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
 Type help, copyright, credits or license for more information. 
 from struct import pack, unpack
  unpack('=I', pack('=i',-327681234))

 (3967286062,)

 I would think there's some more efficient way to do this though.

 Cheers,
 Chris


Thanks Chris! I was doing it backwards. I only have a few of these
right now, so performance isn't a concern. I appreciate the advice.

Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: signed to unsigned

2012-02-17 Thread Brad Tilley

  0x  -327681234

 3967286062

Very nice! Thanks for that example. Unsigned long longs:

0x  -9151314442815602945
9295429630893948671L
-- 
http://mail.python.org/mailman/listinfo/python-list


Make a small function thread safe

2011-12-16 Thread Brad Tilley
Hey guys,

I have a C++ function that I'd like to replicate (as closely as
possible) in Python. Here's an example:

107 void increment_counter( unsigned int counter )
108 {
109 boost::mutex::scoped_lock lock( counter_lock );
110 ++counter;
111 }

A thread locks the function on entrance and then releases it on exit.
What is the equivalent way to do this in Python?

Many thanks!

Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Make a small function thread safe

2011-12-16 Thread Brad Tilley
On Fri, Dec 16, 2011 at 8:33 AM, Tim Wintle tim.win...@teamrubber.comwrote:

 On Fri, 2011-12-16 at 05:21 -0800, Brad Tilley wrote:
  107 void increment_counter( unsigned int counter )
  108 {
  109 boost::mutex::scoped_lock lock( counter_lock );
  110 ++counter;
  111 }


 with counter_lock:
counter += 1


 ... where counter_lock is a threading.Lock instance.

 (see docs for the threading module)




So something like this then:

import threading

shared_container = []
lock = threading.Lock()

class thread_example( threading.Thread ):

def __init__( self ):
threading.Thread.__init__ (self)

def run(t):
lock
shared_container.append(t.name)

# main

threads = []
for i in xrange(10):
thread = thread_example()
threads.append(thread)

for thread in threads:
thread.start()

for item in shared_container:
print item
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Make a small function thread safe

2011-12-16 Thread Brad Tilley
On Fri, Dec 16, 2011 at 9:24 AM, Brad Tilley kj4...@gmail.com wrote:



 On Fri, Dec 16, 2011 at 8:33 AM, Tim Wintle tim.win...@teamrubber.comwrote:

 On Fri, 2011-12-16 at 05:21 -0800, Brad Tilley wrote:
  107 void increment_counter( unsigned int counter )
  108 {
  109 boost::mutex::scoped_lock lock( counter_lock );
  110 ++counter;
  111 }


 with counter_lock:
counter += 1


 ... where counter_lock is a threading.Lock instance.

 (see docs for the threading module)




 So something like this then:

 import threading

 shared_container = []
 lock = threading.Lock()

 class thread_example( threading.Thread ):

 def __init__( self ):
 threading.Thread.__init__ (self)

 def run(t):
 lock
 shared_container.append(t.name)

 # main

 threads = []
 for i in xrange(10):
 thread = thread_example()
 threads.append(thread)

 for thread in threads:
 thread.start()

 for item in shared_container:
 print item


Or perhaps run should look like this instead:

def run(t):
lock.acquire()
shared_container.append(t.name)
lock.release()

That seems a bit barbaric to me, not sure.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Make a small function thread safe

2011-12-16 Thread Brad Tilley
On Dec 16, 9:36 am, Tim Wintle tim.win...@teamrubber.com wrote:

 should be:
       def run(t):
           with lock:
               shared_container.append(t.name)

 (or lock.acquire() and lock.release() as you mentioned)


Thanks Tim. The with statement is closer to the C++ code (IMO) more so
than the explicit acquire() and release() so I'll use that approach. I
appreciate your advice.

Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


10 Reasons You Should Attend PyTexas 2011...Register Now!

2011-08-11 Thread Brad Allen
If you're in the Texas area, please check out this post explaining
registration and the 10 reasons
you should consider attending PyTexas 2011:

http://pytexas.blogspot.com/2011/08/10-reasons-you-should-attend-pytexas.html

We opened registration on Monday morning with this post to the local
user groups, and so far 68 have registered within these past three
days, with 53 confirmed and 15 tentative.

I'm confident we can pass 100 registrations and optimistic and
planning for a maximum of 150 attendees. PyTexas 2011 is going to be a
great conference, so please help spread the word, and pass that URL
around.

Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


PyTexas 2011 Call for Proposals

2011-06-13 Thread Brad Allen
PyTexas 2011, the fourth annual Python programming conference for
Texas and the surrounding region, will take place Saturday September
10 and Sunday September 11, 2011 at Texas AM University in College
Station, Texas.

Last year with 94 attendees, PyTexas 2010 reached critical mass to
achieve an exciting event akin to a small taste of PyCon, and this
year we're want to further boost participation and sponsor support. In
order to succeed, we need you to step forward and commit to giving a
presentation, a tutorial, or perhaps organize a panel discussion...go
ahead and propose your idea, whether serious or silly, we want to
consider it.

We are also looking for proposals for keynote speakers, and are
working toward obtaining sponsor pledges to bring in funding to pay
travel expenses for speakers willing to travel. If you are outside the
Texas area, and want to give a presentation, please contact me to
discuss reimbursement options.

PyTexas is especially interested in hosting a Beginner's Track for
those new to Python. If your proposal would be suitable for inclusion
in a Beginner's Track, please indicate so. Organizers will work with
speakers and instructors in the Beginner's Track to help them
coordinate their talks/tutorials into a coherent learning curve for
new Python users.

Please submit proposals by end of day (23:59 CST) July 16, 2011.
Accepted speakers will be notified by August 1.

For details on submitting a proposal see:

http://pytexas.org/CallForProposals2011

If you are undecided about submitting a proposal, or have questions,
please feel free to contact me.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


python 3 - instantiating class from user input

2011-04-06 Thread Brad Bailey
I dont understand why this is such a big deal. Nor do i understand why google 
can't find a reasonable answer. If one can't figure out from the title what I'm 
trying to do, then a look at code should firmly plant the intent. The general 
idea of the code is, in my opinion, very basic. 

I notice, that when you are coding a class instance, it's in the format of:
newInstance = someClass()

OK, so we are calling someClass as if it's a function. Is there a way to do 
something to the effect of:
 someClass(newInstance)

I've seen all kinds of hacks and workarounds that seem 10 times more 
complicated that this ought to be. 

class inventoryItem:
itsDecrtiption = None
itsVendor = None
itsCost = None
itsMarkup = None
itsQuantity = None

newItem = input('enter the new item to add to inventory')
findItem = input('enter the item number to find')

def addItem(newItem):
pass

def lookupItem(findItem):
if findItem:
doSomething()
else:
complain()
addItem(findItem)
-- 
http://mail.python.org/mailman/listinfo/python-list


Python CPU

2011-04-01 Thread Brad
Hi All,

I've heard of Java CPUs. Has anyone implemented a Python CPU in VHDL
or Verilog?

-Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python Tools for Visual Studio from Microsoft - Free Open Source

2011-03-13 Thread Brad Davies



 From: pa...@cruzio.com
 To: santacruz-...@hotmail.com
 Subject: Fw: Python Tools for Visual Studio from Microsoft - Free  Open 
 Source
 Date: Thu, 10 Mar 2011 18:47:19 -0800
 
 
 - Original Message - 
 From: pyt...@bdurham.com
 To: roland garros rolandgarros...@gmail.com; python-list@python.org
 Sent: Thursday, March 10, 2011 2:03 AM
 Subject: Re: Python Tools for Visual Studio from Microsoft - Free  Open 
 Source
 
 
  Roland,
 
  http://pytools.codeplex.com
 
  Looks very impressive! Thank you for sharing this work.
 
  For others following this thread
 
  - this add-in to Visual Studio works with CPython 2.5 - 3.2 and is not
  dependent on .NET or IronPython
 
  - this project also brings HPC (high performance computing) and MPI
  support to CPython using the latest Microsoft API's for large scale data
  and computing
 
  Regards,
  Malcolm
  -- 
  http://mail.python.org/mailman/listinfo/python-list
 
  
 

Hi Roland, Malcolm and everyone,

As it turns out, I have Microsoft Visual Studio Express 2010 and when I tried 
to run the installer, it stopped and gave
me a message that Visual Studio 2010 must be installed.  The free integrated 
shell can be downloaded.  I saw on the 
web page that a 'VS Shell' could be downloaded.  I am assuming that PythonTools 
was tested for Microsoft Visual Studio 
Professional 2010, not Express and that is the problem.  I don't want 2 Visual 
Studios on my system, is that what would happen
 if I downloaded VS Shell?  And where would VS Shell go?  Would it make itself 
the default of some things?

(I am emailing from a diff acct than usual)

Regards,

Patty


  -- 
http://mail.python.org/mailman/listinfo/python-list


Python SIG for Healthcare IT

2011-03-11 Thread Brad Allen
For those seeking to work with Python-based tools in the healthcare
IT industry, this SIG (special interest group) can provide a forum to
discuss challenges and hopefully foster knowledge sharing and tools
development. Relevant topics include tools for working with healthcare
standard data formats, industry news items, professional development,
and success stories about Python and open source in the healthcare
industry. Along the way, this SIG page can be updated with links to
relevant projects and resources.

If this interests you, please join this discussion on the mailing list:

  http://mail.python.org/mailman/listinfo/healthcare

This is a new list, so it has no archives as of yet.

If you're attending PyCon today, please join us in a face to face meeting
at 1pm in the Hanover A open space room. As with all open space
meetings, all are welcome, including those with no healthcare IT
background interested in joining the industry.
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue10392] GZipFile crash when fileobj.mode is None

2010-11-13 Thread Brad Greenlee

Brad Greenlee b...@footle.org added the comment:

Understood. I just felt that fileobj.mode == None should be handled the same 
way that GzipFile(...,mode=None) is handled.

I've submitted a patch to Django: http://code.djangoproject.com/ticket/14681

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10392
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10392] GZipFile crash when fileobj.mode is None

2010-11-12 Thread Brad Greenlee

Brad Greenlee b...@footle.org added the comment:

GzipFile.__init__ considers mode == None to be the equivalent of undefined, and 
sets it to the default of 'rb'. I see fileobj.mode == None as the same thing.

That said, it is probably a bug in Django as well; I'll look into that. I still 
think that GzipFile should handle this gracefully.

--
status: pending - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10392
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10392] GZipFile crash when fileobj.mode is None

2010-11-12 Thread Brad Greenlee

Brad Greenlee b...@footle.org added the comment:

Yes, but if I actually passed mode=None in, the behavior would be the same, no?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10392
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10392] GZipFile crash when fileobj.mode is None

2010-11-11 Thread Brad Greenlee

New submission from Brad Greenlee b...@footle.org:

If GZipFile.__init_ is passed a fileobj that has a mode attribute set to None, 
it will crash with a 'NoneType' object is unsubscriptable error when it tries 
to read the first character of the mode.

I ran across this when trying to pass GZipFile an uploaded file in Django 
1.2.3. Django produced an InMemoryUploadedFile object that has a mode attribute 
set to None.

The attached patch fixes the issue by only using fileobj.mode if it exists and 
is not None.

(The patch is against 2.7, although the issue exists in all versions I've 
looked at.)

--
components: Library (Lib)
files: gzip_mode_fix.diff
keywords: patch
messages: 121021
nosy: bgreenlee
priority: normal
severity: normal
status: open
title: GZipFile crash when fileobj.mode is None
type: crash
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3
Added file: http://bugs.python.org/file19576/gzip_mode_fix.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10392
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?

2010-08-26 Thread Brad
On Aug 25, 4:05 am, Alex McDonald b...@rivadpm.com wrote:
 Your example of writing code with
 memory leaks *and not caring because it's a waste of your time* makes
 me think that you've never been a programmer of any sort.

Windows applications are immune from memory leaks since programmers
can count on regular crashes to automatically release previously
allocated RAM.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?

2010-08-21 Thread Brad
On Aug 21, 3:36 am, David Kastrup d...@gnu.org wrote:

 I think there must be some programmer gene.  It is not enough to be able
 to recognize O(n^k) or worse (though it helps having a more exact rather
 than a fuzzy notion of them _if_ you have that gene).  

Some of the best minds in comp.lang.forth have a penchant for sarcasm
- one of the reasons I always read their posts. Maybe it gets lost on
the international crowd, but I love it.

-Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?

2010-08-17 Thread Brad
On Aug 17, 10:34 am, Standish P stnd...@gmail.com wrote:
 On Aug 16, 11:09 am, Elizabeth D Rather erat...@forth.com wrote:

 How are these heaps being implemented ? Is there some illustrative
 code or a book showing how to implement these heaps in C for example ?

Forth does not use a heap, except maybe to implement malloc/free which
many Forth apps do not use. The dictionary is a linked list structure.
Now seems like a good time for you to teach yourself Forth (by
studying the best commercial implementation you can find) since you
seem to be working with a clean slate. But I will say a few things
about stacks in general.

There are many ways to implement stacks. The simplest is to declare
some space for the stack and then post-increment or pre-decrement a
stack pointer depending on whether you're pushing or popping. Normally
you make the memory for them big enough that they don't overflow.

If you are concerned about stack overflow you can change the
implementation. Add bounds checking, for example.

Another trick is to use an 8-bit stack pointer. Then you will have a
circular stack. If there is underflow or overflow it at least will not
step on other data. It will only return bad data, which you may find
preferable to an ugly crash. OTOH, bugs that cause spectacular
failures tend to be discovered. You can also initialize the stack
memory with a pattern like 0xDEAD and then after sufficiently
exercising the code, examine the memory contents to see the high
water mark of the stack pointer.

-Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


PyTexas 2010 Call for Proposals

2010-06-14 Thread Brad Allen
PyTexas 2010, the fourth annual Python programming conference for
Texas and the surrounding region, will take place Saturday August 28,
2010 at the Baylor University in Waco, Texas. A variety of activities
are under consideration, including tutorials, scheduled talks,
Lightning Talks, Open Spaces, and Sprints.

PyTexas invites all interested people to submit proposals for
scheduled talks, tutorials, and panels. All topics of interest to
Python programmers will be considered, including topics suitable for
inclusion in a Beginner's Track.

For more detail please see the PyTexas wiki:

http://pytexas.org/CallForProposals2010
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


PyTexas survey

2010-05-27 Thread Brad Allen
Hello Python Community,

If you live in the Texas region, please help with PyTexas 2010
planning by filling out the new survey. This will tell us things like
whether the planned Aug 28 date works for you, whether you have a user
group in your area, and more importantly your t-shirt size :-).

http://www.surveymonkey.com/s/pytexas2010

For more info on PyTexas, see the following:

http://pytexas.org
http://dfwpython.blogspot.com/

Thanks!

P.S. We need Python teachers for our beginner track!  This same survey
is planned to reach a large number of area students, and they will
likely be interested in learning Python fundamentals, web development
in popular frameworks like Django, BFG, etc. Please watch for the
upcoming call for proposals, and feel free to contact me directly.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac?

2010-02-22 Thread Brad Harms
On Mon, 22 Feb 2010 09:10:38 -0800, Alex Quinn wrote:

 Is there a way to have some kind of database (i.e. sqlite3, bsddb, dbm,
 etc.) that works out of the box on any Win/Linux/Mac machine with Python
 2.6+ or 3.x? It's okay if the file format is different between machines,
 but I want my script to work without having to install anything.
 
 Problems with current modules:
 
 * Shelve used to do this.  Unfortunately, since bsddb was
 deprecated/removed from the standard distro and Windows doesn't have dbm
 or gdbm, the only remaining option on Windows is dumbdbm, which is
 discouraged in the docs.
 
 * Sqlite3 should fill the void now.  However, in my experience, nearly
 every Linux Python install I encounter has a broken sqlite3 module
 (ImportError: No module named _sqlite3). It's a well-documented issue,
 but it the solution generally requires root access, which I don't have
 on these servers.
 
 Potential solutions:
 
 * Could I somehow bundle with my project the _sqlite3.so file and/or
 whatever else it needs? Or is there an alternate sqlite3 module I could
 use as a fallback that would just interface with the sqlite3 executable
 on the machine (i.e. /usr/local/bin/sqlite3)?
 
 * Is there a way to drop bsddb into my project so it works out of the
 gate (no install) on either Linux, Windows, or Mac?
 
 If you have any ideas, I'd be most appreciative.  My objective here is
 just to find a portable and reliable solution that I can use for small
 projects.
 
 Thanks,
 Alex

Hi,

I'm speaking with little experience here, but one thought I had is to try 
compiling Pysqlite ( http://pypi.python.org/pypi/pysqlite/2.5.6 ) for 
each of your target OS's, probably using GCC cross compilers for the 
platforms you aren't compiling on, then sort of splice them together so 
that _sqlite3 always points to the binary for the current OS.

This snippet might help you get started:

import sys

# Linux binary
if 'linux' in sys.platform.lower():
import _sqlite3_linux as _sqlite3

# Windows binary
elif 'win32' == sys.platform:
import _sqlite3_windows as _sqlite3

# Mac binary
elif 'darwin' == sys.platform:
import _sqlite3_mac as _sqlite3

sys.modules['_sqlite3'] = _sqlite3


I'm not exactly sure when you would run this code. It would have to be 
sometime before you import the main sqlite3 module.

-- 
Brad Harms -- http://alphaios.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: method to intercept string formatting % operations

2010-02-05 Thread Brad Allen
On Fri, Feb 5, 2010 at 9:49 AM, Jean-Michel Pichavant
jeanmic...@sequans.com wrote:

 Anyway why would you want to use the tuple form ? it's beaten in every
 aspect by the dictionary form.

I'm subclassing a namedtuple, and adding some additional functionality
such as __getitem__, __setitem__, so that the namedtuple also behaves
like a dict.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: KeyboardInterrupt

2009-12-09 Thread Brad Harms
On Thu, 10 Dec 2009 00:29:45 +, mattia wrote:

 Il Wed, 09 Dec 2009 16:19:24 -0800, Jon Clements ha scritto:
 
 On Dec 9, 11:53 pm, mattia ger...@gmail.com wrote:
 Hi all, can you provide me a simple code snippet to interrupt the
 execution of my program catching the KeyboardInterrupt signal?

 Thanks,
 Mattia
 
 Errr, normally you can just catch the KeyboardInterrupt exception -- is
 that what you mean?
 
 Jon.
 
 Ouch, so the simplest solution is just insert in the 'main' function a
 try/catch? I believed there was the necessity to create a signal and
 than attach the KeyboardInterrupt to it...


KeyboardInterrupt is just an exception that gets raised when CTLR+C (or 
the OS's equivalent keyboard combo) gets pressed. It can occur at any 
point in a script since you never know when the user will press it, which 
is why you put the try: except KeyboardInterrupt: around as much of your 
script as possible.  The signal that the OS sends to the Python 
interpreter is irrelevant.


-- 
Brad Harms -- http://alphaios.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Feature request: String-inferred names

2009-12-04 Thread Brad Harms
On Fri, 04 Dec 2009 18:05:03 +1100, Ben Finney wrote:

 Brad Harms fearsomedragon...@gmail.com writes:
 
 Anyway, it looks like the docs agree with you
 (http://docs.python.org/glossary.html#term-attribute), so I'm not going
 to argue.
 
 That's good, because the terms are quite well established in Python
 terminology.

I'm just saying, if the official documentation defines the term 
attribute thusly, it would be silly of me to continue using my own made-
up term that means pretty much the same thing.

 
 However, for the purpose of clean communication, I'd still like to have
 terms that refer specifically to:

 1.) Regular attributes, ie. those that are shortcuts to items in the
 directly associated object's __dict__,
 
 I don't know what you mean by “shortcuts to items”. The names are looked
 up in dictionaries; where do shortcuts play a part?
 
 Try “instance attribute”, as distinct from “class attribute”.
 
 2.) Attributes whose values are determined or assigned dynamically by
 indirectly calling a function (like properties and instancemethods)
 
 Yes, the term “property” seems to do what you want.

I wasn't asking what you call any object or any /kind/ of object. I was 
asking for a term (noun?) that describes the WAY the object is accessed 
as an attribute of an instance, with the connotation that the value of 
the attribute would be calculated dynamically (by calling a function) at 
the time the attribute was accessed. Note that the value does not have to 
exist in ANY __dict__ anywhere, it could, for example, be calculated by 
object.__getattribute__.

Example: 

 obj.attr

Without knowing what obj is or what attr is as it pertains to obj, 
but knowing that attr does not actually a key in obj.__dict_,_ and that 
its value has to be determined by some other means, what do you call the 
thing on the code line above? That is what I'm trying to find out. (HINT: 
Don't think about how the Python interpreter parses it or how the value 
is eventually determined. That's not relevant. Just understand that the 
value does not come directly from obj.__dict__.)

By the way, a property is an object of type __builtin__.property. A 
property with a reference in an attribute of a class /does/ call a 
function when you try to access that property as an attribute of the 
class's instances. However, properties are not the only objects that have 
this behavior, so calling objects that behave in this way is ambiguous. I 
think the actual, general term for such an object is data descriptor, 
or just descriptor. (http://docs.python.org/glossary.html#term-
descriptor)

 
 The value of an instance method is *not* determined dynamically: its
 value is a function, and that value is no more dynamic than any other
 attribute of the instance.

That is incorrect. Indirectly accessing an instancemethod of a class 
through an instance of that class will trigger the descriptor behavior of 
the instancemethod type. This produces a new object, another 
instancemethod, that is bound to the instance through which it was 
accessed. It's a mouthful to say, but it is sufficiently accurate.

Heck, just look at this:

 class Foo(object):
... def spam(self): pass
...
 foo = Foo()
 foo.spam
bound method Foo.spam of __main__.Foo object at 0x931c46c
 Foo.spam
unbound method Foo.spam
 foo.spam is Foo.spam
False
 foo.spam == Foo.spam
False
 Foo.spam.__get__(foo, Foo)
bound method Foo.spam of __main__.Foo object at 0x931c46c
 Foo.__dict__[spam].__get__(foo, Foo)
bound method Foo.spam of __main__.Foo object at 0x931c46c
 Foo.__dict__[spam].__get__(foo, Foo) is foo.spam
False
 Foo.__dict__[spam].__get__(foo, Foo) == foo.spam
True

Also note the fact that Foo.spam is an _instancemethod_ object and not 
just a function, even though it was defined as just a function in the 
class body. That's because function objects are descriptors as well; it 
lets them produce unbound instancemethods. I'm not precisely sure how 
this works, though. I think it only happens when the metaclass of a class 
processes the functions in the class block.

 
 3.) Attributes that are read from an object with regular .dot syntax,
 but are actually attributes (in the sense of #1 above) of the __dict__
 of the object's class.
 
 This is a “class attribute” as distinct from an “instance attribute”.


I know it's called that, but I was talking more about the fact of it 
being accessed through an instance of the class rather than 


 The distinction isn't often worth knowing, though, so you'll probably
 still have to explain it when you use it.

I beg to differ. For one thing, it affects descriptors.


Anyway, these metadiscussions are starting to give me headaches. Let's 
talk about something more interesting...


PS. I'm truly sorry once again for using email addresses and names 
inconsistently. I really am trying to solve the problem. I'm going to try 
accessing the list via comp.lang.python and Pan (newsreader for Gnome) 
for a while. Hopefully it will help.

-- 
Brad Harms

Re: Feature request: String-inferred names

2009-12-04 Thread Brad Harms
On Fri, 04 Dec 2009 09:00:42 +, Steven D'Aprano wrote:
 Not all such attributes are actually found in instance.__dict__.

...I hadn't even considered __slots__ yet. Hm...

 Or dynamic attributes returned by __getattr__ or __getattribute__.

I'm looking for a generic term, because it's too cumbersome to say 
properties or dynamic attributes using __getattr__ or __getattribute__ 
all the time.

That will be my last message for a while...good night, c.p.l.

-- 
Brad Harms -- http://alphaios.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Feature request: String-inferred names

2009-12-03 Thread Brad Harms
On Tue, 2009-12-01 at 14:38 +, Steven D'Aprano wrote:
 On Mon, 30 Nov 2009 18:55:46 -0800, The Music Guy wrote:
 
  Lie Ryan, I think I see what you're saying about using __dict__ to add
  members to a class, but it's not quite the same. __dict__ is only for
  attributes, NOT properties, methods, etc. which all come from the class
  of an object rather than the object's __dict__. 
 
 Almost but not quite.
 
 It's just special double-underscore methods like __init__ __add__ etc 
 that have to be in the class rather than the instance. (To be precise, 
 you can add such a method to the instance, but it won't be called 
 automatically.) Likewise staticmethods and classmethods won't work 
 correctly unless they are in the class. But ordinary methods work fine: 
 the only tricky bit is creating them in the first place.
 
  class K(object):
 ... pass
 ...
  k = K()
  import types
  k.method = types.MethodType(lambda self: I am %s % self, k)
  k.method()
 'I am __main__.K object at 0xb7cc7d4c'

...I'm not sure I follow your logic.

Yes, you can create an instancemethod out of a function and assign it to
an instance after (or during) its instantiation, which is what Python's
class/instance model provides automatically. However, to do so manually
in this manner completely disregards the fundamentals of object-oriented
programming, not to mention the basic guiding principles of nearly all
Python code in existence. It totally breaks inheritance and
polymorphism. Maybe I'm missing something, but I can't see how that line
of thought helps anything.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Feature request: String-inferred names

2009-12-03 Thread Brad Harms
On Tue, 2009-12-01 at 16:58 +0100, Bruno Desthuilliers wrote:
 The Music Guy a écrit :
 (snip)
  Lie Ryan, I think I see what you're saying about using __dict__ to add
  members
 
 No members in Python - only attributes.

  to a class, but it's not quite the same. __dict__ is only for
  attributes, NOT properties, methods, etc. which all come from the
  class of an object rather than the object's __dict__.
 
 properties and methods (well, functions actually) ARE attributes... of 
 the class object. And you can of course access the obj.__class__.__dict__
 
 Just for the record...

When I say member I am using it as a general term that describes any
value that can be accessed (get, set, del) through an object. If the
object is referenced by a variable named `foo`, then by using `foo.name`
or one of the XXXattr functions, one can access the member of `foo`
called `name`. What's important to note, though, is that the term
member does not make any assumption about how `foo.name` is
implemented.

When I say attribute, however, I am referring specifically to a member
of an object where the member's name is a key in the object's __dict__,
and the value is the one that is paired with that key.

Example:

class Foo(object):
def __init__(self):
self._x = 5

@property
def x(self):
return self._x

@x.setter
def x(self,val):
self._x = val

def frob(self):
print I've been frobbed!

foo = Foo()

foo._x # Each of these is both a member and an attribute.
foo.y = 6 
foo.x  # Each of these is a member, but neither is an attribute.
foo.frob

To be perfectly precise, foo.y is only an attribute AFTER the assignment
has been performed. Before 6 is assigned, foo.y is only a member and
not an attribute because y does not yet exist as a key in foo's
__dict__.

Essentially, I just use member as a convenience term. I thought that
was the convention among the community, but evidently it isn't as widely
used as such as I thought. 

Anyway, it looks like the docs agree with you
(http://docs.python.org/glossary.html#term-attribute), so I'm not going
to argue. However, for the purpose of clean communication, I'd still
like to have terms that refer specifically to:

1.) Regular attributes, ie. those that are shortcuts to items in the
directly associated object's __dict__, 
2.) Attributes whose values are determined or assigned dynamically by
indirectly calling a function (like properties and instancemethods)
3.) Attributes that are read from an object with regular .dot syntax,
but are actually attributes (in the sense of #1 above) of the  __dict__
of the object's class.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Feature request: String-inferred names

2009-11-29 Thread Brad Harms
On Sun, Nov 29, 2009 at 7:49 PM, Lie Ryan lie.1...@gmail.com wrote:

 On 11/29/2009 12:22 PM, The Music Guy wrote:

 When I first started seeing @ show up in Python code, I said what the
 heck is that? It looks so weird and _ugly_.I would never try to mess
 with that. But I started seeing it more and more, so I asked #python
 what it was. They told me about decorators, so I looked it up in the
 docs, and I thought the idea was interesting. It took me a while to
 figure out exactly how they worked--and judging from messages I've
 seen in #python a number of people have the same trouble understanding
 them.


 And we don't want a second flood of users asking about foo.$bar.


  My point is that any particular syntax would look ugly to you only
 because you haven't seen it in use enough, and haven't used it enough
 yourself.


 You're absolutely right, and I have *never needed* to use the plain
 getattr/setattr/delattr enough to even bother considering a syntax that
 already looks ugly at first sight. For @decorators, everyone used it *often
 enough* BEFORE it turned into a syntax that the ugly syntax is justified and
 become acceptable. If you can find a syntax that doesn't look ugly at
 first sight +0, fine by me; otherwise -1, I don't want to be forced to read
 an ugly syntax for a feature that I don't use often enough. It's not just
 the syntax, the necessity+syntax don't add up well.


  But of course you haven't--it's not currently a valid

 syntax. However, the ugliness would seem to go away after the syntax
 had been in use for a while. And again, the EXACT syntax of the
 feature can be adjusted until its just right.


 In so far, your definition of adjusting only means something around
 [a-zA-Z0-9_]+\.[^a-zA-Z0-9_][{(\[]?[a-zA-Z0-9_]+[})\]]?



 that class of syntax is ugly; some are more acceptable (e.g. obj.[arg]) the
 old thread have spawned better alternatives than that class of syntax.



  As for my specific use case, it's somewhat difficult to explain.


 You know that:
 If the implementation is hard to explain it's a bad idea.
 -- Zen of Python --

 right?


  The

 general idea was to isolate a pattern that I spotted repeated in
 several unrelated parts of my project. The pattern manifested itself
 as a set of 4-5 methods and/or properties on a class whose objects
 were designed to work in conjunction with other objects that fit a
 particular behavior. These other objects had methods and properties
 that were designed to interact with the first type of object in a
 similar but--how should I say--inverted fashion.


 Do you mean something like this?

 class A(object):
@property
def the_b(self):
return self._b
@the_b
def the_b(self, new_b):
self._b = new_b
self._b._a = self

 class B(object):
@property
def the_a(self):
return self._a
@the_a
def the_a(self, new_a):
self._a = new_a
self._a._b = self

 am I getting you right? If not, please elaborate and give an example of
 what you actually meant.

 --
 http://mail.python.org/mailman/listinfo/python-list



I understand that in all likelyhood this feature won't be added to Python
anytime soon, if at all. But I'd like to continue this discussion anyway;
it's been enlightening for me. Even though I don't agree with the views of
some of the people who've replied, I like the insight. And anyway, I think
that if the syntax were already present, people would feel a lot more
positively about it; it's the idea of adding it in so late in the game that
people seem to have a problem with for the most part.

It doesn't seem like anybody besides inhahe has actually realized that my
proposition is actually different than PEP 363 in a subtle but crucial way.
It's not _literally_ a shorthand for accessing the *attr functions; that's
just the way I originally assumed it would be used most often. However, I
have since realized that the syntax is more powerful than I originally
thought: ANYWHERE that a name appeared--this includes function names, class
names, function parameters, possibly even module names--could be replaced by
an expression that would be evaluated to the name. That makes the use of any
kind of brackets, except maybe angle brackets, bad options, as it would
conflict with [lists,] {dicts,} (tuples,) or generic parenthesized
(expressions). There must be a unique indicator of some kind, something that
isn't already in use by the interpreter. That way there is no possible way
that it could get confused with another syntactical construct.

So you could do something like this:


def class_factory(this, that)
get_that = get_+that
set_that = set_+that
_that = _ + that

class $this (object):

def __init__(self, $that = None):
self.$_that = $that

def $get_that (self):
return self.$_that

def $set_that (self, $that):
self.$_that = $that

$that = 

Re: Feature request: String-inferred names

2009-11-29 Thread Brad Harms
On Sun, Nov 29, 2009 at 9:59 PM, Carl Banks pavlovevide...@gmail.comwrote:

 Another thing that can be determined through common sense is that if
 you have object that you are calling getattr and setattr on so much
 that you think you need special syntax, you should have been using a
 dict.


(Re-send; original was sent to the wrong address. I--I mean, Gmail--sent it
to the wrong address by mistake. :P )

While you were writing this and your previous reply I was working on a
response that kind of covers what you were talking about, but I'm going to
say something anyway.

Well, yes, the names would have to be determined at run time. That's what
getattr and setattr do, except that that do it in the context of an object
rather than the local scope. However, I was under the impression that
python's mechanism for looking up local names was the same as the mechanism
used to look up attributes because names and attributes seem to function
pretty much the same way. This I assumed because of the functionality of the
locals() and globals() functions, which seem to act like the __dict__
attribute on objects except that the work on the current scope. Also, there
is the __builtins__ module, which actually _is_ an object, but its names can
be accessed in the same way as locals and globals.

I had considered the possibility of a peformance hit, however I didn't
anticipate that it would be all that much. Not that it matters, but how much
are we talking? 10% ? 50% ? In any case, I'm not really an expert on
Python's internal constructions, but because of this discussion I'm
considering taking some time to learn them.


Python is unique compared to several other languages in that it makes a
distinction between items and attributes. Some languages, like
JavaScript and Lua, do not make this distinction. They leave it to the
programmer to access members of an object either as an item or as an
attribute. I don't think there is necessarily anything wrong with this, nor
do I think there is anything wrong with Python's separation.

That said, just because you can use the proposed syntax to use an object in
the same way as a dict does not mean that it works the other way around. I'm
not talking about the allowance of any specific object to have any number of
pairings between arbitrary keys and values. That's what dicts are for, and
that's what indexing syntax implies.

Rather, I'm talking about specific, concrete variables which objects are
expected (though not technically required) to have bound to them according
to how the object is intended to be used. (That's probably not the best
definition of an attribute, but it's the best I can think of ATM.)

I'm not trying to discard Python's distinction between items and attributes,
but I don't want to be limited by it due to mere syntactical constraints,
either.

May the Penguin in the sky bless your every subroutine,

Brad Harms
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Feature request: String-inferred names

2009-11-25 Thread Brad
On Nov 25, 10:49 pm, Chris Rebert c...@rebertia.com wrote:
 On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy

 fearsomedragon...@gmail.com wrote:
  Hello all,

  I just posted to my blog about a feature that I'd like to see added to
  Python. Before I go through the trouble of learning how to write a PEP or
  how to extend the Python interpreter, I want to know what people in the
  community have to say about it.

 http://alphaios.blogspot.com/2009/11/python-string-inferred-names-wor...

  As far as I know, a feature like this does not appear in any existing PEPs.
  (If it does I would appreciate it if someone could tell me what PEP it is.)

  Please give and comments you may have, but I request that you be
  constructive if you must criticize...thank you!

 Ugly, Perlish, and as you even admit, entirely unnecessary.
 And you'd need to wait at least a year 
 anyway:http://www.python.org/dev/peps/pep-3003/

 Cheers,
 Chris
 --http://blog.rebertia.com

Like I said, lots of things in Python are unnecessary, but that
doesn't make them useless, and it certainly doesn't mean they
shouldn't exist. My proposed feature is not useless; I think it would
make a lot of code easier.

As for it being ugly...well, that's really a matter of opinion and
experience. How ugly it looks to you will be a product of how well you
think it can be used, and how well you use it yourself. When I first
looked at decorators, I thought they were not only ugly but confusing.
Now that I understand them, however, I hardly consider them ugly,
and see them as a shining example of Python's abilities. (By the way,
decorators are another example of a feature that is entirely
unnecessary, but still very useful.)

As for the wait, that's to be expected. I'm willing to wait.
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue7159] Urllib2 authentication memory.

2009-10-17 Thread Brad Olson

New submission from Brad Olson br...@movedbylight.com:

For each request requiring HTTP authentication, urllib2 submits the
request without authentication, receives the server's 401
error/challenge, then re-submits the request with authentication.

This is compliant behavior. The problem comes in that urllib2 repeats
this for every ensuing request to the same namespace.

At times this is just an inefficiency--every request gets sent twice,
often with POST data (which can be sizeable).

Sometimes, especially with large POST bodies, this causes a connection
failure.

(Mercurial suffers greatly from this (and I have suggested workaround to
that team.)

This isn't non-compliant behavior, but RFC2617 (sections 2, 3.3)
suggests that once an HTTP client authenticates, it pre-emptively send
authentication with ensuing requests.

More analysis and fix suggestions at
bitbucket.org/bradobro/liquidhg/wiki/Home.

--
components: Library (Lib)
messages: 94180
nosy: bradobro
severity: normal
status: open
title: Urllib2 authentication memory.
type: behavior
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7159
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Sequence splitting

2009-07-03 Thread Brad
On Jul 2, 9:40 pm, Pablo Torres N. tn.pa...@gmail.com wrote:

 If it is speed that we are after, it's my understanding that map and
 filter are faster than iterating with the for statement (and also
 faster than list comprehensions).  So here is a rewrite:

 def split(seq, func=bool):
         t = filter(func, seq)
         f = filter(lambda x: not func(x), seq)
         return list(t), list(f)


In my simple tests, that takes 1.8x as long as the original solution.
Better than the itertools solution, when func is short and fast. I
think the solution here would worse if func was more complex.

Either way, what I am still wondering is if people would find a built-
in implementation useful?

-Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sequence splitting

2009-07-03 Thread Brad
On Jul 2, 8:17 pm, Pablo Torres N. tn.pa...@gmail.com wrote:

 This sounds like it belongs to the python-ideas list.  I suggest
 posting there for better feedback, since the core developers check
 that list more often than this one.

I tried posting on python-ideas and received a You are not allowed to
post to this mailing list reply. Perhaps because I am posting through
Google groups? Or maybe one must be an approved member to post?

-Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sequence splitting

2009-07-03 Thread Brad
On Jul 3, 12:57 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 I've never needed such a split function, and I don't like the name, and
 the functionality isn't general enough. I'd prefer something which splits
 the input sequence into as many sublists as necessary, according to the
 output of the key function.

That's not a bad idea, I'll have to experiment with the alternatives.
My thought process for this, however, was that filter itself already
splits the sequence and it would have been more useful had it not
thrown away half of what it discovers. It could have been written to
returned two sequences with very litter perf hit for all but very
large input sequences, and been useful in more situations. What I
*really* wanted was a way to make filter itself more useful, since it
seems a bit silly to have two very similar functions.

Maybe this would be difficult to get into the core, but how about this
idea: Rename the current filter function to something like split or
partition (which I agree may be a better name) and modify it to
return the desired true and false sequences. Then recreate the
existing filter function with a wrapper that throws away the false
sequence.

Here are two simplified re-creations of situations where I could have
used partition (aka split):

words = ['this', 'is', 'a', 'bunch', 'of', 'words']
short, long = partition(words, lambda w: len(w)  3)

d = {1 : 'w', 2 : 'x' ,3 : 'y' ,4 : 'z'}
keys = [1, 3, 4, 9]
found, missing = partition(keys, d.has_key)


There are probably a dozen other approaches, but the existing filter
is fast, clear, and *almost* good enough. So when is this useful in
general: Whenever filter itself is useful, but you want to use both
sides of the partitioning work it already does.


-Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sequence splitting

2009-07-02 Thread Brad
On Jul 2, 8:14 pm, Paul Rubin http://phr...@nospam.invalid wrote:
 schickb schi...@gmail.com writes:
  def split(seq, func=None):
      if func is None:
          func = bool
      t, f = [], []
      for item in seq:
          if func(item):
              t.append(item)
          else:
              f.append(item)
      return (t, f)

 untested:

    def split(seq, func=bool):
       xs = zip(seq, itertools.imap(func, seq))
       t = list(x for (x,y) in xs if y)
       f = list(x for (x,y) in xs if not y)
       return (t, f)

In my testing that is 3.5x slower than the original solution (and less
clear imo). I fixed my version to take a bool default. Either way, I'm
not really looking for additional ways to do this in Python unless
I've totally missed something. What I am considering is writing it in
C, much like filter.

-Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sequence splitting

2009-07-02 Thread Brad
On Jul 2, 8:17 pm, Pablo Torres N. tn.pa...@gmail.com wrote:
 On Jul 2, 9:56 pm, schickb schi...@gmail.com wrote:

  I have fairly often found the need to split a sequence into two groups
  based on a function result.

 This sounds like it belongs to the python-ideas list.  I suggest
 posting there for better feedback, since the core developers check
 that list more often than this one.

Thanks, I didn't know about that list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sequence splitting

2009-07-02 Thread Brad
On Jul 2, 9:08 pm, Paul Rubin http://phr...@nospam.invalid wrote:
 Brad schi...@gmail.com writes:
  On Jul 2, 8:14 pm, Paul Rubin http://phr...@nospam.invalid wrote:
   schickb schi...@gmail.com writes:
def split(seq, func=None):
    if func is None:
        func = bool
    t, f = [], []
    for item in seq:
        if func(item):
            t.append(item)
        else:
            f.append(item)
    return (t, f)

   untested:

      def split(seq, func=bool):
         xs = zip(seq, itertools.imap(func, seq))
         t = list(x for (x,y) in xs if y)
         f = list(x for (x,y) in xs if not y)
         return (t, f)

  In my testing that is 3.5x slower than the original solution (and less
  clear imo). I fixed my version to take a bool default. Either way, I'm
  not really looking for additional ways to do this in Python unless
  I've totally missed something. What I am considering is writing it in
  C, much like filter.

 I'm a little skeptical that the C version will help much, if it's
 evaluating a python function at every list element.  

Perhaps true, but it would be a nice convenience (for me) as a built-
in written in either Python or C. Although the default case of a bool
function would surely be faster.

 Here's a variant of your version:

  def split(seq, func=bool):
      t, f = [], []
      ta, fa = t.append, f.append
      for item in seq:
          (ta if func(item) else fa)(item)
      return (t, f)

 This avoids some dict lookups and copying.  I wonder if that helps
 significantly.

Faster, but in tests of a few short sequences only 1% so.

-Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue4773] HTTPMessage not documented and has inconsistent API across 2.6/3.0

2009-03-26 Thread Brad Miller

Brad Miller bonel...@gmail.com added the comment:

On Thu, Mar 26, 2009 at 4:29 PM, Barry A. Warsaw rep...@bugs.python.orgwrote:


 Barry A. Warsaw ba...@python.org added the comment:

 I propose that you only document the getitem header access API.  I.e.
 the thing that info() gives you can be used to access the message
 headers via message['content-type'].  That's an API common to both
 rfc822.Messages (the ultimate base class of mimetools.Message) and
 email.message.Message.


As I've found myself in the awkward position of having to explain the new
3.0 api to my students I've thought about this and have some
ideas/questions.
I'm also willing to help with the documentation or any enhancements.

Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: 'addinfourl' object is unsubscriptable

I wish I new what an addinfourl object was.

'Fri, 27 Mar 2009 00:41:34 GMT'

'Fri, 27 Mar 2009 00:41:34 GMT'

['Date', 'Server', 'Last-Modified', 'ETag', 'Accept-Ranges',
'Content-Length', 'Connection', 'Content-Type']

Using x.headers over x.info()  makes the most sense to me, but I don't know
that I can give any good rationale.  Which would we want to document?

'text/html; charset=ISO-8859-1'

I guess technically this is correct since the charset is part of the
Content-Type header in HTTP but it does make life difficult for what I think
will be a pretty common use case in this new urllib:  read from the url (as
bytes) and then decode them into a string using the appropriate character
set.

As you follow this road, you have the confusing option of these three calls:

'iso-8859-1'
 x.headers.get_charsets()
['iso-8859-1']

I think it should be a bug that get_charset() does not return anything in
this case.  It is not at all clear why get_content_charset() and
get_charset() should have different behavior.

Brad


 --
 nosy: +barry

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue4773
 ___


--
Added file: http://bugs.python.org/file13430/unnamed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4773
___divbrdiv class=gmail_quoteOn Thu, Mar 26, 2009 at 4:29 PM, Barry A. 
Warsaw span dir=ltrlt;a 
href=mailto:rep...@bugs.python.org;rep...@bugs.python.org/agt;/span 
wrote:brblockquote class=gmail_quote style=margin:0 0 0 
.8ex;border-left:1px #ccc solid;padding-left:1ex;
br
Barry A. Warsaw lt;a href=mailto:ba...@python.org;ba...@python.org/agt; 
added the comment:br
br
I propose that you only document the getitem header access API.  I.e.br
the thing that info() gives you can be used to access the messagebr
headers via message[#39;content-type#39;].  That#39;s an API common to 
bothbr
rfc822.Messages (the ultimate base class of mimetools.Message) andbr
email.message.Message.br/blockquotedivbr/divdivAs I#39;ve found 
myself in the awkward position of having to explain the new 3.0 api to my 
students I#39;ve thought about this and have some ideas/questions.div
br/divdivI#39;m also willing to help with the documentation or any 
enhancements./divdivbr/divdivgt;gt;gt; x = 
urllib.request.urlopen(#39;a 
href=http://knuth.luther.edu/python/test.html;http://knuth.luther.edu/python/test.html/a#39;)/div
divdivgt;gt;gt; x[#39;Date#39;]/divdivTraceback (most recent call 
last):/divdiv  File quot;lt;stdingt;quot;, line 1, in 
lt;modulegt;/divdivTypeError: #39;addinfourl#39; object is 
unsubscriptable/div
divbr/divdivI wish I new what an addinfourl object 
was./divdivbr/divdivdivgt;gt;gt; a 
href=http://x.info;x.info/a()[#39;Date#39;]/divdiv#39;Fri, 27 Mar 
2009 00:41:34 GMT#39;/divdivbr
/divdivdivgt;gt;gt; x.headers[#39;Date#39;]/divdiv#39;Fri, 27 
Mar 2009 00:41:34 GMT#39;/divdivbr/divdivdivgt;gt;gt; 
x.headers.keys()/divdiv[#39;Date#39;, #39;Server#39;, 
#39;Last-Modified#39;, #39;ETag#39;, #39;Accept-Ranges#39;, 
#39;Content-Length#39;, #39;Connection#39;, #39;Content-Type#39;]/div
divbr/divdivUsing x.headers over a href=http://x.info;x.info/a() 
 makes the most sense to me, but I don#39;t know that I can give any good 
rationale.  Which would we want to document?/div/div/div/div
divbr/divdivdivgt;gt;gt; 
x.headers[#39;Content-Type#39;]/divdiv#39;text/html; 
charset=ISO-8859-1#39;/divdivbr/divdivI guess technically this is 
correct since the charset is part of the Content-Type header in HTTP but it 
does make life difficult for what I think will be a pretty common use case in 
this new urllib:  read from the url (as bytes) and then decode them into a 
string using the appropriate character set./div
divbr/div/divdivAs you follow this road, you have the confusing 
option of these three calls:/divdivbr/divdivdivgt;gt;gt; 
x.headers.get_charset()/divdivgt;gt;gt; 
x.headers.get_content_charset()/div
div#39;iso-8859-1#39;/divdivgt;gt;gt; 
x.headers.get_charsets()/divdiv[#39;iso-8859-1#39;]/divdivbr/divdivI

[issue4773] HTTPMessage not documented and has inconsistent API across 2.6/3.0

2009-03-18 Thread Brad Miller

Changes by Brad Miller bonel...@gmail.com:


--
nosy: +bmiller

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4773
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5232] Setting font from preference dialog in IDLE on OS X broken

2009-03-17 Thread Brad Miller

Brad Miller bonel...@gmail.com added the comment:

I get the same problem when I try to change the key set.  This is on on 
intel build using Tk 8.5, and the latest 3.1 source checked out with 
bzr.  

I too changed the order of /Library/Frameworks and 
/System/Library/Frameworks in setup.py

A simple fix for me was to add the line

root.instance_dict = {}

in macosxsupport.py  That does not seem to have any other ill effects.

--
nosy: +bmiller

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5232
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2704] IDLE: Patch to make PyShell behave more like a Terminal interface

2009-03-11 Thread Brad Miller

Brad Miller bonel...@gmail.com added the comment:

I hand applied the patch because I hoped it would fix the problem of the 
cursor going all the way to the left of the  in the Python shell when 
you press home or ctrl-a.  The patch as it is does not solve this problem 
on the Mac.  I've uploaded the patch as a unified diff to make it easier 
for others who might want to give it a try.

The patch does a great job of scrolling through the history at the current 
prompt.  This is a great improvement!  Thanks.

--
nosy: +bmiller
Added file: http://bugs.python.org/file13306/PyShell.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2704
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5276] IDLE startup file .Idle.py not documented

2009-03-10 Thread Brad Miller

Brad Miller bonel...@gmail.com added the comment:

Here's a simple patch that documents the different startup files.  It is 
missing a good use case for .Idle.py but I'd be happy to add that if 
someone can give me one.

--
keywords: +patch
message_count: 1.0 - 2.0
nosy: +bmiller
nosy_count: 2.0 - 3.0
Added file: http://bugs.python.org/file13296/idlestartdoc.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5276
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2610] string representation of range and dictionary views

2009-03-10 Thread Brad Miller

Brad Miller bonel...@gmail.com added the comment:

Just to restart the discussion on the original issue since I see that 
the latest 3.1 has solved the problem with dict_keys, dict_values, etc 
al objects.  Many thanks!

A suggestion was made by Alexander to create a custom displayhook that 
could be included in the standard library.  From the research I've done 
it looks like a solution for range would be something like the 
following:

import sys
def eduhook(o):
if o is None:
return
if isinstance(o,range):
print(list(o))
else:
print(repr(o))

sys.displayhook = eduhook

Now if 5233/5234 were approved I could tell my students to setup an 
environment variable PYTHONSTARTUP that points to a file that imports a 
module containing the above code.  (or I could just tell them to import 
said module each time.)

The above hook appears to work fine.  Is there anything obvious I'm 
missing?  If this is along the right track then I could extend it to 
support other custom display ideas that my fellow educators have in 
mind.

Thanks,

Brad

--
message_count: 30.0 - 31.0

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2610
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



String Comparison Testing

2008-12-24 Thread Brad Causey
Python Version: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310
32 bit (Intel)] on win32

List,

I am trying to do some basic log parsing, and well, I am absolutely floored
at this seemingly simple problem. I am by no means a novice in python, but
yet this is really stumping me. I have extracted the pertinent code snippets
and modified them to function as a standalone script. Basically I am reading
a log file ( in this case, testlog.log) for entries and comparing them to
entries in a safe list (in this case, safelist.lst). I have spent numerous
hours doing this several ways and this is the most simple way I can come up
with:

code
import string

safelistfh = file('safelist.lst', 'r')
safelist = safelistfh.readlines()

logfh = file('testlog.log', 'r')
loglines = logfh.readlines()

def safecheck(line):
for entry in safelist:
print 'I am searching for\n'
print entry
print '\n'
print 'to exist in\n'
print line
comp = line.find(entry)
if comp  -1:
out = 'Failed'
else:
out = 'Passed'
return out

for log in loglines:
finalentry = safecheck(log)
if finalentry == 'Failed':
print 'This is an internal site'
else:
print 'This is an external site'
/code

The contents of the two files are as follows:

safelist.lst
http://www.mysite.com
/safelist.lst

testlog.log
http://www.mysite.com/images/homepage/xmlslideshow-personal.swf
/testlog.log

It seems that no matter what I do, I can't get this to fail the  if comp 
-1: check. (My goal is for the check to fail so that I know this is just a
URL to a safe[internal] site)
My assumption is that the HTTP:// is somehow affecting the searching
capabilities of the string.find function. But I can't seem to locate any
documentation online that outlines restrictions when using special
characters.

Any thoughts?

Thanks!



-Brad Causey
CISSP, MCSE, C|EH, CIFI

Zero Day Consulting
--
http://mail.python.org/mailman/listinfo/python-list


VERY simple string comparison issue

2008-12-24 Thread Brad Causey
Python Version: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310
32 bit (Intel)] on win32

List,

I am trying to do some basic log parsing, and well, I am absolutely floored
at this seemingly simple problem. I am by no means a novice in python, but
yet this is really stumping me. I have extracted the pertinent code snippets
and modified them to function as a standalone script. Basically I am reading
a log file ( in this case, testlog.log) for entries and comparing them to
entries in a safe list (in this case, safelist.lst). I have spent numerous
hours doing this several ways and this is the most simple way I can come up
with:

code
import string

safelistfh = file('safelist.lst', 'r')
safelist = safelistfh.readlines()

logfh = file('testlog.log', 'r')
loglines = logfh.readlines()

def safecheck(line):
for entry in safelist:
print 'I am searching for\n'
print entry
print '\n'
print 'to exist in\n'
print line
comp = line.find(entry)
if comp  -1:
out = 'Failed'
else:
out = 'Passed'
return out

for log in loglines:
finalentry = safecheck(log)
if finalentry == 'Failed':
print 'This is an internal site'
else:
print 'This is an external site'
/code

The contents of the two files are as follows:

safelist.lst
http://www.mysite.com
/safelist.lst

testlog.log
http://www.mysite.com/images/homepage/xmlslideshow-personal.swf
/testlog.log

It seems that no matter what I do, I can't get this to fail the  if comp 
-1: check. (My goal is for the check to fail so that I know this is just a
URL to a safe[internal] site)
My assumption is that the HTTP:// is somehow affecting the searching
capabilities of the string.find function. But I can't seem to locate any
documentation online that outlines restrictions when using special
characters.

Any thoughts?

Thanks!
-Brad
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >