Re: Why is array.array('u') deprecated?

2015-05-08 Thread jonathan . slenders
Le vendredi 8 mai 2015 15:11:56 UTC+2, Peter Otten a écrit :
> > So, this works perfectly fine and fast. But it scares me that it's
> > deprecated and Python 4 will not support it anymore.
> 
> Hm, this doesn't even work with Python 3:

My mistake. I should have tested better.

> >>> data = array.array("u", u"x"*1000)
> >>> data[100] = "y"
> >>> re.search("y", data)
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python3.4/re.py", line 166, in search
> return _compile(pattern, flags).search(string)
> TypeError: can't use a string pattern on a bytes-like object
> 
> You can search for bytes
> 
> >>> re.search(b"y", data)
> <_sre.SRE_Match object; span=(400, 401), match=b'y'>
> >>> data[101] = "z"
> >>> re.search(b"y", data)
> <_sre.SRE_Match object; span=(400, 401), match=b'y'>
> >>> re.search(b"yz", data)
> >>> re.search(b"y\0\0\0z", data)
> <_sre.SRE_Match object; span=(400, 405), match=b'y\x00\x00\x00z'>
> 
> but if that is good enough you can use a bytearray in the first place.

Maybe I'll try that. Thanks for the suggestions!

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


Re: Why is array.array('u') deprecated?

2015-05-08 Thread jonathan . slenders
> Can you expand a bit on how array("u") helps here? Are the matches in the 
> gigabyte range?

I have a string of unicode characters, e.g.:

data = array.array('u', u'x' * 10)

Then I need to change some data in the middle of this string, for instance:

data[50] = 'y'

Then I want to use re to search in this text:

re.search('y', data)

This has to be fast. I really don't want to split and concatenate strings. Re 
should be able to process it and the expressions can be much more complex than 
this. (I think it should be anything that implements the buffer protocol).

So, this works perfectly fine and fast. But it scares me that it's deprecated 
and Python 4 will not support it anymore.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why is array.array('u') deprecated?

2015-05-08 Thread jonathan . slenders
Le vendredi 8 mai 2015 12:29:15 UTC+2, Steven D'Aprano a écrit :
> On Fri, 8 May 2015 07:14 pm, jonathan.slenders wrote:
> 
> > Why is array.array('u') deprecated?
> > 
> > Will we get an alternative for a character array or mutable unicode
> > string?
> 
> 
> Good question.
> 
> Of the three main encodings for Unicode, two are variable-width: 
> 
> * UTF-8 uses 1-4 bytes per character 
> * UTF-16 uses 2 or 4 bytes per character
> 
> while UTF-32 is fixed-width (4 bytes per character). So you could try faking
> it with a 32-bit array and filling it with string.encode('utf-32').


I guess that doesn't work. I need to have something that I can pass to the re 
module for searching through it. Creating new strings all the time is no 
option. (Think about gigabyte strings.)


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


Why is array.array('u') deprecated?

2015-05-08 Thread jonathan . slenders
Why is array.array('u') deprecated?

Will we get an alternative for a character array or mutable unicode string?

Thanks!
Jonathan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I check if a string is a prefix of any possible other string that matches a given regex.

2014-10-08 Thread jonathan . slenders
Le mercredi 8 octobre 2014 01:40:11 UTC+2, MRAB a écrit :
> If you're not interested in generating an actual regex, but only in
> 
> matching the prefix, then it sounds like you want "partial matching".
> 
> 
> 
> The regex module supports that:
> 
> 
> 
> https://pypi.python.org/pypi/regex

Wow, thanks a lot! That really helps me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I check if a string is a prefix of any possible other string that matches a given regex.

2014-10-07 Thread jonathan . slenders

> > Logically, I'd think it should be possible by running the input string 
> > against the state machine that the given regex describes, and if at some 
> > point all the input characters are consumed, it's a match. (We don't have 
> > to run the regex until the end.) But I cannot find any library that does 
> > it...
> 
> 
> 
> Strictly speaking, a DFA or NFA always consumes the entire input; the
> 
> question of interest is whether it halts in an accepting state or not.
> 
> 
> 
> It would be easy to transform a DFA or NFA in the manner that you
> 
> want, though.  For each non-accepting state, determine whether it has
> 
> any transitions that lead in one or more steps to an accepting state.
> 
> Modify the FSM so that each such state is also an accepting state.


Thanks, I'll make every state of the FSM an accepting state.

My use case is to implement autocompletion for a regular language. So I think 
if the input is accepted by the FSM that I build, it's a valid "prefix", and 
the autocompletion can be generated by looking at which transitions are 
possible at that point.

More pointers are welcome, but I think that I have enough to start the 
implementation.

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


How do I check if a string is a prefix of any possible other string that matches a given regex.

2014-10-07 Thread jonathan . slenders
Hi everyone,


Probably I'm turning the use of regular expressions upside down with this 
question. I don't want to write a regex that matches prefixes of other strings, 
I know how to do that. I want to generate a regex -- given another regex --, 
that matches all possible strings that are a prefix of a string that matches 
the given regex.


E.g. You have the regex  ^[a-z]*4R$  then the strings "a", "ab", "A4" "ab4" are 
prefixes of this regex (because there is a way of adding characters that causes 
the regex to match), but "4a" or "a44" or not.
How do I programmatically create a regex that matches "a", "ab", "A4", etc.. 
but not "4a", "a44", etc..

Logically, I'd think it should be possible by running the input string against 
the state machine that the given regex describes, and if at some point all the 
input characters are consumed, it's a match. (We don't have to run the regex 
until the end.) But I cannot find any library that does it...

Thanks a lot, if anyone knows the answer to this question!


Cheers,
Jonathan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Looking for a name for a deployment framework...

2013-06-25 Thread jonathan . slenders
Le mardi 25 juin 2013 06:38:44 UTC+2, Chris Rebert a écrit :
> Er, Salt is likewise written in Python.

You're right. Salt is also Python, excuse me, and it's very powerful as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a name for a deployment framework...

2013-06-24 Thread jonathan . slenders
Thanks everyone, I'll think about it.

The main reason is that I'm working on the documentation, and this a a good 
opportunity to think about the naming. python-deploy-framework or 
python-deployer could be too boring.
-- 
http://mail.python.org/mailman/listinfo/python-list


Looking for a name for a deployment framework...

2013-06-24 Thread jonathan . slenders
Hi all,

Any suggestions for a good name, for a framework that does automatic server 
deployments?

It's like Fabric, but more powerful.
It has some similarities with Puppet, Chef and Saltstack, but is written in 
Python.

Key points are that it uses Python, but is still very declarative and supports 
introspection. It supports parallel deployments, and interactivity. And it has 
a nice commandline shell with autocompletion for traversing the deployment tree.

The repository:
https://github.com/jonathanslenders/python-deployer/tree/refactoring-a-lot-v2


Suggestions welcome :)
Jonathan
-- 
http://mail.python.org/mailman/listinfo/python-list