This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Cep query by brazilian correios web services. | |
requirements: | |
- zeep==3.4.0 | |
""" | |
from zeep import Client, exceptions | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def _cpf_dv(digits): | |
""" | |
Returns the calculated verification digit. | |
""" | |
mod = sum(a * b for a, b in zip(digits, range(len(digits) + 1, 1, -1))) % 11 | |
return 0 if mod < 2 else 11 - mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import random | |
def _cnpj_dv(digits): | |
""" | |
Returns the calculated verification digit. | |
""" | |
mul = list(itertools.chain(*[range(len(digits) - 7, 1, -1), range(9, 1, -1)])) | |
return ((sum([a * b for a, b in zip(digits, mul)]) * 10) % 11) % 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from django.conf import settings | |
from django.utils import timezone | |
from django.utils.translation import ugettext_lazy as _ | |
from rest_framework import serializers, compat | |
class TimestampField(serializers.Field): | |
default_error_messages = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Unset: | |
""" | |
This class represent an unset instance. | |
""" | |
unset = Unset() | |
def first_or_default(sequence, condition=unset, default=None): |
OlderNewer