[IronPython] Access to Enumeration Values

Anthony Tarlano tarlano at gmail.com
Thu Aug 4 22:22:53 CEST 2005


Martin,

I still think it can be made better. For example, if in c# I could say:

i = (int) SocketOptionName.Broadcast;

I can get the correct value, but in IronPython I can't say:

int(SocketOptionName.Broadcast)

since I will not get the correct value back. 

I do see your point, but I think that for enumerations they should
either support conversion using standards functions such as int(), or
hex(), and not make programmers have to append the ".value__" just to
get the value, which in my humble opinion is unpythonic and just so
far off c# that some thought should be given to fix it.

Anthony


On 8/4/05, Martin Maly <martmaly at exchange.microsoft.com> wrote:
> Hi Anthony,
> 
> I don't think it is a bug. The value you get when getting an enum value
> (SocketOptionName.Broadcast) is indeed the value itself:
> 
> x = SocketOptions.Broadcast
> 
> x becomes a boxed enum object. It is the ToString() method of the enum
> object prints the name. Consider following C# code that does exactly the
> same:
> 
> using System.Net.Sockets;
> namespace Test {
>     public class Program {
>         static void Main(string[] args) {
>             Console.WriteLine(SocketOptionName.Broadcast);
>         }
>     }
> }
> 
> Does that answer the question?
> 
> Martin
> 
> -----Original Message-----
> From: users-ironpython.com-bounces at lists.ironpython.com
> [mailto:users-ironpython.com-bounces at lists.ironpython.com] On Behalf Of
> Anthony Tarlano
> Sent: Thursday, August 04, 2005 9:12 AM
> To: Discussion of IronPython
> Subject: [IronPython] Access to Enumeration Values
> 
> the namespace System.Net.Sockets contains an enumation type named
> SocketOptionName for retrieving Socket options. It's definition is:
> 
> public enum SocketOptionName
> {
>       // Fields
>       AcceptConnection = 2,
>       AddMembership = 12,
>       AddSourceMembership = 15,
>       BlockSource = 0x11,
>       Broadcast = 0x20,
>       BsdUrgent = 2,
>       ChecksumCoverage = 20,
>       Debug = 1,
>       DontFragment = 14,
>       DontLinger = -129,
>       DontRoute = 0x10,
>       DropMembership = 13,
>       DropSourceMembership = 0x10,
>       Error = 0x1007,
>       ExclusiveAddressUse = -5,
>       Expedited = 2,
>       HeaderIncluded = 2,
>       HopLimit = 0x15,
>       IPOptions = 1,
>       IpTimeToLive = 4,
>       IPv6ProtectionLevel = 0x17,
>       KeepAlive = 8,
>       Linger = 0x80,
>       MaxConnections = 0x7fffffff,
>       MulticastInterface = 9,
>       MulticastLoopback = 11,
>       MulticastTimeToLive = 10,
>       NoChecksum = 1,
>       NoDelay = 1,
>       OutOfBandInline = 0x100,
>       PacketInformation = 0x13,
>       ReceiveBuffer = 0x1002,
>       ReceiveLowWater = 0x1004,
>       ReceiveTimeout = 0x1006,
>       ReuseAddress = 4,
>       SendBuffer = 0x1001,
>       SendLowWater = 0x1003,
>       SendTimeout = 0x1005,
>       Type = 0x1008,
>       TypeOfService = 3,
>       UnblockSource = 0x12,
>       UpdateAcceptContext = 0x700b,
>       UpdateConnectContext = 0x7010,
>       UseLoopback = 0x40
> }
> 
> Upon accessing an enumeration value by name IronPython only returns its
> name as a string... If this isn't a bug then it should be... see this
> output
> 
> IronPython 0.9.2036 on .NET 2.0.50215.44 Copyright (c) Microsoft
> Corporation. All rights reserved.
> >>> from System.Net.Sockets import SocketOptionName SocketOptionName
> <type 'System.Net.Sockets.SocketOptionName'>
> >>> SocketOptionName.MaxConnections
> MaxConnections
> >>> SocketOptionName.MaxConnections.value__
> 2147483647
> >>>
> 
> Anthony
>



More information about the Ironpython-users mailing list