MobileBlur

web2py.gluon.validators.IS_IPV4-class.html at [50a1ba732d]
Login

web2py.gluon.validators.IS_IPV4-class.html at [50a1ba732d]

File applications/examples/static/epydoc/web2py.gluon.validators.IS_IPV4-class.html artifact cbb515ef29 part of check-in 50a1ba732d


<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>web2py.gluon.validators.IS_IPV4</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="web2py.gluon-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://www.web2py.com">web2py Web Framework</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        Package&nbsp;web2py ::
        <a href="web2py.gluon-module.html">Package&nbsp;gluon</a> ::
        <a href="web2py.gluon.validators-module.html">Module&nbsp;validators</a> ::
        Class&nbsp;IS_IPV4
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="web2py.gluon.validators.IS_IPV4-class.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== CLASS DESCRIPTION ==================== -->
<h1 class="epydoc">Class IS_IPV4</h1><span class="codelink"><a href="web2py.gluon.validators-pysrc.html#IS_IPV4">source&nbsp;code</a></span><br /><br />
<pre class="base-tree">
object --+    
         |    
 <a href="web2py.gluon.validators.Validator-class.html">Validator</a> --+
             |
            <strong class="uidshort">IS_IPV4</strong>
</pre>

<hr />
<pre class="literalblock">

Checks if field's value is an IP version 4 address in decimal form. Can
be set to force addresses from certain range.

IPv4 regex taken from: http://regexlib.com/REDetails.aspx?regexp_id=1411

Arguments:

minip: lowest allowed address; accepts:
       str, eg. 192.168.0.1
       list or tuple of octets, eg. [192, 168, 0, 1]
maxip: highest allowed address; same as above
invert: True to allow addresses only from outside of given range; note
        that range boundaries are not matched this way
is_localhost: localhost address treatment:
              None (default): indifferent
              True (enforce): query address must match localhost address
                              (127.0.0.1)
              False (forbid): query address must not match localhost
                              address
is_private: same as above, except that query address is checked against
            two address ranges: 172.16.0.0 - 172.31.255.255 and
            192.168.0.0 - 192.168.255.255
is_automatic: same as above, except that query address is checked against
              one address range: 169.254.0.0 - 169.254.255.255

Minip and maxip may also be lists or tuples of addresses in all above
forms (str, int, list / tuple), allowing setup of multiple address ranges:

    minip = (minip1, minip2, ... minipN)
               |       |           |
               |       |           |
    maxip = (maxip1, maxip2, ... maxipN)

Longer iterable will be truncated to match length of shorter one.

Examples::

    #Check for valid IPv4 address:
    INPUT(_type='text', _name='name', requires=IS_IPV4())

    #Check for valid IPv4 address belonging to specific range:
    INPUT(_type='text', _name='name',
        requires=IS_IPV4(minip='100.200.0.0', maxip='100.200.255.255'))

    #Check for valid IPv4 address belonging to either 100.110.0.0 -
    #100.110.255.255 or 200.50.0.0 - 200.50.0.255 address range:
    INPUT(_type='text', _name='name',
        requires=IS_IPV4(minip=('100.110.0.0', '200.50.0.0'),
                         maxip=('100.110.255.255', '200.50.0.255')))

    #Check for valid IPv4 address belonging to private address space:
    INPUT(_type='text', _name='name', requires=IS_IPV4(is_private=True))

    #Check for valid IPv4 address that is not a localhost address:
    INPUT(_type='text', _name='name', requires=IS_IPV4(is_localhost=False))

&gt;&gt;&gt; IS_IPV4()('1.2.3.4')
('1.2.3.4', None)
&gt;&gt;&gt; IS_IPV4()('255.255.255.255')
('255.255.255.255', None)
&gt;&gt;&gt; IS_IPV4()('1.2.3.4 ')
('1.2.3.4 ', 'enter valid IPv4 address')
&gt;&gt;&gt; IS_IPV4()('1.2.3.4.5')
('1.2.3.4.5', 'enter valid IPv4 address')
&gt;&gt;&gt; IS_IPV4()('123.123')
('123.123', 'enter valid IPv4 address')
&gt;&gt;&gt; IS_IPV4()('1111.2.3.4')
('1111.2.3.4', 'enter valid IPv4 address')
&gt;&gt;&gt; IS_IPV4()('0111.2.3.4')
('0111.2.3.4', 'enter valid IPv4 address')
&gt;&gt;&gt; IS_IPV4()('256.2.3.4')
('256.2.3.4', 'enter valid IPv4 address')
&gt;&gt;&gt; IS_IPV4()('300.2.3.4')
('300.2.3.4', 'enter valid IPv4 address')
&gt;&gt;&gt; IS_IPV4(minip='1.2.3.4', maxip='1.2.3.4')('1.2.3.4')
('1.2.3.4', None)
&gt;&gt;&gt; IS_IPV4(minip='1.2.3.5', maxip='1.2.3.9', error_message='bad ip')('1.2.3.4')
('1.2.3.4', 'bad ip')
&gt;&gt;&gt; IS_IPV4(maxip='1.2.3.4', invert=True)('127.0.0.1')
('127.0.0.1', None)
&gt;&gt;&gt; IS_IPV4(maxip='1.2.3.4', invert=True)('1.2.3.4')
('1.2.3.4', 'enter valid IPv4 address')
&gt;&gt;&gt; IS_IPV4(is_localhost=True)('127.0.0.1')
('127.0.0.1', None)
&gt;&gt;&gt; IS_IPV4(is_localhost=True)('1.2.3.4')
('1.2.3.4', 'enter valid IPv4 address')
&gt;&gt;&gt; IS_IPV4(is_localhost=False)('127.0.0.1')
('127.0.0.1', 'enter valid IPv4 address')
&gt;&gt;&gt; IS_IPV4(maxip='100.0.0.0', is_localhost=True)('127.0.0.1')
('127.0.0.1', 'enter valid IPv4 address')

</pre><br /><br />

<!-- ==================== INSTANCE METHODS ==================== -->
<a name="section-InstanceMethods"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Instance Methods</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-InstanceMethods"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="web2py.gluon.validators.IS_IPV4-class.html#__init__" class="summary-sig-name">__init__</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">minip</span>=<span class="summary-sig-default"><code class="variable-quote">'</code><code class="variable-string">0.0.0.0</code><code class="variable-quote">'</code></span>,
        <span class="summary-sig-arg">maxip</span>=<span class="summary-sig-default"><code class="variable-quote">'</code><code class="variable-string">255.255.255.255</code><code class="variable-quote">'</code></span>,
        <span class="summary-sig-arg">invert</span>=<span class="summary-sig-default">True</span>,
        <span class="summary-sig-arg">is_localhost</span>=<span class="summary-sig-default">1</span>,
        <span class="summary-sig-arg">is_private</span>=<span class="summary-sig-default">1</span>,
        <span class="summary-sig-arg">is_automatic</span>=<span class="summary-sig-default">1</span>,
        <span class="summary-sig-arg">error_message</span>=<span class="summary-sig-default"><code class="variable-quote">'</code><code class="variable-string">enter valid IPv4 address</code><code class="variable-quote">'</code></span>)</span><br />
      x.__init__(...) initializes x; see x.__class__.__doc__ for 
      signature</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="web2py.gluon.validators-pysrc.html#IS_IPV4.__init__">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="__call__"></a><span class="summary-sig-name">__call__</span>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">value</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="web2py.gluon.validators-pysrc.html#IS_IPV4.__call__">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code><a href="web2py.gluon.validators.Validator-class.html">Validator</a></code></b>:
      <code><a href="web2py.gluon.validators.Validator-class.html#formatter">formatter</a></code>
      </p>
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__delattr__</code>,
      <code>__getattribute__</code>,
      <code>__hash__</code>,
      <code>__new__</code>,
      <code>__reduce__</code>,
      <code>__reduce_ex__</code>,
      <code>__repr__</code>,
      <code>__setattr__</code>,
      <code>__str__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== CLASS VARIABLES ==================== -->
<a name="section-ClassVariables"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Class Variables</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-ClassVariables"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="web2py.gluon.validators.IS_IPV4-class.html#regex" class="summary-name">regex</a> = <code title="re.compile(r'^(([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.){3}([1-9]?\d|1\d\d|\
2[0-4]\d|25[0-5])$')">re.compile(r'^<code class="re-group">(</code><code class="re-group">(</code><code class="re-group">[</code>1<code class="re-op">-</code>9<code class="re-group">]</code><code class="re-op">?</code>\d<code class="re-op">|</code>1\d\d<code class="re-op">|</code>2<code class="re-group">[</code>0<code class="re-op">-</code>4<code class="re-group">]</code>\d<code class="re-op">|</code>25<code class="re-group">[</code>0<code class="re-op">-</code>5<code class="re-group">]</code><code class="re-group">)</code>\.<code class="re-group">)</code><code class="re-op">{3}</code><code class="variable-ellipsis">...</code></code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="numbers"></a><span class="summary-name">numbers</span> = <code title="(16777216, 65536, 256, 1)"><code class="variable-group">(</code>16777216<code class="variable-op">, </code>65536<code class="variable-op">, </code>256<code class="variable-op">, </code>1<code class="variable-group">)</code></code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="localhost"></a><span class="summary-name">localhost</span> = <code title="2130706433">2130706433</code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="private"></a><span class="summary-name">private</span> = <code title="((2886729728, 2886795263), (3232235520, 3232301055))"><code class="variable-group">(</code><code class="variable-group">(</code>2886729728<code class="variable-op">, </code>2886795263<code class="variable-group">)</code><code class="variable-op">, </code><code class="variable-group">(</code>3232235520<code class="variable-op">, </code>3232301055<code class="variable-group">)</code><code class="variable-group">)</code></code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="automatic"></a><span class="summary-name">automatic</span> = <code title="(2851995648, 2852061183)"><code class="variable-group">(</code>2851995648<code class="variable-op">, </code>2852061183<code class="variable-group">)</code></code>
    </td>
  </tr>
</table>
<!-- ==================== PROPERTIES ==================== -->
<a name="section-Properties"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Properties</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Properties"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__class__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== METHOD DETAILS ==================== -->
<a name="section-MethodDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Method Details</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-MethodDetails"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
</table>
<a name="__init__"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">__init__</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">minip</span>=<span class="sig-default"><code class="variable-quote">'</code><code class="variable-string">0.0.0.0</code><code class="variable-quote">'</code></span>,
        <span class="sig-arg">maxip</span>=<span class="sig-default"><code class="variable-quote">'</code><code class="variable-string">255.255.255.255</code><code class="variable-quote">'</code></span>,
        <span class="sig-arg">invert</span>=<span class="sig-default">True</span>,
        <span class="sig-arg">is_localhost</span>=<span class="sig-default">1</span>,
        <span class="sig-arg">is_private</span>=<span class="sig-default">1</span>,
        <span class="sig-arg">is_automatic</span>=<span class="sig-default">1</span>,
        <span class="sig-arg">error_message</span>=<span class="sig-default"><code class="variable-quote">'</code><code class="variable-string">enter valid IPv4 address</code><code class="variable-quote">'</code></span>)</span>
    <br /><em class="fname">(Constructor)</em>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="web2py.gluon.validators-pysrc.html#IS_IPV4.__init__">source&nbsp;code</a></span>&nbsp;
    </td>
  </table>
  
  x.__init__(...) initializes x; see x.__class__.__doc__ for 
  signature
  <dl class="fields">
    <dt>Overrides:
      object.__init__
        <dd><em class="note">(inherited documentation)</em></dd>
    </dt>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== CLASS VARIABLE DETAILS ==================== -->
<a name="section-ClassVariableDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Class Variable Details</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-ClassVariableDetails"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
</table>
<a name="regex"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">regex</h3>
  
  <dl class="fields">
  </dl>
  <dl class="fields">
    <dt>Value:</dt>
      <dd><table><tr><td><pre class="variable">
re.compile(r'^<code class="re-group">(</code><code class="re-group">(</code><code class="re-group">[</code>1<code class="re-op">-</code>9<code class="re-group">]</code><code class="re-op">?</code>\d<code class="re-op">|</code>1\d\d<code class="re-op">|</code>2<code class="re-group">[</code>0<code class="re-op">-</code>4<code class="re-group">]</code>\d<code class="re-op">|</code>25<code class="re-group">[</code>0<code class="re-op">-</code>5<code class="re-group">]</code><code class="re-group">)</code>\.<code class="re-group">)</code><code class="re-op">{3}</code><code class="re-group">(</code><code class="re-group">[</code>1<code class="re-op">-</code>9<code class="re-group">]</code><code class="re-op">?</code>\d<code class="re-op">|</code>1\d\d<code class="re-op">|</code><span class="variable-linewrap"><img src="crarr.png" alt="\" /></span>
2<code class="re-group">[</code>0<code class="re-op">-</code>4<code class="re-group">]</code>\d<code class="re-op">|</code>25<code class="re-group">[</code>0<code class="re-op">-</code>5<code class="re-group">]</code><code class="re-group">)</code>$')
</pre></td></tr></table>
</dd>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="web2py.gluon-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://www.web2py.com">web2py Web Framework</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0beta1 on Thu Aug  4 00:47:02 2011
    </td>
    <td align="right" class="footer">
      <a href="http://epydoc.sourceforge.net">http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie()
  // -->
</script>
  
</body>
</html>