BVB Source Codes

TextBlob Show decorators.py Source code

Return Download TextBlob: download decorators.py Source code - Download TextBlob Source code - Type:.py
  1. # -*- coding: utf-8 -*-
  2. """Custom decorators."""
  3.  
  4. from __future__ import absolute_import
  5. from functools import wraps
  6. from textblob.exceptions import MissingCorpusError
  7.  
  8.  
  9. class cached_property(object):
  10.     """A property that is only computed once per instance and then replaces
  11.    itself with an ordinary attribute. Deleting the attribute resets the
  12.    property.
  13.  
  14.    Credit to Marcel Hellkamp, author of bottle.py.
  15.    """
  16.  
  17.     def __init__(self, func):
  18.         self.__doc__ = getattr(func, '__doc__')
  19.         self.func = func
  20.  
  21.     def __get__(self, obj, cls):
  22.         if obj is None:
  23.             return self
  24.         value = obj.__dict__[self.func.__name__] = self.func(obj)
  25.         return value
  26.  
  27.  
  28. def requires_nltk_corpus(func):
  29.     """Wraps a function that requires an NLTK corpus. If the corpus isn't found,
  30.    raise a :exc:`MissingCorpusError`.
  31.    """
  32.     @wraps(func)
  33.     def decorated(*args, **kwargs):
  34.         try:
  35.             return func(*args, **kwargs)
  36.         except LookupError as err:
  37.             print(err)
  38.             raise MissingCorpusError()
  39.     return decorated
  40.  
downloaddecorators.py Source code - Download TextBlob Source code
Related Source Codes/Software:
monaco-editor - A browser based code editor 2017-01-07
grumpy - Grumpy is a Python to Go source code transcompiler... 2017-01-07
flinux - Foreign LINUX - Run unmodified Linux applications ... 2017-01-07
beeswithmachineguns - A utility for arming (creating) many bees (micro E... 2017-01-07
TopDeepLearning - A list of popular github projects related to deep ... 2017-01-07
yui3 - A library for building richly interactive web appl... 2017-01-07
KineticJS - KineticJS is an HTML5 Canvas JavaScript framework ... 2017-01-07
web-design-standards - Open source UI components and visual style guide f... 2017-01-07
Knuff - The debug application for Apple Push Notification ... 2017-01-07
RoundedImageView - A fast ImageView that supports rounded corners, ov... 2017-01-07
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top