Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templateparser jittag overrides #1

Open
wants to merge 134 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
10bb3e7
Standardized exception handling.
CodePanter May 5, 2020
7f0badf
Merge pull request #17 from CodePanter/development
stefvanhouten May 6, 2020
dfabc1e
Updated error message when there is no pagemaker/route handler found
stefvanhouten May 6, 2020
d1abd42
Removed old documentation from readme. Can now be found in uweb3 docu…
stefvanhouten May 12, 2020
5c8e153
Added the unescape method for SQLSAFE
stefvanhouten May 12, 2020
53432fb
Removed the underdark folder in ext_lib. Moved all files 1 folder back
stefvanhouten May 13, 2020
b7c555d
Added more unittests for SQLSAFE
stefvanhouten May 13, 2020
f4331e8
More SQLSAFE unittests
stefvanhouten May 13, 2020
caf9c5c
Removed OpenID stuff from uWeb3.
stefvanhouten May 13, 2020
a7369f1
Cleaning up code. Setup.py no longer installs OpenID stuff
stefvanhouten May 13, 2020
b6bd0ff
Fixed pathing. Added a feature that should rollback the database if a…
stefvanhouten May 13, 2020
b03fd8c
git push origin developmentMerge branch 'master' into development
stefvanhouten May 13, 2020
99f93ef
Merge branch 'development' of github.com:stefvanhouten/uweb3 into dev…
stefvanhouten May 13, 2020
5c337d3
Added a comment to the source code of the StaticMiddleware helper cla…
stefvanhouten May 13, 2020
1528799
Removed new_login file. uWeb3 no longer needs support for a loginmixin
stefvanhouten May 13, 2020
5c1f9df
removed left over code
stefvanhouten May 13, 2020
b0d1af8
Remove scaffold from uWeb3
stefvanhouten May 13, 2020
7703903
Remove scaffold from uWeb3
stefvanhouten May 13, 2020
5b99ea7
Should now propperly ignore scaffold
stefvanhouten May 13, 2020
aad8c5d
Merge pull request #19 from stefvanhouten/development
stefvanhouten May 13, 2020
99babbb
Removed all login/session support from uWeb3
stefvanhouten May 14, 2020
db85b53
uWeb3 now places incoming PUT/DELETE variables in the correct self.vars
stefvanhouten May 18, 2020
5885ca9
Updated the checkxsrf decorator, now removes form data in PageMaker a…
stefvanhouten May 18, 2020
df4b0fa
Updated the XSRF decorator
stefvanhouten May 19, 2020
7d2a2ae
Added Storage class to the PageMaker. PageMaker now supports self.Fla…
stefvanhouten May 20, 2020
f4af523
uWeb3 now searches for a PreRequest method in the PageMaker. PreReque…
stefvanhouten May 20, 2020
1b2e855
Updated decorators
stefvanhouten May 22, 2020
6428a7e
Merge pull request #21 from stefvanhouten/development
stefvanhouten May 22, 2020
b001f3f
Decorators now use the correct uweb version
stefvanhouten May 22, 2020
eaa6bb3
Moved SQLAlchemy into seperate file, removed leftovers in model
stefvanhouten May 25, 2020
8ddbe77
updated uweb3 cached decorator to be python3 compatible
stefvanhouten May 25, 2020
f34e4c4
model.CachedPage now inherits from object so the user has more contro…
stefvanhouten May 25, 2020
d03931b
Added docstrings to the Flash and ExtendTemplate
stefvanhouten May 28, 2020
83c0016
Updated Cached decorator docstrings and added a error raise
stefvanhouten May 28, 2020
446a999
Updated the cached method, should now use the pymsql Error instead of…
stefvanhouten May 28, 2020
b8fccbd
Updated BasePageMaker docstrings
stefvanhouten May 28, 2020
48d95a4
Merge pull request #23 from stefvanhouten/development
stefvanhouten May 28, 2020
db1da45
Created a WebsocketPageMaker for websocket routes
stefvanhouten Jun 6, 2020
a61b1c9
WebsocketPagemaker can now access the uweb3 templateparser.
stefvanhouten Jun 8, 2020
98c042c
WebsocketPagemaker can now access the uweb3 templateparser. Websocket…
stefvanhouten Jun 8, 2020
ad691b9
Merge pull request #24 from stefvanhouten/development
stefvanhouten Jun 8, 2020
e2dd5e1
PageMaker can now access request
stefvanhouten Jun 8, 2020
c6f0b64
Merge pull request #25 from stefvanhouten/development
stefvanhouten Jun 8, 2020
9095f96
Update CONTRIBUTORS
underdarknl Jun 15, 2020
91afafd
Delete tables.sql
underdarknl Jun 15, 2020
1b58313
html5 compatible error page
JanKlopper Jun 15, 2020
6f2f58c
clean up and merge decorators
JanKlopper Jun 15, 2020
b468ca9
Rework this repos to the current state of development
JanKlopper Oct 26, 2020
a9c1670
make mail module use safestring module, use machine name when no loca…
JanKlopper Oct 27, 2020
fadc285
add email header safestring class
JanKlopper Oct 27, 2020
5a323b9
remove old uweb start stop script
JanKlopper Oct 27, 2020
826d904
move test files to test folder outside of uweb package, remove some u…
JanKlopper Oct 27, 2020
17d80cf
forgot to include the readme file
JanKlopper Oct 27, 2020
f787732
urlsplitter is not needed in core uweb3 package
JanKlopper Oct 27, 2020
5643162
remove unneeded references, remove admin module for now
JanKlopper Oct 27, 2020
a6579b8
fix sqlite results to function with new resultset handling
JanKlopper Oct 27, 2020
422714b
make the initial settingsmanager more configurable, and only reread c…
JanKlopper Oct 28, 2020
c874a60
make the initial settingsmanager more configurable, and only reread c…
JanKlopper Oct 28, 2020
50b93e5
update setup file to reflect changes since uweb on python2
JanKlopper Oct 28, 2020
a486e95
remove unneeded imports
JanKlopper Oct 29, 2020
6092e2c
fix curtime not being set on unread config files
JanKlopper Oct 30, 2020
190a322
allow <= and >= in eval
JanKlopper Nov 2, 2020
dff8249
shuffle some things around for safestrings, including integration wit…
JanKlopper Nov 11, 2020
36700d2
add distinct functionality to List method, add as to List and Selec…
JanKlopper Nov 23, 2020
bbf05a6
more and better output for syntax errors in templates
JanKlopper Nov 26, 2020
338e29a
give the hotReload functionality some much needed attention. Now the …
JanKlopper Nov 30, 2020
9faeffb
remove unneeded print output in reload module
JanKlopper Nov 30, 2020
f794a7a
import parse_qs from urllib instead of cgi with python3.8
errieman Dec 8, 2020
63aaf6e
change xrange to range in tests
errieman Dec 8, 2020
039d37d
Merge pull request #1 from errieman/master
underdarknl Dec 8, 2020
8f00ed4
relative import in sqlresult test
errieman Dec 8, 2020
9dff332
update gitignore to ignore .noseids
errieman Dec 8, 2020
18e52bb
add some methods for header handling, and copy the already present he…
JanKlopper Dec 9, 2020
f150c10
Merge branch 'master' of https://github.com/underdarknl/uweb3
errieman Dec 11, 2020
8ee2936
don't use const naming style for mutable properties
errieman Dec 11, 2020
90905f6
python3 and comprehensions
errieman Dec 11, 2020
715ca4a
use parse_qs and parse_qsl from urllib.parse instead of cgi
errieman Dec 11, 2020
5fec7f9
remove (object) from classes and more comprehensions and generators
errieman Dec 11, 2020
ad22695
Merge branch 'master' into cleanup
errieman Dec 11, 2020
e1dcb58
Merge pull request #2 from errieman/master
underdarknl Dec 11, 2020
a9147d8
Merge pull request #3 from errieman/cleanup
underdarknl Dec 11, 2020
dba06f2
import reload function from importlib
errieman Dec 11, 2020
ffb106a
fix typo in _GetSearchQuery connection arg
errieman Dec 11, 2020
b40062d
Merge branch 'master' of https://github.com/underdarknl/uweb3
errieman Dec 11, 2020
c9fa350
Merge pull request #4 from errieman/master
underdarknl Dec 12, 2020
16fe023
Merge branch 'master' of github.com:underdarknl/uweb3
JanKlopper Dec 14, 2020
532082d
fix some misnamings
JanKlopper Dec 14, 2020
b6dddab
string compare only once, for static routes
JanKlopper Dec 15, 2020
04ee7f7
allow dots in indice names for the templateparser.
JanKlopper Dec 16, 2020
9b931e5
add In keyword to Valid AST commands in eval mode
JanKlopper Feb 2, 2021
50db224
Static files can simly be read as binary
JanKlopper Feb 4, 2021
2b027e9
license update to GPL v3, add build script
JanKlopper Feb 7, 2021
a7dc9b4
license update to GPL v3, add build script
JanKlopper Feb 7, 2021
2a83eff
fix setup.py long_description_file is not actualy a useful key
JanKlopper Feb 7, 2021
e11b65b
improve handling of static and template files, make sure we dont allo…
JanKlopper Feb 15, 2021
6d4f216
update readme to reflect availability of pip package.
JanKlopper Feb 15, 2021
e407e41
tiny fix to set content on reponse directly, and set character encodi…
JanKlopper Feb 15, 2021
a53fabe
Fix setup.py to be more lint friendly
JanKlopper Feb 24, 2021
5f03b2a
some cleanups, and fix an issue where an unknown content-type did not…
JanKlopper Feb 24, 2021
663c5e3
split out the various connectors to seperate files. Make sure the req…
JanKlopper Feb 24, 2021
0bc3973
add pylintrc file
JanKlopper Feb 24, 2021
13af258
don't include restfull api connector just yet
JanKlopper Feb 24, 2021
830feee
various fixes set file to execute using python3, and use new style cl…
JanKlopper Feb 24, 2021
88770e3
linint cleanups and some minor refactoring
JanKlopper Feb 24, 2021
e61cb2a
dont crash when we dont have a content-type header set
JanKlopper Feb 24, 2021
06a39db
linting fixes and some minor refactoring
JanKlopper Feb 24, 2021
e6df6d7
refactoring to the SecureCookie class and some minor refactoring + us…
JanKlopper Feb 24, 2021
8b4fa2f
remove unneeded debug print
JanKlopper Feb 26, 2021
9334f93
remove first slash from relative paths in the static handler
JanKlopper Feb 26, 2021
4f61f85
fix module loading in Signedcookie connector
underdarknl Apr 5, 2021
fc31c24
fix hot reloading by not adding empty strings to ignored_extensions a…
underdarknl Apr 5, 2021
f9a4852
move requirements to seperate file
underdarknl May 24, 2021
f2276f5
make templateparser tests aware of new tag char ./dot, which could be…
underdarknl May 24, 2021
544de41
cleanup the logging, and various other init structures to happen only…
underdarknl May 24, 2021
97b1441
remove unneeded utils file
underdarknl May 24, 2021
0cc95b5
use json instead of pickle on SignedCookies, remove some unneeded deb…
underdarknl May 24, 2021
1431faa
use json instead of pickle on SignedCookies
underdarknl May 24, 2021
911abf0
use Magic module to find content-type for static files, and serve cor…
underdarknl May 24, 2021
e0b347b
add encoding / decoding to secureCookie as not all json chars are val…
underdarknl May 25, 2021
f013161
add log variable to response which allows the user to set custom log …
underdarknl May 25, 2021
a0faabe
add default encoder for xml (svg/xml) outputs which handles mime-type…
underdarknl May 25, 2021
b8484c4
small cleanups to templateparser, better restrict the templateparser'…
underdarknl May 25, 2021
b858034
add upload limiter lib, and use it to parse multipart forms, which al…
underdarknl May 25, 2021
2083a68
add stef's Underdark address to the contributors file
underdarknl May 25, 2021
65d5043
fix typo as per PR9, thnx stef.
underdarknl May 25, 2021
a90f759
add requirements.txt to MANIFEST
underdarknl May 28, 2021
cb78d5f
move error_logging to log setion in config.
underdarknl May 28, 2021
c717ca0
remove logging from non debugging pagemaker, as already handled with …
underdarknl May 28, 2021
6a130e8
remove unneeded registry class, add logger and errorlogger to request…
underdarknl Jun 7, 2021
1c967a8
set the header for non parse json api calls
underdarknl Jul 26, 2021
9d6d99a
work towards a parser instance that knows about the noparse environment
underdarknl Jul 26, 2021
cda2c57
work towards a parser instance that knows about the noparse environment
underdarknl Jul 26, 2021
b355e73
add sparse output pagemaker, JitTags with acces to the scope, various…
underdarknl Feb 9, 2022
ac277d1
allow the user to always override registered tags from withing the pa…
underdarknl Apr 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pip-log.txt
.coverage
.tox
nosetests.xml
.noseids

# Translations
*.mo
Expand All @@ -33,4 +34,5 @@ uweb3-venv
features
*.vscode
*.log
*.out
*.out
scaffold/
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ uWeb was created by:
- Jan Klopper <[email protected]>
- Arjen Pander <[email protected]>
- Elmer de Looff <[email protected]>
- Stef van Houten <[email protected]>

And has had code contributions from:

Expand Down
26 changes: 26 additions & 0 deletions DEVELOPMENT
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Development on µWeb3 follows the pep8 rules

# Development environment.
You can setup a working development environment by issueing:

```bash
python3 setup.py develop --user

# clone the uweb3scaffold project to get started
git clone [email protected]:underdarknl/uweb3scaffold.git
cd uweb3scaffold

python3 serve.py
```

This will setup a local


# Coding conventions:

* Tabs are two spaces.
* Each method and class is required to contain a docstring
* Text files outside the python scope are written in markdown

Each File has an __author__ variable, in which you can list your name and email address if you whish to do so.
You can do a pull request on CONTRIBUTORS to have your name added.
675 changes: 672 additions & 3 deletions LICENSE

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include README.md LICENSE
recursive-include uweb3 *.js *.css *.html *.conf *.txt *.utp
recursive-include uweb3/ext_lib *.py
include README.md LICENSE DEVELOPMENT CONTRIBUTORS requirements.txt
recursive-include uweb3 *.html *.conf *.py
recursive-include test *.py
166 changes: 22 additions & 144 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Since µWeb inception we have used it for many projects, and while it did its job, there were plenty of rough edges. This new version intends to remove those and pull it into the current age.

µWeb3 is free software, distributed under the terms of the [GNU] General Public License as published by the Free Software Foundation, version 3 of the License (or any later version). For more information, see the file LICENSE

# Notable changes

* wsgi complaint interface
Expand All @@ -15,12 +17,13 @@ Since µWeb inception we have used it for many projects, and while it did its jo

The following example applications for uWeb3 exist:

* [uWeb3-info](https://github.com/edelooff/uWeb3-info): This demonstrates most µWeb3 features, and gives you examples on how to use most of them.
* [uWeb3-logviewer](https://github.com/edelooff/uWeb3-logviewer): This allows you to view and search in the logs generated by all µWeb and µWeb3 applications.
* [uWeb3-scaffold](https://github.com/underdarknl/uweb3scaffold): This is an empty project which you can fork to start your own website

# µWeb3 installation

The easiest and quickest way to install µWeb3 is using Python's `virtualenv`. Install using the setuptools installation script, which will automatically gather dependencies.
The easiest and quickest way to install µWeb3 is by running pip3 install uwebthree.

For a development version using Python's `virtualenv`. Install using the setuptools installation script, which will automatically gather dependencies.

```bash
# Set up the Python3 virtualenv
Expand All @@ -31,9 +34,11 @@ source env/bin/activate
python3 setup.py install

# Or you can install in development mode which allows easy modification of the source:
python3 setup.py develop
python3 setup.py develop --user

cd uweb3/scaffold
# clone the uweb3scaffold project to get started
git clone [email protected]:underdarknl/uweb3scaffold.git
cd uweb3scaffold

python3 serve.py
```
Expand Down Expand Up @@ -64,159 +69,32 @@ database = 'dbname'
```
To access your database connection simply use the connection attribute in any class that inherits from PageMaker.

# Config settings
If you are working on µWeb3 core make sure to enable the following setting in the config:
```
[development]
dev = True
```
This makes sure that µWeb3 restarts every time you modify something in the core of the framework aswell.

µWeb3 has inbuild XSRF protection. You can import it from uweb3.pagemaker.new_decorators checkxsrf.
This is a decorator and it will handle validation and generation of the XSRF.
The only thing you have to do is add the ```{{ xsrf [xsrf]}}``` tag into a form.
The xsrf token is accessible in any pagemaker with self.xsrf.

# Routing
The default way to create new routes in µWeb3 is to create a folder called routes.
In the routes folder create your pagemaker class of choice, the name doesn't matter as long as it inherits from PageMaker.
After creating your pagemaker be sure to add the route endpoint to routes list in base/__init__.py.

# New
# New since v3
- In uweb3 __init__ a class called HotReload
- In pagemaker __init__:
- A classmethod called loadModules that loads all pagemaker modules inheriting from PageMaker class
- A XSRF class
- Generates a xsrf token and creates a cookie if not in place
- Validates the xsrf token in a post request if the enable_xsrf flag is set in the config.ini
- In requests:
- Self.method attribute
- self.post.form attribute. This is the post request as a dict, includes blank values.
- Method called Redirect #Moved from the response class to the request class so cookies that are set before a redirect are actually set.
- Method called Redirect #Moved from the response class to the request class so cookies that are set before a redirect are actually persist to the next request.
- Method called DeleteCookie
- A if statement that checks string like cookies and raises an error if the size is equal or bigger than 4096 bytes.
- AddCookie method, edited this and the response class to handle the setting of multiple cookies. Previously setting multiple cookies with the Set-Cookie header would make the last cookie the only cookie.
- In pagemaker/new_login Users class:
- Create user
- Find user by name
- Create a cookie with userID + secret
- Validate if user messed with given cookie and render it useless if so
- In pagemaker/new_decorators:
- An if statement that checks string like cookies and raises an error if the size is equal or bigger than 4096 bytes.
- AddCookie method, now supports multiple calls to Set-Cookie setting all cookies instead of just the last.
- In pagemaker/decorators:
- Loggedin decorator that validates if user is loggedin based on cookie with userid
- Checkxsrf decorator that checks if the incorrect_xsrf_token flag is set
- In templatepaser:
- A function called _TemplateConstructXsrf that generates a hidden input field with the supplied value: {{ xsrf [xsrf_variable]}}
- In libs/sqltalk
- Tried to make sqltalk python3 compatible by removing references to: long, unicode and basestring
- So far so good but it might crash on functions that I didn't use yet


# Login validation
Instead of using sessions to keep track of logged in users µWeb3 uses secure cookies. So how does this work?
When a user logs in for the first time there is no cookie in place, to set one we go through the normal process of validating a user and loggin in.

To create a secure cookie inherit from the Model.SecureCookie. The SecureCookie class has a few build in methods, Create, Update and Delete.
To create a new cookie make use of the `Create` method, it works the same ass the AddCookie method.

If you want to see which cookies are managed by the SecureCookie class you can call the session attribute.
The session attribute decodes all managed cookies and can be used to read them.

# SQLAlchemy
SQLAlchemy is available in uWeb3 by using the SqAlchemyPageMaker instead of the regular pagemaker.
SQLAlchemy comes with most of the methods that are available in the default model.Record class, however because SQLAlchemy works like an ORM
there are some adjustments. Instead of inheriting from dict the SQLAlchemy model.Record inherits from object, meaning you can no longer use
dict like functions such as get and set. Instead the model is accessible by the columns defined in the class you want to create.

The SQLAlchemy model.Record class makes use of the session attribute accessible in the SqAlchemyPageMaker.

The session keeps track of all queries to the database and comes with some usefull features.

An example of a few usefull features:
`session.new`: The set of all instances marked as ‘new’ within this Session.
`session.dirty`: Instances are considered dirty when they were modified but not deleted.
`session.deleted`: The set of all instances marked as ‘deleted’ within this Session
the rest can be found at https://docs.sqlalchemy.org/en/13/orm/session_api.html

Objects in the session will only be updated/created in the actual database on session.commit()/session.flush().

Defining classes that represent a table is different from how we used to do it in uWeb2.
SQLAlchemy requires you to define all columns from the table that you want to use.
For example, creating a class that represents the user table could look like this:

```
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class User(Base):
__tablename__ = 'users'

id = Column(Integer, primary_key=True)
username = Column(String, nullable=False, unique=True)
password = Column(String, nullable=False)
```
We can now use this class to query our users table in the SqAlchemyPageMaker to get the user with id 1:
`self.session.query(User).filter(User.id == 1).first() `
or to list all users:
`self.session.query(User).all()`
uWeb3's SQLAlchemy model.Record has almost the same functionality as uWeb3's regular model.Record so we can simplify our code to this:

```
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

#Notice how we load in the uweb3.model.AlchemyRecord class to gain access to all sorts of functionality
class User(uweb3.model.AlchemyRecord, Base):
__tablename__ = 'users'

id = Column(Integer, primary_key=True)
username = Column(String, nullable=False, unique=True)
password = Column(String, nullable=False)
```
We can now query the users table like this:
```
User.FromPrimary(self.session, 1)
>>> User({'id': 1, 'username': 'username', 'password': 'password'})
```
Or to get a list of all users:
```
User.List(self.session, conditions=[User.id <= 2])
>>> [
User({'id': 1, 'username': 'name', 'password': 'password'}),
User({'id': 2, 'username': 'user2', 'password': 'password'})
]
```

Now if we want to automatically load related tables we can set it up like this:

```
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship

Base = declarative_base()

class User(uweb3.model.AlchemyRecord, Base):
__tablename__ = 'users'

id = Column(Integer, primary_key=True)
username = Column(String, nullable=False, unique=True)
password = Column(String, nullable=False)
userinfoid = Column('userinfoid', Integer, ForeignKey('UserInfo.id'))
userdata = relationship("UserInfo", lazy="select")

def __init__(self, *args, **kwargs):
super(User, self).__init__(*args, **kwargs)

class UserInfo(uweb3.model.AlchemyRecord, Base):
__tablename__ = 'UserInfo'

id = Column(Integer, primary_key=True)
name = Column(String, unique=True)
```
Now the UserInfo table will be loaded on the `userinfoid` attribute, but only after we try and access
this key a seperate query is send to retrieve the related information.
SQLAlchemy's lazy loading is fast but should be avoided while in loops. Take a look at SQLAlchemys documentation for optimal use.
- Its possible to register tags to the parser, for example in your _postInit call
- Its possible to register 'Just in Time' tags to the parser, which will be evaluated only when needed.
- In libs/sqltalk, use of PyMysql instead of c mysql functions
- Connections
- All Connections are now all availabe on the self.connections member of the pagemaker, regardless of what type of backend they connect to
- Cookies (signed and safe) are available as a connection
- Config files (read/write) are available as a connection
Loading