Re: OOP for System Administrator

2015-04-06 Thread pankaj sharma
Yes Michael, your guess is right. I once was a Java Programmer :)

Thanks for the advice and link.

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


implementing pyshark

2015-04-06 Thread Michael S.

Hi everyone. while trying to implement pyshark, i am getting this error:
   import pyshark
  capture = pyshark.LiveCapture(interface='wlan0')
  capture.sniff(timeout=50)
  capture
i have tried also to run it through interpreter yet, i got this error:
import pyshark
---
ImportError   Traceback (most recent call last)
 in ()
> 1 import pyshark

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-py2.7.egg/pyshark/__init__.py 
in ()

> 1 from pyshark.capture.live_capture import LiveCapture
  2 from pyshark.capture.file_capture import FileCapture
  3 from pyshark.capture.remote_capture import RemoteCapture
  4 from pyshark.capture.inmem_capture import InMemCapture

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-py2.7.egg/pyshark/capture/live_capture.py 
in ()

> 1 from pyshark.capture.capture import Capture
  2 from pyshark.tshark.tshark import get_tshark_interfaces
  3
  4
  5 class LiveCapture(Capture):

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-py2.7.egg/pyshark/capture/capture.py 
in ()

  1 from __future__ import unicode_literals
  2 import os
> 3 import logbook
  4 import sys
  5

/usr/local/lib/python2.7/dist-packages/logbook/__init__.py in ()
 12
 13
---> 14 from logbook.base import LogRecord, Logger, LoggerGroup, 
NestedSetup, \
 15  Processor, Flags, get_level_name, lookup_level, 
dispatch_record, \

 16  CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG, NOTSET, \

/usr/local/lib/python2.7/dist-packages/logbook/base.py in ()
 16 from datetime import datetime
 17 from logbook import helpers
---> 18 from logbook.concurrency import thread_get_name, 
thread_get_ident, greenlet_get_ident

 19
 20 from logbook.helpers import to_safe_json, parse_iso8601, 
cached_property, \


/usr/local/lib/python2.7/dist-packages/logbook/concurrency.py in ()
 29
 30 if has_gevent:
---> 31 from gevent._threading import (Lock as ThreadLock,
 32RLock as ThreadRLock,
 33get_ident as thread_get_ident,

ImportError: No module named _threading

i tried importing threading first and importing pyshark, but the answer 
was the same.

any suggestions?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to deliver different source distributions for different Python versions?

2015-04-06 Thread Dylan Evans
> I would like to distribute a python package with different code for 
> Python 2.* than for Python 3.*. (Mostly this is because of different 
> unicode string handling). 

> There is nothing in to setuptools or PyPi that directly supports 
> this scenario. 
The 2to3 utility will handle the unicode differences. You can set the keyword 
argument use_2to3 to True in setup.py dependent on the version number like so:



extra = {}

if sys.version_info >= (3, ):

    extra['use_2to3'] = True



and then put **extra in setup.py. This will run 2to3 on the code when it 
installs it. I don’t know whether this is good style but it does work. I got it 
from the feedparser source code. 


-- 
Dylan Evans

On 6 April 2015 at 11:05:47, python-list-requ...@python.org 
(python-list-requ...@python.org) wrote:

Send Python-list mailing list submissions to  
python-list@python.org  

To subscribe or unsubscribe via the World Wide Web, visit  
https://mail.python.org/mailman/listinfo/python-list  
or, via email, send a message with subject or body 'help' to  
python-list-requ...@python.org  

You can reach the person managing the list at  
python-list-ow...@python.org  

When replying, please edit your Subject line so it is more specific  
than "Re: Contents of Python-list digest..."  
Today's Topics:  

1. Permission denied when opening a file that was created  
concurrently by os.rename (Windows) (Alexey Izbyshev)  
2. Re: Permission denied when opening a file that was created  
concurrently by os.rename (Windows) (Chris Angelico)  
3. Re: Permission denied when opening a file that was created  
concurrently by os.rename (Windows) (Alexey Izbyshev)  
4. Re: Permission denied when opening a file that was created  
concurrently by os.rename (Windows) (Dave Angel)  
5. Help with pipes, buffering and pseudoterminals (Daniel Ellis)  
6. Re: Permission denied when opening a file that was created  
concurrently by os.rename (Windows) (Terry Reedy)  
7. Is it possible to deliver different source distributions for  
different Python versions? (Dave Hein)  
8. ANN: polynice 0.7 - a nice(1) like utility for throttling  
processes (garabik-news-2005...@kassiopeia.juls.savba.sk)  
9. Re: Help with pipes, buffering and pseudoterminals (Nobody)  
10. Re: Help with pipes, buffering and pseudoterminals  
(Cameron Simpson)  
11. Re: Is it possible to deliver different source distributions  
for different Python versions? (Steven D'Aprano)  
12. XML Parsing (Sepideh Ghanavati)  
13. Re: XML Parsing (Ben Finney)  
14. Re: Is it possible to deliver different source distributions  
for different Python versions? (Mark Lawrence)  
15. Re: Is it possible to deliver different source distributions  
for different Python versions? (Stefan Behnel)  
16. Re: XML Parsing (Stefan Behnel)  
17. Re: OOP for System Administrator (pankaj sharma)  
18. implementing pyshark (Michael S.)  
Hello!  

I've hit a strange problem that I reduced to the following test case:  
* Run several python processes in parallel that spin in the following  
loop:  
while True:  
if os.path.isfile(fname):  
with open(fname, 'rb') as f:  
f.read()  
break  
* Then, run another process that creates a temporary file and then  
renames it to the name than other processes are expecting  
* Now, some of the reading processes occasionally fail with "Permission  
denied" OSError  

I was able to reproduce it on two Windows 7 64-bit machines. It seems  
when the file appears on the filesystem it is still unavailable to  
reading, but I have no idea how it can happen. Both source and  
destination files are in the same directory, and the destination doesn't  
exist before calling os.rename. Everything I could find indicates that  
os.rename should be atomic under this conditions even on Windows, so  
nobody should be able to observe the destination in unaccessible state.  

I know that I can workaround this problem by removing useless  
os.path.isfile() check and wrapping open() with try-except, but I'd like  
to know the root cause of the problem. Please share you thoughts.  

The test case is attached, the main file is test.bat. Python is  
expected to be in PATH. Stderr of readers is redirected to *.log. You  
may need to run several times to hit the issue.  

Alexey Izbyshev,  
research assistant,  
ISP RAS  


On Mon, Apr 6, 2015 at 3:45 AM, Alexey Izbyshev  wrote:  
> The test case is attached, the main file is test.bat. Python is expected to  
> be in PATH. Stderr of readers is redirected to *.log. You may need to run  
> several times to hit the issue.  

You have an interesting-looking problem, but the attachment didn't  
arrive. Is it short enough to include in-line as text in your email?  

ChrisA  

On 2015-04-05 20:45, Alexey Izbyshev wrote:  
> Hello!  
>  
> I've hit a strange problem that I reduced to the following test case:  
> * Run several python processes in parallel that spin in the following  
> loop:  
> while True:  
> if os

Re: Is it possible to deliver different source distributions for different Python versions?

2015-04-06 Thread Steven D'Aprano
On Mon, 6 Apr 2015 09:23 pm, Dylan Evans wrote:

[content snipped]


Hi Dylan, and welcome!

If you're going to post in response to people's questions, would you please
disable HTML email and trim your responses? This mailing list is mirrored
on Usenet, as comp.lang.python, where HTML is against the rules of the
newsgroup and is considered rude.

If you're planning on sticking around as a regular contributor, and we hope
you do, the best way to read this group is to use individual emails, not
digests. When you reply to a digest, unless you trim the response, we get a
copy of the ENTIRE digest, in this case eighteen posts we have already seen
before. And then *doubled*, because Gmail sends a plain text version plus a
HTML version. So we get 1855 lines of text shoved down our throat,
including a massive block of rubbish that looks like this:


Re: implementing pyshark

2015-04-06 Thread Steven D'Aprano
On Mon, 6 Apr 2015 06:40 pm, Michael S. wrote:

> Hi everyone. while trying to implement pyshark, i am getting this error:
[...]

> ImportError: No module named _threading


Well that's awesome. I don't think I've seen that in Python 2.7 before.
Apparently, you are using a version of Python compiled without support for
threading. I didn't think that was still possible.

How did you install Python? Did you build it from source?

My guess is that you did build from source, but you were missing some
packages needed for threading support so the Python interpreter was built
without threading. That means you'll have to re-install to fix this
problem.

But first you'll need to install the necessary dependencies. What operating
system and/or distro are you using? It looks like Linux or Unix, or maybe
Mac OS X.


-- 
Steven

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


Re: implementing pyshark

2015-04-06 Thread Peter Otten
Michael S. wrote:

> Hi everyone. while trying to implement pyshark, i am getting this error:
> import pyshark
>capture = pyshark.LiveCapture(interface='wlan0')
>capture.sniff(timeout=50)
>capture
> i have tried also to run it through interpreter yet, i got this error:
> import pyshark
> 
---
> ImportError   Traceback (most recent call
> last)  in ()
> > 1 import pyshark
> 
> /usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-
py2.7.egg/pyshark/__init__.py
> in ()
> > 1 from pyshark.capture.live_capture import LiveCapture
>2 from pyshark.capture.file_capture import FileCapture
>3 from pyshark.capture.remote_capture import RemoteCapture
>4 from pyshark.capture.inmem_capture import InMemCapture
> 
> /usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-
py2.7.egg/pyshark/capture/live_capture.py
> in ()
> > 1 from pyshark.capture.capture import Capture
>2 from pyshark.tshark.tshark import get_tshark_interfaces
>3
>4
>5 class LiveCapture(Capture):
> 
> /usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-
py2.7.egg/pyshark/capture/capture.py
> in ()
>1 from __future__ import unicode_literals
>2 import os
> > 3 import logbook
>4 import sys
>5
> 
> /usr/local/lib/python2.7/dist-packages/logbook/__init__.py in ()
>   12
>   13
> ---> 14 from logbook.base import LogRecord, Logger, LoggerGroup,
> NestedSetup, \
>   15  Processor, Flags, get_level_name, lookup_level,
> dispatch_record, \
>   16  CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG, NOTSET, \
> 
> /usr/local/lib/python2.7/dist-packages/logbook/base.py in ()
>   16 from datetime import datetime
>   17 from logbook import helpers
> ---> 18 from logbook.concurrency import thread_get_name,
> thread_get_ident, greenlet_get_ident
>   19
>   20 from logbook.helpers import to_safe_json, parse_iso8601,
> cached_property, \
> 
> /usr/local/lib/python2.7/dist-packages/logbook/concurrency.py in
> ()
>   29
>   30 if has_gevent:
> ---> 31 from gevent._threading import (Lock as ThreadLock,
>   32RLock as ThreadRLock,
>   33get_ident as thread_get_ident,
> 
> ImportError: No module named _threading
> 
> i tried importing threading first and importing pyshark, but the answer
> was the same.
> any suggestions?

Line 30 suggests that pyshark assumes that gevent is installed while line 31 
indicates that gevent is not installed correctly.

So do you have an incomplete install of gevent? Either remove it or replace 
it with a working one, i. e.

import gevent
import gevent._threading

should either both fail or both succeed.

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


Re: Is it possible to deliver different source distributions for different Python versions?

2015-04-06 Thread Ian Kelly
On Mon, Apr 6, 2015 at 5:52 AM, Steven D'Aprano
 wrote:
> To the rest of the list... didn't somebody write up a wiki post on how to
> convince Gmail to be less unreasonable about top posting, quoting, etc?
> Does anyone still have the link?

There is https://wiki.python.org/moin/GoogleGroupsPython about posting
from Google Groups, but I'm not aware of a similar resource for Gmail,
which has far fewer issues. As long as you compose your email in plain
text mode and remember to move the cursor from the top when replying,
Gmail is fine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to deliver different source distributions for different Python versions?

2015-04-06 Thread Chris Angelico
On Tue, Apr 7, 2015 at 12:05 AM, Ian Kelly  wrote:
> There is https://wiki.python.org/moin/GoogleGroupsPython about posting
> from Google Groups, but I'm not aware of a similar resource for Gmail,
> which has far fewer issues. As long as you compose your email in plain
> text mode and remember to move the cursor from the top when replying,
> Gmail is fine.

There's one other niggling issue, and that's that it doesn't support
"Reply to List". So you either have to hit Reply, and then replace the
single recipient with the list address, or Reply-All and remove the
superfluous duplicates. (Personally, I do the latter. Much too easy to
reply to the wrong list, else.)

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


Re: implementing pyshark

2015-04-06 Thread Michael S.
I am using kali-linux(debian based). i have installed all from 
repository. i haven't tried yet to use the source but i don't think it 
was compiled incorrectly. Kali's developers are quite precise in terms 
of OS development.


On 04/06/2015 03:05 PM, Steven D'Aprano wrote:

On Mon, 6 Apr 2015 06:40 pm, Michael S. wrote:


Hi everyone. while trying to implement pyshark, i am getting this error:

[...]


ImportError: No module named _threading


Well that's awesome. I don't think I've seen that in Python 2.7 before.
Apparently, you are using a version of Python compiled without support for
threading. I didn't think that was still possible.

How did you install Python? Did you build it from source?

My guess is that you did build from source, but you were missing some
packages needed for threading support so the Python interpreter was built
without threading. That means you'll have to re-install to fix this
problem.

But first you'll need to install the necessary dependencies. What operating
system and/or distro are you using? It looks like Linux or Unix, or maybe
Mac OS X.




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


Re: implementing pyshark

2015-04-06 Thread Michael S.

import gevent --->  successful
import gevent._threading ---> fails
 output :
In [2]: import gevent._threading
---
ImportError   Traceback (most recent call last)
 in ()
> 1 import gevent._threading

ImportError: No module named _threading

In [3]: import gevent_threading
---
ImportError   Traceback (most recent call last)
 in ()
> 1 import gevent_threading

ImportError: No module named gevent_threading



On 04/06/2015 03:11 PM, Peter Otten wrote:

Michael S. wrote:


Hi everyone. while trying to implement pyshark, i am getting this error:
 import pyshark
capture = pyshark.LiveCapture(interface='wlan0')
capture.sniff(timeout=50)
capture
i have tried also to run it through interpreter yet, i got this error:
import pyshark


---

ImportError   Traceback (most recent call
last)  in ()
> 1 import pyshark

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-

py2.7.egg/pyshark/__init__.py

in ()
> 1 from pyshark.capture.live_capture import LiveCapture
2 from pyshark.capture.file_capture import FileCapture
3 from pyshark.capture.remote_capture import RemoteCapture
4 from pyshark.capture.inmem_capture import InMemCapture

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-

py2.7.egg/pyshark/capture/live_capture.py

in ()
> 1 from pyshark.capture.capture import Capture
2 from pyshark.tshark.tshark import get_tshark_interfaces
3
4
5 class LiveCapture(Capture):

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-

py2.7.egg/pyshark/capture/capture.py

in ()
1 from __future__ import unicode_literals
2 import os
> 3 import logbook
4 import sys
5

/usr/local/lib/python2.7/dist-packages/logbook/__init__.py in ()
   12
   13
---> 14 from logbook.base import LogRecord, Logger, LoggerGroup,
NestedSetup, \
   15  Processor, Flags, get_level_name, lookup_level,
dispatch_record, \
   16  CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG, NOTSET, \

/usr/local/lib/python2.7/dist-packages/logbook/base.py in ()
   16 from datetime import datetime
   17 from logbook import helpers
---> 18 from logbook.concurrency import thread_get_name,
thread_get_ident, greenlet_get_ident
   19
   20 from logbook.helpers import to_safe_json, parse_iso8601,
cached_property, \

/usr/local/lib/python2.7/dist-packages/logbook/concurrency.py in
()
   29
   30 if has_gevent:
---> 31 from gevent._threading import (Lock as ThreadLock,
   32RLock as ThreadRLock,
   33get_ident as thread_get_ident,

ImportError: No module named _threading

i tried importing threading first and importing pyshark, but the answer
was the same.
any suggestions?

Line 30 suggests that pyshark assumes that gevent is installed while line 31
indicates that gevent is not installed correctly.

So do you have an incomplete install of gevent? Either remove it or replace
it with a working one, i. e.

import gevent
import gevent._threading

should either both fail or both succeed.



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


Re: implementing pyshark

2015-04-06 Thread Peter Otten
Michael S. wrote:

[Please don't top-post. Thank you]

> import gevent --->  successful
> import gevent._threading ---> fails
>   output :
> In [2]: import gevent._threading
> 
---
> ImportError   Traceback (most recent call
> last)  in ()
> > 1 import gevent._threading
> 
> ImportError: No module named _threading

And the question is?

Everything that follows comes directly from my crystal ball and has the 
potential to break more stuff; if you try it you do it at your own risk.

Again, most likely you have a broken python-gevent install. If you got this 
by attempting a manual install from source without the necessary build 
dependencies you can either add these and try again.

Alternatively you can remove the debris:

1 Find out the location of the gevent folder:

$ python -c 'import gevent; print gevent.__file__'
/somefolder/gevent/__init__.pyc

2 Remove the gevent folder (unless it's maintained by the package manager).
$ rm -r /somefolder/gevent

Now pyshark should correctly detect that gevent is not available and use a 
fallback.

3 If you need gevent later use the official way to install it

$ sudo apt-get install python-gevent

in the hope that it contains a _threading module and pyshark will start 
using gevent again, this time successfully.

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


Re: implementing pyshark

2015-04-06 Thread Terry Reedy

On 4/6/2015 8:05 AM, Steven D'Aprano wrote:

On Mon, 6 Apr 2015 06:40 pm, Michael S. wrote:


Hi everyone. while trying to implement pyshark, i am getting this error:

[...]


ImportError: No module named _threading



Well that's awesome. I don't think I've seen that in Python 2.7 before.
Apparently, you are using a version of Python compiled without support for
threading. I didn't think that was still possible.


There is (used to be) a 'without threads' buildbot
http://buildbot.python.org/all/builders/AMD64%20Fedora%20without%20threads%203.x
though it has been offline for a year.


--
Terry Jan Reedy

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


Re: Python-list Digest, Vol 139, Issue 7

2015-04-06 Thread Dylan Evans
On Mon, Apr 6, 2015 at 5:52 AM, Steven D’Aprano  wrote:
> I understand that Gmail is a pig about these sorts of things, and makes it
> really hard to avoid breaking list etiquette. We appreciate whatever you
> can do, and while a few of us may bark occasionally, we don't bite.

Oh my days, I’m really sorry about that! It didn’t cross my mind that I was 
using the rich text composer, and I cursed myself for leaving the whole email 
on the end.

I use an email client called Airmail, so I’ve just set plain text as the 
default. It shouldn’t affect me at all.

Thank you for being understanding and my apologies once again. I hope my 
attempt at help was at least readable.

(Also sorry if I’m committing another faux pas by clogging up the list but I 
had to apologise!)

—

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


Python library - WMI.py RegistryValueChangeEvent

2015-04-06 Thread Khyati
I have a question about RegistryValueChangeEvent that I have not been able to 
find an answer to on the internet so far. I would appreciate any help since I 
have already spent a lot of time finding any material that explains this:

What I am trying to do: 
- create an event when a value for a registry key changes

How I am doing it:
>raw_wql = "SELECT * FROM RegistryValueChangeEvent WHERE 
>Hive='HKEY_LOCAL_MACHINE' AND KeyPath='SoftwareTemp' AND ValueName='Name\'"
>watcher = c.watch_for(raw_wql=raw_wql,wmi_class = "__ExtrinsicEvent")
>while TRUE:
>process_created = watcher()

Problem:
the _wmi_event object returned is not coming back as Extrinsic event - 
So, in wmi.py, in class _wmi_watcher:
   "self.is_extrinsic" returns false and I get an exception from the else part 
- [line 1186 - 1195]

What I need 
- Any reference/idea/explanation on => why does RegistryValueChangeEvent 
returns as a Non-Extrinsic  event? even though it has been derived from 
__ExtrinsicEvent

Other information:
Running on Windows 8 64 Bit 
>>> platform.machine()
'AMD64'
>>> platform.architecture()
('64bit', 'WindowsPE')
>>> platform.python_version()
'2.7.8'
>>> platform.python_implementation()
'CPython'

Using WMI-1.4.9.win32 - downloaded via PIP
pywin32-219.win-amd64-py2.7

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


pypi submission?

2015-04-06 Thread Benjamin Schollnick
Folks,

I’m having issues with submitting to pypi.

I can register and upload my package.

nerv:~ Benjamin$ pip search directory_caching
Directory_Caching - A Caching library for Directories & Files
nerv:~ Benjamin$ 

but, if you try to install it using pip:

pip install directory_caching
Reading Profile from ~/dropbox/shellscripts/profile
nerv:~ Benjamin$ pip install directory_caching
Collecting directory-caching
  Could not find any downloads that satisfy the requirement directory-caching
  No distributions at all found for directory-caching

If you do a verbose:

Last login: Mon Apr  6 18:05:02 on ttys000
Reading Profile from ~/dropbox/shellscripts/profile
nerv:~ Benjamin$ pip -v install directory_caching
Collecting directory-caching
  Getting page https://pypi.python.org/simple/directory-caching/
  URLs to search for versions for directory-caching:
  * https://pypi.python.org/simple/directory-caching/
  Getting page https://pypi.python.org/simple/directory-caching/
  Analyzing links from page https://pypi.python.org/simple/directory-caching/
  Could not find any downloads that satisfy the requirement directory-caching
  Cleaning up...
  No distributions at all found for directory-caching
  Exception information:
  Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 232, in 
main
  status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 339, 
in run
  requirement_set.prepare_files(finder)
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 333, in 
prepare_files
  upgrade=self.upgrade,
File "/Library/Python/2.7/site-packages/pip/index.py", line 397, in 
find_requirement
  'No distributions at all found for %s' % req
  DistributionNotFound: No distributions at all found for directory-caching

The package is here, https://github.com/bschollnick/Directory_Caching 
.

And I’ve been messing around with different config files, etc, trying to solve 
the problem myself.  
Can anyone point out what I have done wrong?

If a simpler package would be useful, then 
https://github.com/bschollnick/semantic_url 


I haven’t attempted to release semantic_url yet, simply because I’m trying to 
solve Directory_Caching first.
And yes, I know caching files & directory listings is a black voodoo art, and 
asking for trouble.

This attempts to validate three different ways, and I’ve been using it for 
quite a while without any issue.  It’s invaluable in the web gallery when you 
have a directory that can have 2-4K worth of files.

- Benjamin

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


Re: Python library - WMI.py RegistryValueChangeEvent

2015-04-06 Thread Chris Angelico
On Tue, Apr 7, 2015 at 8:02 AM, Khyati  wrote:
> I have a question about RegistryValueChangeEvent that I have not been able to 
> find an answer to on the internet so far. I would appreciate any help since I 
> have already spent a lot of time finding any material that explains this:
>
> What I am trying to do:
> - create an event when a value for a registry key changes

Thanks for being clear about this part! Unfortunately, there are a few
other parts that aren't clear yet, so hopefully you can expand on your
question a bit.

> How I am doing it:
>>raw_wql = "SELECT * FROM RegistryValueChangeEvent WHERE 
>>Hive='HKEY_LOCAL_MACHINE' AND KeyPath='SoftwareTemp' AND 
>>ValueName='Name\'"

Tip: Try adding "print(raw_wql)" just underneath this line, to see if
you're getting back what you really want. The backslash at the end of
ValueName is not currently doing anything.

>>watcher = c.watch_for(raw_wql=raw_wql,wmi_class = "__ExtrinsicEvent")
>>while TRUE:
>>process_created = watcher()

This code isn't complete. Can you post a complete (and minimal)
example piece of code?

> Problem:
> the _wmi_event object returned is not coming back as Extrinsic event -
> So, in wmi.py, in class _wmi_watcher:
>"self.is_extrinsic" returns false and I get an exception from the else 
> part - [line 1186 - 1195]

It'd help hugely if you could post the entire traceback here - what
exception you're getting, and the exact lines that produce it.

> What I need
> - Any reference/idea/explanation on => why does RegistryValueChangeEvent 
> returns as a Non-Extrinsic  event? even though it has been derived from 
> __ExtrinsicEvent
>
> Other information:
> Running on Windows 8 64 Bit
 platform.machine()
> 'AMD64'
 platform.architecture()
> ('64bit', 'WindowsPE')
 platform.python_version()
> '2.7.8'
 platform.python_implementation()
> 'CPython'
>
> Using WMI-1.4.9.win32 - downloaded via PIP
> pywin32-219.win-amd64-py2.7

Just for reference, this is a general Python discussion list. Lots of
us won't know specific libraries, so all we can offer is fairly
general information. If you can't get the help you need here, you may
do better to look for more specific help about this module.

All the best!

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


Re: Is it possible to deliver different source distributions for different Python versions?

2015-04-06 Thread Dave Hein
On Sunday, April 5, 2015 at 10:28:55 PM UTC-5, Mark Lawrence wrote:
> On 05/04/2015 21:38, Dave Hein wrote:
> > I would like to distribute a python package with different code for
> > Python 2.* than for Python 3.*. (Mostly this is because of different
> > unicode string handling).
> >
> > There is nothing in to setuptools or PyPi that directly supports
> > this scenario.
> >
> > But perhaps there could be some script run at install time that moves
> > the correct source code to the right location? In other works, if I
> > included both source code versions in the distribution (in a src2 and
> > a src3 subdirectory) then a function invoked at install time could
> > detect the python version and copy the appropriate source code to the
> > right location.
> >
> > Is that at all possible? Is there some install time hook that lets me
> > supply custom installation code?
> >
> > --
> > Dave Hein
> >
> 
> I can't help directly but have you looked here 
> https://packaging.python.org/en/latest/ ?

Yep. I looked there first and from that thought that I could 
distribute "wheels" -- a 2.7 wheel, a 3.3 wheel, and a 3.4 wheel.
But the latest setup.py (version 15.0) doesn't build wheels anymore.
It does build binary distributions, but they are tied more to a
particular version of a particular OS rather than to a particular
version of Python.

So, anyway, I think parts of that documentation site are out of
date. And I didn't see anything that let me do what I wanted.

> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

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


Re: Is it possible to deliver different source distributions for different Python versions?

2015-04-06 Thread Dave Hein
On Monday, April 6, 2015 at 12:47:05 AM UTC-5, Stefan Behnel wrote:
> Dave Hein schrieb am 05.04.2015 um 22:38:
> > I would like to distribute a python package with different code for
> > Python 2.* than for Python 3.*. (Mostly this is because of different
> > unicode string handling).
> > 
> > There is nothing in to setuptools or PyPi that directly supports
> > this scenario.
> > 
> > But perhaps there could be some script run at install time that moves
> > the correct source code to the right location? In other works, if I
> > included both source code versions in the distribution (in a src2 and
> > a src3 subdirectory) then a function invoked at install time could
> > detect the python version and copy the appropriate source code to the
> > right location.
> > 
> > Is that at all possible? Is there some install time hook that lets me
> > supply custom installation code?
> 
> Sure. You can simply change the directory in which distutils looks for your
> Python code:
> 
> https://docs.python.org/2/distutils/setupscript.html#listing-whole-packages
> 
> However, in general, you shouldn't be doing this. It's usually easier
> (definitely in the long-term) to keep your sources cross-Py2.x/3.x
> compatible, maybe with the help of tools like "six" or "python-future",
> than to try to keep separate source trees in sync.
> 
> http://python-future.org/
> 
> Stefan

I understand. What got me going down the two-source-trees path is that
the unittest support isn't cross compatible ... the way I'm using
mocks doesn't translate between 2.7 and 3.3.

I also like having really clean 3.x code and just keeping the warts 
confined to the 2.x branch. I use the futures stuff in the 2.x branch
to keep it as close as possible to the 3.x branch, but there are still
enough differences that I have to mung the 3.x changes just a little 
when I merge them back into the 2.x branch.

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


Re: implementing pyshark

2015-04-06 Thread Steven D'Aprano
On Mon, 6 Apr 2015 10:45 pm, Michael S. wrote:

> I am using kali-linux(debian based). i have installed all from
> repository. i haven't tried yet to use the source but i don't think it
> was compiled incorrectly. Kali's developers are quite precise in terms
> of OS development.

What happens if you import threading?


If it returns without failure, then your Python interpreter is built
correctly with support for threading, and my guess was wrong.

If you get an error about no module _threading (or possibly _thread, I
forget which) then it is built without support for threading.

But, I'm now leaning towards thinking that Peter Otten's answer is more
likely. It seems to be gevent._threading that is missing. It wasn't
entirely clear from your original post, but in looking back I think Peter
is correct.

You should check whether you are accidentally shadowing gevent:

import gevent
print(gevent.__file__)


If that prints the file name of the actual gevent library, then it is
possible that you have a broken or outdated version of the library.

But if it is a file you have created, then you are shadowing the gevent
library, blocking Python from importing the library, it imports your
version instead. Rename your gevent.py file and the problem will hopefully
go away.



-- 
Steven

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


Re: Is it possible to deliver different source distributions for different Python versions?

2015-04-06 Thread Steven D'Aprano
On Tue, 7 Apr 2015 12:05 am, Ian Kelly wrote:

> On Mon, Apr 6, 2015 at 5:52 AM, Steven D'Aprano
>  wrote:
>> To the rest of the list... didn't somebody write up a wiki post on how to
>> convince Gmail to be less unreasonable about top posting, quoting, etc?
>> Does anyone still have the link?
> 
> There is https://wiki.python.org/moin/GoogleGroupsPython about posting
> from Google Groups, but I'm not aware of a similar resource for Gmail,
> which has far fewer issues. As long as you compose your email in plain
> text mode and remember to move the cursor from the top when replying,
> Gmail is fine.

Ah, that was what I was thinking of -- Google Groups, not Gmail.

It's been too long without a flame war between the haters of GG and its
impassioned defender(s), I had conflated the two Google products. Sorry for
the noise.



-- 
Steven

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


Re: Is it possible to deliver different source distributions for different Python versions?

2015-04-06 Thread Dave Hein
On Sunday, April 5, 2015 at 8:01:22 PM UTC-5, Steven D'Aprano wrote:
> On Mon, 6 Apr 2015 06:38 am, Dave Hein wrote:
> 
> > I would like to distribute a python package with different code for
> > Python 2.* than for Python 3.*. (Mostly this is because of different
> > unicode string handling).
> > 
> > There is nothing in to setuptools or PyPi that directly supports
> > this scenario.
> > 
> > But perhaps there could be some script run at install time that moves
> > the correct source code to the right location? In other works, if I
> > included both source code versions in the distribution (in a src2 and
> > a src3 subdirectory) then a function invoked at install time could
> > detect the python version and copy the appropriate source code to the
> > right location.
> > 
> > Is that at all possible? Is there some install time hook that lets me
> > supply custom installation code?
> 
> I'm not aware of any standard solution to that, but I'm not a setuptools
> expert. setup.py files are Python code, so you can put any code you like in
> them. But, as far as I am concerned, having the installer pick and choose
> what source files to include is not a good solution. Instead, you should
> pick one of these two alternatives:
> 
> 
> (1) Supply a separate package for 2.x and 3.x, each with their own
> installer. The installer confirms that it is running under the correct
> version of Python, and just installs.
> 

Yep. That's what I'm doing now. Two distinct packages on PyPi.

> 
> (2) Or supply a single package with a single installer that works under both
> 2.x and 3.x. (This is my preference.)
> 
> One way of handling the second case is to only support 3.3 or better: that
> way, you can still use u"..." for Unicode strings. Hardly anyone used 3.1
> or 3.2, and 3.0 is no longer supported, so it is quite reasonable to insist
> people upgrade to 3.3.
> 

There is other code that doesn't translate cleanly between 2.x and 3.x. 
Specifically the unittest tests and unittest.mock usage. That's mainly why
I don't have one source tree.

> Another way to handle the second case is to use conditional imports:

Hmm. Maybe I can figure out how to isolate the 2.x weirdness into a 
separate package and conditionally import the 3.x version vs. 2.x version.
I'll look into that.

Thanks.

> 
[snip]
> 
> -- 
> Steven

--
Dave Hein

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


Re: pypi submission?

2015-04-06 Thread Dave Hein
On Monday, April 6, 2015 at 5:19:29 PM UTC-5, Benjamin Schollnick wrote:
> Folks,
> 
> 
> I'm having issues with submitting to pypi.
> 
> 
> I can register and upload my package.
> 
> 
> 
> nerv:~ Benjamin$ pip search directory_caching
> Directory_Caching - A Caching library for Directories & Files
> nerv:~ Benjamin$ 
> 
> 
> but, if you try to install it using pip:
> 
> 
> 
> pip install directory_caching
> Reading Profile from ~/dropbox/shellscripts/profile
> nerv:~ Benjamin$ pip install directory_caching
> Collecting directory-caching
>   Could not find any downloads that satisfy the requirement directory-caching
>   No distributions at all found for directory-caching
> 
> 

Try adding the "--pre" option. If your version number is an 'alpha' or 'pre' or 
'rc' version (like 1.0a1 or 1.0rc4), then pip won't install it by default ... 
it will only install 'released' versions (like 1.0 or 1.0.1).

Adding the --pre option tells pip you actually do want the pre-release version. 
So:

pip install --pre directory-caching


>
[snip]

> 
>   - Benjamin

--
Dave Hein

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


Intsalling wxPython

2015-04-06 Thread Sepi
Hi,

I installed wxpython through command line but when I want to use it, python 
gives me an error:  File "/Users/sepidehghanavati/Desktop/test.py", line 1, in 

import wx
ImportError: No module named 'wx'

When I check my python path it is version 3.3 
(/Library/Frameworks/Python.framework/Versions/3.3/) but when I try to install 
wxpython via python setup.py install --user it installs in 
/Users/sepidehghanavati/Library/Python/2.7/bin/

I don't know how to change this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Intsalling wxPython

2015-04-06 Thread Sepi Gh
On Monday, 6 April 2015 22:54:26 UTC-4, Sepi  wrote:
> Hi,
> 
> I installed wxpython through command line but when I want to use it, python 
> gives me an error:  File "/Users/sepidehghanavati/Desktop/test.py", line 1, 
> in 
> import wx
> ImportError: No module named 'wx'
> 
> When I check my python path it is version 3.3 
> (/Library/Frameworks/Python.framework/Versions/3.3/) but when I try to 
> install wxpython via python setup.py install --user it installs in 
> /Users/sepidehghanavati/Library/Python/2.7/bin/
> 
> I don't know how to change this.

I got the answer! Just using python 3 instead of python in the command line
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Intsalling wxPython

2015-04-06 Thread Sepi Gh
On Monday, 6 April 2015 23:27:54 UTC-4, Sepi Gh  wrote:
> On Monday, 6 April 2015 22:54:26 UTC-4, Sepi  wrote:
> > Hi,
> > 
> > I installed wxpython through command line but when I want to use it, python 
> > gives me an error:  File "/Users//Desktop/test.py", line 1, in 
> > import wx
> > ImportError: No module named 'wx'
> > 
> > When I check my python path it is version 3.3 
> > (/Library/Frameworks/Python.framework/Versions/3.3/) but when I try to 
> > install wxpython via python setup.py install --user it installs in 
> > /UsersLibrary/Python/2.7/bin/
> > 
> > I don't know how to change this.
> 
> I got the answer! Just using python 3 instead of python in the command line

But I get this error now:  File 
"/Users//Library/Python/3.3/lib/python/site-packages/wx_py/PyWrap.py", line 27
print "Please specify a module name."
^
SyntaxError: invalid syntax
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: implementing pyshark

2015-04-06 Thread Michael S.



On 04/07/2015 03:55 AM, Steven D'Aprano wrote:

On Mon, 6 Apr 2015 10:45 pm, Michael S. wrote:


I am using kali-linux(debian based). i have installed all from
repository. i haven't tried yet to use the source but i don't think it
was compiled incorrectly. Kali's developers are quite precise in terms
of OS development.

What happens if you import threading?


If it returns without failure, then your Python interpreter is built
correctly with support for threading, and my guess was wrong.

If you get an error about no module _threading (or possibly _thread, I
forget which) then it is built without support for threading.

But, I'm now leaning towards thinking that Peter Otten's answer is more
likely. It seems to be gevent._threading that is missing. It wasn't
entirely clear from your original post, but in looking back I think Peter
is correct.

You should check whether you are accidentally shadowing gevent:

import gevent
print(gevent.__file__)


If that prints the file name of the actual gevent library, then it is
possible that you have a broken or outdated version of the library.

But if it is a file you have created, then you are shadowing the gevent
library, blocking Python from importing the library, it imports your
version instead. Rename your gevent.py file and the problem will hopefully
go away.




 Hi ,
i tried your suggestion: it did print the lib directory. - i tried 
removing the gevent deb-package and then installing  from src but got 
the same error.

I'll download other OS and will test it there.
--
https://mail.python.org/mailman/listinfo/python-list


Intstalling wxPything

2015-04-06 Thread Sepi
Hi, 

I installed wxpython through command line but when I want to use it, python 
gives me an error:  File "/Users//Desktop/test.py", line 1, in  
 import wx 
 ImportError: No module named 'wx' 

When I check my python path it is version 3.3 
(/Library/Frameworks/Python.framework/Versions/3.3/) but when I try to install 
wxpython via python setup.py install --user it installs in 
/UsersLibrary/Python/2.7/bin/ 

 I don't know how to change this. 
 
 I got the answer! Just using python 3 instead of python in the command line 

But I get this error now:  File 
"/Users//Library/Python/3.3/lib/python/site-packages/wx_py/PyWrap.py", line 27 
print "Please specify a module name." 
^ 
SyntaxError: invalid syntax 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with pipes, buffering and pseudoterminals

2015-04-06 Thread Daniel Ellis
Wow, thank you for the long and detailed reply.

As for the question ptys and C, no, I have no experience in that area.
I've read a bit on the master/slave stuff, but I'm still finding it
confusing.  The manpage for pty states that it creates a "pair" of virtual
devices, one master and one slave.  It doesn't seem like these are simple
file descriptors for stdin, stdout, and stderr, given that there is only
one for the master and one for the slave, so I'm really not understanding
what it means for these devices to be created.

One way to do that is for "your-program" to open a pty and itself invoke
> "command-generating-output" with its output via the pty, which is why so
> many tutorials suppose a "fork" situation.


Yeah, I'm beginning to realize that.  It's a shame, but I case the use-case
in the end isn't that big of a deal.

Thanks again for the explanation.  I think I'm understanding a bit better
now, or at least understanding why my current means of tackling the problem
won't work.  I'd still very much like to figure out the reading/writing to
the master & slave stuff though.



On Sun, Apr 5, 2015 at 5:11 PM, Cameron Simpson  wrote:

> On 05Apr2015 12:20, Daniel Ellis  wrote:
>
>> I have a small little tool I'd like to make.  It essentially takes piped
>> input, modifies the text in some way, and immediately prints the output.
>> The problem I'm having is that any output I pipe to the program seems to be
>> buffered, removing the desired effect.
>>
>
> That depends on the upstream program; it does the buffering. The pipe
> itself presents received data downstream immediately.
>
> However, as you've seen, almost every program buffers its standard output
> if the output is not a tty; this is automatic in the stdio C library and
> results in more fficient use of I/O.
>
>  From what I understand, I need to somehow have the input be retrieved via
>> a pseudoterminal.
>>
>
> This is a rather gross hack, though sometimes all you can do. While some
> programs have an option to force unbuffered output, most do not. Attaching
> their output to a pty is one way to encourage them to at least line buffer
> their output.
>
> However, you should bear in mind that the reason that programs line buffer
> to a terminal is that they presume they are in an interactive situation
> with a person watching. The program _may_ act differently in other ways as
> well, such as asking question it might not otherwise ask in "batch" mode
> (where it might cautiously not ask and presume "no").
>
> Also, output sent through a pty is subject to the line discipline in the
> terminal; temrinals are funny things with much historical behaviour. At the
> least you pobably want your pty in "raw" mode to avoid all sorts of stuff
> that can be done to your data.
>
>  The problem that I'm having is that most examples on the internet seem to
>> assume I would like to launch a program in a forked pty process, which
>> doesn't really fit my use case.
>>
>
> Indeed not, but not to worry. You don't need to fork.
>
>  I've tried a number of things, but I seem to be unable to get even a
>> basic understanding of how to use the pty module.
>>
>
> Have you every used a pty from C? Do you know how ptys work? (master side,
> slave side, etc).
>
>  Here's a piece of code I whipped up just to try to get a feel for what is
>> going on when I use pty.fork, but it doesn't seem to do what I think it
>> should:
>>
>>import pty
>>import os
>>import sys
>>
>>pid, fd = pty.fork()
>>print pid, fd
>>sys.stdout.flush()
>>os.read(fd, 1024)
>>
>> This only seems to print from the parent process.
>>
>
> The documentation for pty.fork says:
>
>  Return value is (pid, fd). Note that the child gets pid 0, and the fd is
> invalid.
>
> So the child cannot used "fd". It further says that the child has its
> stdin and stdout attached to the pty, and that the pty is the child's
> controlling terminal (this means it is affected by things like "typing" ^C
> at the pty, etc).
>
>  I read that I need to do the os.read call for the fork to happen.  I've
>> also
>>
> tried printing *after* the os.read call.
>
> Don't try to adapt fork-based tutorials to your needs. Understand ptys
> directly first.
>
>  I realize this does very little to solve my overall goal, but I figure
>> understanding what is going on is probably a worthwhile first step.
>>
>
> What you probably want to use is pty.openpty() instead. No fork. You will
> get back file descriptors for the master and slave sides of the pty. Then
> you can use these with the subprocess module to connect your input program.
> Or, guessing from your opening sentence, you can write a wrapper script
> whose whole purpose is to run a program on a pty.
>
> Regarding terminology: a pseudoterminal (pty) is a device that looks like
> a traditional serial terminal. All terminal emulators like xterm use one,
> and so do other programs presenting a terminal session such as the sshd
> process handling an interactive r

Re: Intsalling wxPython

2015-04-06 Thread Michael Torrie
On 04/06/2015 09:29 PM, Sepi Gh wrote:
>> I got the answer! Just using python 3 instead of python in the command line
> 
> But I get this error now:  File 
> "/Users//Library/Python/3.3/lib/python/site-packages/wx_py/PyWrap.py", line 27
> print "Please specify a module name."
> ^
> SyntaxError: invalid syntax

wxWidgets does not yet support Python 3, though you can find beta builds
of it:

http://wiki.wxpython.org/ProjectPhoenix


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


Re: Intsalling wxPython

2015-04-06 Thread Ian Kelly
On Apr 6, 2015 9:31 PM, "Sepi Gh"  wrote:
>
> On Monday, 6 April 2015 23:27:54 UTC-4, Sepi Gh  wrote:
> > On Monday, 6 April 2015 22:54:26 UTC-4, Sepi  wrote:
> > > Hi,
> > >
> > > I installed wxpython through command line but when I want to use it,
python gives me an error:  File "/Users//Desktop/test.py", line 1, in

> > > import wx
> > > ImportError: No module named 'wx'
> > >
> > > When I check my python path it is version 3.3
(/Library/Frameworks/Python.framework/Versions/3.3/) but when I try to
install wxpython via python setup.py install --user it installs in
/UsersLibrary/Python/2.7/bin/
> > >
> > > I don't know how to change this.
> >
> > I got the answer! Just using python 3 instead of python in the command
line
>
> But I get this error now:  File
"/Users//Library/Python/3.3/lib/python/site-packages/wx_py/PyWrap.py", line
27
> print "Please specify a module name."
> ^
> SyntaxError: invalid syntax

wxPython classic doesn't support Python 3. You can try using wxPython
Phoenix which is a complete rewrite that does support Python 3. It doesn't
have a stable release yet, although I hear it's getting close.
-- 
https://mail.python.org/mailman/listinfo/python-list


webware for python 3

2015-04-06 Thread rahulmr


I have an old project which uses web ware, where i want to convert to latest 
version 3.4

I am wondering whether any webware is available for python version 3.4. What I 
am seeing is the webware version 1.1.1 which is old and seems like it is not 
supporting the version 3.4 as I could see the print is written print abc and no 
braces.

So how should i approach converting this project which is based on python 2.2.1 
?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: webware for python 3

2015-04-06 Thread prennix
https://docs.python.org/2/library/2to3.html 


> So how should i approach converting this project which is based on python 
> 2.2.1 ?

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


Re: webware for python 3

2015-04-06 Thread Novocastrian_Nomad
On Monday, April 6, 2015 at 11:26:15 PM UTC-6, rah...@gmail.com wrote:
> I have an old project which uses web ware, where i want to convert to latest 
> version 3.4
> 
> I am wondering whether any webware is available for python version 3.4. What 
> I am seeing is the webware version 1.1.1 which is old and seems like it is 
> not supporting the version 3.4 as I could see the print is written print abc 
> and no braces.
> 
> So how should i approach converting this project which is based on python 
> 2.2.1 ?

Some or all of what you need may already be done.  See 
http://pythonpaste.org/wareweb/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with pipes, buffering and pseudoterminals

2015-04-06 Thread Cameron Simpson

On 06Apr2015 21:13, Daniel Ellis  wrote:

Wow, thank you for the long and detailed reply.

As for the question ptys and C, no, I have no experience in that area.


No worries. The use is the same in Python.

BTW, you may want a fixed width font; there are some ASCII diagrams in this 
message.



I've read a bit on the master/slave stuff, but I'm still finding it
confusing.  The manpage for pty states that it creates a "pair" of virtual
devices, one master and one slave.  It doesn't seem like these are simple
file descriptors for stdin, stdout, and stderr, given that there is only
one for the master and one for the slave, so I'm really not understanding
what it means for these devices to be created.


The following explaination is long; I do get to master/slave at the bottom. But 
I'm covering stdin/stdout/stderr too.


Think about a serial terminal. On one end there is a computer, with wires to 
the terminal. Since the computer runs UNIX, access to the terminal is done with 
read and write calls. A read returns characters typed at the terminal by a 
person and a write sends characters to the terminal which are displayed to the 
person.


<--eyes-
 person terminal <==cable==> computer
--fingers-->

If someone is logged in on a physical terminal, on the computer's end there 
will be a program acting on what they type. The UNIX command prompt, the shell, 
is what one would normally get after logging in; for moderns users this is 
often bash.


Terminology Digression:

 When you open() a file (or device) in UNIX you get a file descriptor handed 
 to you; this is a single integer which is essentially an index into the 
 process' array of open files. Index 0 is stdin, 1 stdout, 2 stderr, and other 
 open files get further indices.


 It is important to realise an open() creates, internally, a "file handle", 
 the data structure that tracks use of the file from that specific open() 
 call. It has information like the I/O mode (read/write/append) and the file 
 position (where data lands when you write or where data comes from when you 
 read).


 The file descriptor, the index, points into an array of _references_ to file 
 handles. You can dup() a file descriptor to get another file descriptor i.e.  
 another index; it will refer to the _same_ file handle internally.


 process: fd 0 -> tty handle -> tty device
  fd 1 ---^ ^
  fd 2 -+

Returning...

The operating system arranges the commection of the shell to the terminal. Your 
usual program has by default a stdin, stdout and stderr. These are _all_ the 
same file handle, duplicated to each of the three file descriptors 0, 1 and 2 
respectively. On the operating system side, the OS has performed _one_ open() 
call on the terminal device and handed the caller a single file descriptor. The 
caller then calls dup() (or modernly, dup2()) to present the open terminal as 
stdin, stdout and stderr.


That file handle is open for read and write, as you might imagine.

If you want to see this, type:

 lsof -p $$

at your shell prompt. Observe fd 0, 1, 2.

Why the duplication? This lets you do redirection! You can attach something 
else to a program's stdout, for example:


 ls > files.txt

without disturbing stdin or stderr. And so forth.

A pty behaves the same way, except that there is no physical device involved.  
There is just an abstraction which behaves like a physical device:


   You see, wire telegraph is a kind of a very, very long cat. You
   pull his tail in New York and his head is meowing in Los Angeles.
   Do you understand this?  And radio operates exactly the same way:
   you send signals here, they receive them there. The only difference
   is that there is no cat.
   - Albert Einstein, when asked to describe radio

The main reason for ptys is that there is a class of programs which present a 
terminal interface to users (xterm, sshd, telnetd, etc).


So, something like xterm _draws_ a GUI representation of a terminal for you to 
look at, and collects keystrokes (as GUI events), converts them into bytes and 
writes them to the pty. For example, it might see "Shift-A-Down" and send code 
65 (capital "A"). Similarly it reads from the pty and draws on the screen.


The shell you use in an xterm is on the other side of the pty. The code 65 the 
xterm sent above is seen read as code 65 by the shell and treated as a typed 
"A".


In this scenario, effectively the xterm is a server to the shell: it is 
responsible for accepting things from the shell and displaying them, and 
providing typed GUI events to the shell as input bytes. It also sets the 
initial terminal modes and attaches the shell to the pty.


Correspondingly, when xterm opened a pty for its work the two file descriptors 
it gets are "master" and "slave" file descriptors.


The master is kept by xterm and used to read shell output and write to the 
shell's input.


The slave is used to set up the shell. The basic scheme is that the xterm 
fork