how to edit .wsgi file extebtions with IDLE on windows

Discussion in 'Python' started by gert, Aug 28, 2009.

  1. gert

    gert Guest

    I can't figure out how to enable the .py shell and syntax highlighting
    for .wsgi file extensions using IDLE for windows ?
    gert, Aug 28, 2009
    #1
    1. Advertising

  2. En Fri, 28 Aug 2009 15:31:31 -0300, gert <> escribió:

    > I can't figure out how to enable the .py shell and syntax highlighting
    > for .wsgi file extensions using IDLE for windows ?


    That's a Windows question, not a Python one. You have to associate the
    ..wsgi extension with the Python.File file type (the one used for .py
    files):

    D:\USERDATA\Gabriel>assoc .py
    ..py=Python.File

    D:\USERDATA\Gabriel>assoc .wsgi=Python.File
    ..wsgi=Python.File

    --
    Gabriel Genellina
    Gabriel Genellina, Aug 29, 2009
    #2
    1. Advertising

  3. gert

    gert Guest

    On Aug 29, 6:43 am, "Gabriel Genellina" <>
    wrote:
    > En Fri, 28 Aug 2009 15:31:31 -0300, gert <> escribió:
    >
    > > I can't figure out how to enable the .py shell and syntax highlighting
    > > for .wsgi file extensions using IDLE for windows ?

    >
    > That's a Windows question, not a Python one. You have to associate the  
    > .wsgi extension with the Python.File file type (the one used for .py  
    > files):
    >
    > D:\USERDATA\Gabriel>assoc .py
    > .py=Python.File
    >
    > D:\USERDATA\Gabriel>assoc .wsgi=Python.File
    > .wsgi=Python.File
    >


    Thanks that does make it open exactly like a .py file, expect that
    there is no syntax highlighting. Don't know if this is also a windows
    issue or a IDLE issue ?
    gert, Aug 29, 2009
    #3
  4. gert

    Chris Rebert Guest

    On Sat, Aug 29, 2009 at 5:40 AM, gert<> wrote:
    > On Aug 29, 6:43 am, "Gabriel Genellina" <>
    > wrote:
    >> En Fri, 28 Aug 2009 15:31:31 -0300, gert <> escribió:
    >>
    >> > I can't figure out how to enable the .py shell and syntax highlighting
    >> > for .wsgi file extensions using IDLE for windows ?

    >>
    >> That's a Windows question, not a Python one. You have to associate the
    >> .wsgi extension with the Python.File file type (the one used for .py
    >> files):
    >>
    >> D:\USERDATA\Gabriel>assoc .py
    >> .py=Python.File
    >>
    >> D:\USERDATA\Gabriel>assoc .wsgi=Python.File
    >> .wsgi=Python.File
    >>

    >
    > Thanks that does make it open exactly like a .py file, expect that
    > there is no syntax highlighting. Don't know if this is also a windows
    > issue or a IDLE issue ?


    That's an IDLE issue; it only highlights files with .py (and possibly
    ..pyw) extensions.

    Cheers,
    Chris
    --
    http://blog.rebertia.com
    Chris Rebert, Aug 29, 2009
    #4
  5. gert

    gert Guest

    On Aug 29, 9:31 pm, Chris Rebert <> wrote:
    > On Sat, Aug 29, 2009 at 5:40 AM, gert<> wrote:
    > > On Aug 29, 6:43 am, "Gabriel Genellina" <>
    > > wrote:
    > >> En Fri, 28 Aug 2009 15:31:31 -0300, gert <> escribió:

    >
    > >> > I can't figure out how to enable the .py shell and syntax highlighting
    > >> > for .wsgi file extensions using IDLE for windows ?

    >
    > >> That's a Windows question, not a Python one. You have to associate the
    > >> .wsgi extension with the Python.File file type (the one used for .py
    > >> files):

    >
    > >> D:\USERDATA\Gabriel>assoc .py
    > >> .py=Python.File

    >
    > >> D:\USERDATA\Gabriel>assoc .wsgi=Python.File
    > >> .wsgi=Python.File

    >
    > > Thanks that does make it open exactly like a .py file, expect that
    > > there is no syntax highlighting. Don't know if this is also a windows
    > > issue or a IDLE issue ?

    >
    > That's an IDLE issue; it only highlights files with .py (and possibly
    > .pyw) extensions.
    >


    Any chance they would make a highlight option in the menu ?
    gert, Aug 29, 2009
    #5
  6. En Sat, 29 Aug 2009 17:14:14 -0300, gert <> escribió:
    > On Aug 29, 9:31 pm, Chris Rebert <> wrote:
    >> On Sat, Aug 29, 2009 at 5:40 AM, gert<> wrote:
    >> > On Aug 29, 6:43 am, "Gabriel Genellina" <>
    >> > wrote:
    >> >> En Fri, 28 Aug 2009 15:31:31 -0300, gert <>

    >> escribió:
    >>
    >> >> > I can't figure out how to enable the .py shell and syntax

    >> highlighting
    >> >> > for .wsgi file extensions using IDLE for windows ?

    >>
    >> >> That's a Windows question, not a Python one. You have to associate

    >> the
    >> >> .wsgi extension with the Python.File file type (the one used for .py
    >> >> files):

    >>
    >> >> D:\USERDATA\Gabriel>assoc .py
    >> >> .py=Python.File

    >>
    >> >> D:\USERDATA\Gabriel>assoc .wsgi=Python.File
    >> >> .wsgi=Python.File

    >>
    >> > Thanks that does make it open exactly like a .py file, expect that
    >> > there is no syntax highlighting. Don't know if this is also a windows
    >> > issue or a IDLE issue ?

    >>
    >> That's an IDLE issue; it only highlights files with .py (and possibly
    >> .pyw) extensions.
    >>

    >
    > Any chance they would make a highlight option in the menu ?


    Two alternatives:

    a) Ensure your scripts contain a shebang - no purpose on Windows, but IDLE
    recognizes the file as a Python file. That is, make sure the very first
    line is like this:

    #!c:\python26\python.exe

    (it must start with #! and contain the word "python" somewhere)

    b) Edit IDLE sources:

    - Locate the file EditorWindow.py in the idlelib package.

    - Add this line near the top:
    import _winreg

    - Modify function ispythonsource near line 580 as follows:

    def ispythonsource(self, filename):
    if not filename or os.path.isdir(filename):
    return True
    base, ext = os.path.splitext(os.path.basename(filename))
    if os.path.normcase(ext) in (".py", ".pyw"):
    return True
    ### add these 4 lines ###
    with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, ext) as key:
    ftype = _winreg.QueryValueEx(key, None)[0]
    if ftype.lower() in ("python.file","python.noconfile"):
    return True
    ### end ###
    try:
    f = open(filename)
    line = f.readline()
    f.close()
    except IOError:
    return False
    return line.startswith('#!') and line.find('python') >= 0



    --
    Gabriel Genellina
    Gabriel Genellina, Aug 29, 2009
    #6
  7. gert

    gert Guest

    On Aug 29, 11:16 pm, "Gabriel Genellina" <>
    wrote:
    > En Sat, 29 Aug 2009 17:14:14 -0300, gert <> escribió:
    >
    > > On Aug 29, 9:31 pm, Chris Rebert <> wrote:
    > >> On Sat, Aug 29, 2009 at 5:40 AM, gert<> wrote:
    > >> > On Aug 29, 6:43 am, "Gabriel Genellina" <>
    > >> > wrote:
    > >> >> En Fri, 28 Aug 2009 15:31:31 -0300, gert <>  
    > >> escribió:

    >
    > >> >> > I can't figure out how to enable the .py shell and syntax  
    > >> highlighting
    > >> >> > for .wsgi file extensions using IDLE for windows ?

    >
    > >> >> That's a Windows question, not a Python one. You have to associate  
    > >> the
    > >> >> .wsgi extension with the Python.File file type (the one used for .py
    > >> >> files):

    >
    > >> >> D:\USERDATA\Gabriel>assoc .py
    > >> >> .py=Python.File

    >
    > >> >> D:\USERDATA\Gabriel>assoc .wsgi=Python.File
    > >> >> .wsgi=Python.File

    >
    > >> > Thanks that does make it open exactly like a .py file, expect that
    > >> > there is no syntax highlighting. Don't know if this is also a windows
    > >> > issue or a IDLE issue ?

    >
    > >> That's an IDLE issue; it only highlights files with .py (and possibly
    > >> .pyw) extensions.

    >
    > > Any chance they would make a highlight option in the menu ?

    >
    > Two alternatives:
    >
    > a) Ensure your scripts contain a shebang - no purpose on Windows, but IDLE  
    > recognizes the file as a Python file. That is, make sure the very first  
    > line is like this:
    >
    > #!c:\python26\python.exe
    >
    > (it must start with #! and contain the word "python" somewhere)
    >
    > b) Edit IDLE sources:
    >
    > - Locate the file EditorWindow.py in the idlelib package.
    >
    > - Add this line near the top:
    >    import _winreg
    >
    > - Modify function ispythonsource near line 580 as follows:
    >
    >      def ispythonsource(self, filename):
    >          if not filename or os.path.isdir(filename):
    >              return True
    >          base, ext = os.path.splitext(os.path.basename(filename))
    >          if os.path.normcase(ext) in (".py", ".pyw"):
    >              return True
    >          ### add these 4 lines ###
    >          with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, ext) as key:
    >              ftype = _winreg.QueryValueEx(key, None)[0]
    >              if ftype.lower() in ("python.file","python.noconfile"):
    >                  return True
    >          ### end ###
    >          try:
    >              f = open(filename)
    >              line = f.readline()
    >              f.close()
    >          except IOError:
    >              return False
    >          return line.startswith('#!') and line.find('python') >= 0
    >


    Thanks. Can you make a ispythonsource menu option in the next
    python3.x release? There are many examples of txt, xml or wsgi files
    having python parts in them.
    gert, Aug 30, 2009
    #7
  8. En Sat, 29 Aug 2009 20:29:43 -0300, gert <> escribió:
    > On Aug 29, 11:16 pm, "Gabriel Genellina" <>
    > wrote:
    >> En Sat, 29 Aug 2009 17:14:14 -0300, gert <>
    >> escribió:
    >> > On Aug 29, 9:31 pm, Chris Rebert <> wrote:
    >> >> On Sat, Aug 29, 2009 at 5:40 AM, gert<> wrote:
    >> >> > On Aug 29, 6:43 am, "Gabriel Genellina" <>
    >> >> > wrote:
    >> >> >> En Fri, 28 Aug 2009 15:31:31 -0300, gert <>
    >> >> escribió:


    >> >> >> > I can't figure out how to enable the .py shell and syntax  
    >> >> >> > highlighting
    >> >> >> > for .wsgi file extensions using IDLE for windows ?


    > Thanks. Can you make a ispythonsource menu option in the next
    > python3.x release? There are many examples of txt, xml or wsgi files
    > having python parts in them.


    Please file a feature request at http://bugs.python.org/
    I think a "This is a python file, apply syntax highlighting" menu option
    is feasible, but doing the same only for part of a file is a lot harder.

    --
    Gabriel Genellina
    Gabriel Genellina, Sep 4, 2009
    #8
  9. gert

    gert Guest

    On Sep 4, 6:07 am, "Gabriel Genellina" <> wrote:
    > En Sat, 29 Aug 2009 20:29:43 -0300, gert <> escribió:
    >
    >
    >
    > > On Aug 29, 11:16 pm, "Gabriel Genellina" <>
    > > wrote:
    > >> En Sat, 29 Aug 2009 17:14:14 -0300, gert <>  
    > >> escribió:
    > >> > On Aug 29, 9:31 pm, Chris Rebert <> wrote:
    > >> >> On Sat, Aug 29, 2009 at 5:40 AM, gert<> wrote:
    > >> >> > On Aug 29, 6:43 am, "Gabriel Genellina" <>
    > >> >> > wrote:
    > >> >> >> En Fri, 28 Aug 2009 15:31:31 -0300, gert <>  
    > >> >> escribió:
    > >> >> >> > I can't figure out how to enable the .py shell and syntax  
    > >> >> >> > highlighting
    > >> >> >> > for .wsgi file extensions using IDLE for windows ?

    > > Thanks. Can you make a ispythonsource menu option in the next
    > > python3.x release? There are many examples of txt, xml or wsgi files
    > > having python parts in them.

    >
    > Please file a feature request athttp://bugs.python.org/
    > I think a "This is a python file, apply syntax highlighting" menu option
    > is feasible, but doing the same only for part of a file is a lot harder.
    >


    http://bugs.python.org/issue6858

    does not matter its trival to see which part is python
    gert, Sep 8, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bartolomé Sintes Marco

    Windows Python 2.3b2 bug? Edit with IDLE

    Bartolomé Sintes Marco, Jul 10, 2003, in forum: Python
    Replies:
    0
    Views:
    307
    Bartolomé Sintes Marco
    Jul 10, 2003
  2. Lith
    Replies:
    0
    Views:
    314
  3. Replies:
    2
    Views:
    335
  4. Rami Chowdhury

    Re: wsgi with separate css file

    Rami Chowdhury, Nov 13, 2009, in forum: Python
    Replies:
    1
    Views:
    373
    Aaron Watters
    Nov 13, 2009
  5. Hans
    Replies:
    0
    Views:
    120
Loading...

Share This Page