Skip to content

Commit

Permalink
Merge e59b577 into b9dbcd7
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Apr 10, 2018
2 parents b9dbcd7 + e59b577 commit 7a940cb
Show file tree
Hide file tree
Showing 32 changed files with 345 additions and 104 deletions.
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[run]
source = masonite

[report]
ignore_errors = True
omit =
*/tests/*
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ storage/compiled/
uploads/test.jpg
bootstrap/cache/*.html
bootstrap/cache/*.txt
/uploads/
/uploads/
.coverage
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
language: python

python:
- '3.4'
- '3.5'
- '3.6'

install:
- pip install .
- pip install -r requirements.txt
script: python -m pytest

script: coverage run -m pytest

deploy:
provider: pypi
user: josephmancuso
Expand All @@ -16,3 +20,5 @@ deploy:
tags: true
python: 3.6

after_success:
coveralls
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Masonite
Core files for the python framework

[![Build Status](https://travis-ci.org/MasoniteFramework/core.svg?branch=master)](https://travis-ci.org/MasoniteFramework/core) <img src="https://img.shields.io/badge/coverage-79%25-green.svg">
[![Build Status](https://travis-ci.org/MasoniteFramework/core.svg?branch=master)](https://travis-ci.org/MasoniteFramework/core)

[![Coverage Status](https://coveralls.io/repos/github/MasoniteFramework/core/badge.svg?branch=master)](https://coveralls.io/github/MasoniteFramework/core?branch=master)

To get started with this repo, [read the CONTRIBUTING.md file on the masonite repo](https://github.com/josephmancuso/masonite/blob/master/CONTRIBUTING.md)
3 changes: 2 additions & 1 deletion config/application.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

KEY='NCTpkICMlTXie5te9nJniMj9aVbPM6lsjeq5iDZ0dqY='
KEY = 'NCTpkICMlTXie5te9nJniMj9aVbPM6lsjeq5iDZ0dqY='

BASE_DIRECTORY = os.getcwd()

Expand All @@ -9,6 +9,7 @@
PROVIDERS = [
# Framework Providers
'masonite.providers.AppProvider.AppProvider',
'masonite.providers.SessionProvider.SessionProvider',
'masonite.providers.CsrfProvider.CsrfProvider',
'masonite.providers.RouteProvider.RouteProvider',
'masonite.providers.RedirectionProvider.RedirectionProvider',
Expand Down
2 changes: 1 addition & 1 deletion config/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
'ably': {
'secret': os.getenv('ABLY_SECRET')
}
}
}
5 changes: 5 additions & 0 deletions config/session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
Session configuration
"""

DRIVER = 'memory'
6 changes: 3 additions & 3 deletions masonite/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def make(self, name):
""" Retreives a class from the container by key """
if self.has(name):
return self.providers[name]

raise MissingContainerBindingNotFound("{0} key was not found in the container".format(name))

def has(self, name):
if name in self.providers:
return True

return False

def helper(self):
Expand Down
4 changes: 1 addition & 3 deletions masonite/contracts/BroadcastContract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class BroadcastContract(ABC):

@abstractmethod
def ssl(self): pass

@abstractmethod
def channel(self): pass


3 changes: 2 additions & 1 deletion masonite/contracts/CacheContract.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from abc import ABC, abstractmethod


class CacheContract(ABC):

@abstractmethod
def store(self): pass

@abstractmethod
def store_for(self): pass

Expand Down
5 changes: 3 additions & 2 deletions masonite/contracts/MailContract.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from abc import ABC, abstractmethod


class MailContract(ABC):

@abstractmethod
def to(self): pass

@abstractmethod
def template(self): pass

Expand Down
2 changes: 1 addition & 1 deletion masonite/contracts/QueueContract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
class QueueContract(ABC):

@abstractmethod
def push(self): pass
def push(self): pass
25 changes: 25 additions & 0 deletions masonite/contracts/SessionContract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from abc import ABC, abstractmethod


class SessionContract(ABC):

@abstractmethod
def get(self): pass

@abstractmethod
def set(self): pass

@abstractmethod
def has(self): pass

@abstractmethod
def all(self): pass

@abstractmethod
def flash(self): pass

@abstractmethod
def reset(self): pass

@abstractmethod
def helper(self): pass
3 changes: 0 additions & 3 deletions masonite/contracts/UploadContract.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ def store(self): pass

@abstractmethod
def store_prepend(self): pass



2 changes: 0 additions & 2 deletions masonite/drivers/BaseUploadDriver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from masonite.exceptions import FileTypeException


Expand Down
1 change: 1 addition & 0 deletions masonite/drivers/BroadcastAblyDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
raise DriverLibraryNotFound(
'Could not find the "ably" library. Please pip install this library running "pip install ably"')


class BroadcastAblyDriver(BroadcastContract):

def __init__(self, BroadcastConfig):
Expand Down
3 changes: 2 additions & 1 deletion masonite/drivers/BroadcastPusherDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
raise DriverLibraryNotFound(
'Could not find the "pusher" library. Please pip install this library running "pip install pusher"')


class BroadcastPusherDriver(BroadcastContract):

def __init__(self, BroadcastConfig):
self.config = BroadcastConfig
self.ssl_message = True

def ssl(self, boolean):
self.ssl_message = boolean
return self
Expand Down
6 changes: 3 additions & 3 deletions masonite/drivers/CacheDiskDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def delete(self, key):

for template in glob.glob(glob_path):
os.remove(template)

def update(self, key, value, location=None):
"""
Updates a specific cache by key
Expand All @@ -117,7 +117,7 @@ def update(self, key, value, location=None):

location = os.path.join(location, key)
cache = glob.glob(location + ':*')[0]

open(cache, 'w').write(str(value))

return key
Expand Down Expand Up @@ -172,4 +172,4 @@ def _create_directory(self, directory):
# Create the path to the model if it does not exist
os.makedirs(os.path.dirname(directory))
return True
return False
return False
86 changes: 86 additions & 0 deletions masonite/drivers/SessionCookieDriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from masonite.contracts.SessionContract import SessionContract


class SessionCookieDriver(SessionContract):
"""
Session from the memory driver
"""

def __init__(self, Environ, Request):
"""
Constructor
"""

self.environ = Environ
self.request = Request

def get(self, key):
"""
Get a session from object _session
"""

cookie = self.request.get_cookie('s_{0}'.format(key))
if cookie:
return cookie

return None

def set(self, key, value):
"""
Set a new session in object _session
"""

self.request.cookie('s_{0}'.format(key), value)

def has(self, key):
"""
Check if a key exists in the session
"""

if self.get(key):
return True
return False

def all(self):
"""
Get all session data
"""

return self.__collect_data()

def __collect_data(self):
"""
Collect data from session and flash data
"""

cookies = {}
if 'HTTP_COOKIE' in self.environ and self.environ['HTTP_COOKIE']:
cookies_original = self.environ['HTTP_COOKIE'].split(';')
for cookie in cookies_original:
if cookie.startswith('s_'):
data = cookie.split("=")
cookie_value = self.request.get_cookie(data[0])
cookies[data[0][2:]] = cookie_value
return cookies

def flash(self, key, value):
"""
Add temporary data to the session
"""

self.request.cookie('s_{0}'.format(key), value, expires='2 seconds')

def reset(self, flash_only=False):
"""
Reset object _session
"""
cookies = self.__collect_data()
for cookie in cookies:
self.request.delete_cookie('s_{0}'.format(cookie))

def helper(self):
"""
Used to create builtin helper function
"""

return self
Loading

0 comments on commit 7a940cb

Please sign in to comment.